2017-01-01 23:45:09 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-01-01 23:45:09 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
package issues_test
|
2017-01-01 23:45:09 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-13 15:07:59 +05:30
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-17 18:04:35 +05:30
|
|
|
|
2017-01-01 23:45:09 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPullRequest_LoadAttributes(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NotNil(t, pr.Merger)
|
|
|
|
assert.Equal(t, pr.MergerID, pr.Merger.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequest_LoadIssue(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.NoError(t, pr.LoadIssue(db.DefaultContext))
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NotNil(t, pr.Issue)
|
|
|
|
assert.Equal(t, int64(2), pr.Issue.ID)
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.NoError(t, pr.LoadIssue(db.DefaultContext))
|
2017-01-09 08:45:07 +05:30
|
|
|
assert.NotNil(t, pr.Issue)
|
|
|
|
assert.Equal(t, int64(2), pr.Issue.ID)
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
2020-03-03 04:01:55 +05:30
|
|
|
func TestPullRequest_LoadBaseRepo(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NotNil(t, pr.BaseRepo)
|
|
|
|
assert.Equal(t, pr.BaseRepoID, pr.BaseRepo.ID)
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
2017-01-09 08:45:07 +05:30
|
|
|
assert.NotNil(t, pr.BaseRepo)
|
|
|
|
assert.Equal(t, pr.BaseRepoID, pr.BaseRepo.ID)
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
2020-03-03 04:01:55 +05:30
|
|
|
func TestPullRequest_LoadHeadRepo(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.NoError(t, pr.LoadHeadRepo(db.DefaultContext))
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NotNil(t, pr.HeadRepo)
|
|
|
|
assert.Equal(t, pr.HeadRepoID, pr.HeadRepo.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO TestMerge
|
|
|
|
|
|
|
|
// TODO TestNewPullRequest
|
|
|
|
|
|
|
|
func TestPullRequestsNewest(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
prs, count, err := issues_model.PullRequests(1, &issues_model.PullRequestsOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
},
|
2017-01-01 23:45:09 +05:30
|
|
|
State: "open",
|
|
|
|
SortType: "newest",
|
|
|
|
Labels: []string{},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2020-01-17 11:33:40 +05:30
|
|
|
assert.EqualValues(t, 3, count)
|
|
|
|
if assert.Len(t, prs, 3) {
|
|
|
|
assert.EqualValues(t, 5, prs[0].ID)
|
|
|
|
assert.EqualValues(t, 2, prs[1].ID)
|
|
|
|
assert.EqualValues(t, 1, prs[2].ID)
|
2017-08-28 14:47:45 +05:30
|
|
|
}
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequestsOldest(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
prs, count, err := issues_model.PullRequests(1, &issues_model.PullRequestsOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
},
|
2017-01-01 23:45:09 +05:30
|
|
|
State: "open",
|
|
|
|
SortType: "oldest",
|
|
|
|
Labels: []string{},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2020-01-17 11:33:40 +05:30
|
|
|
assert.EqualValues(t, 3, count)
|
|
|
|
if assert.Len(t, prs, 3) {
|
|
|
|
assert.EqualValues(t, 1, prs[0].ID)
|
|
|
|
assert.EqualValues(t, 2, prs[1].ID)
|
|
|
|
assert.EqualValues(t, 5, prs[2].ID)
|
2017-08-28 14:47:45 +05:30
|
|
|
}
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUnmergedPullRequest(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-11-19 13:42:33 +05:30
|
|
|
pr, err := issues_model.GetUnmergedPullRequest(db.DefaultContext, 1, 1, "branch2", "master", issues_model.PullRequestFlowGithub)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), pr.ID)
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
_, err = issues_model.GetUnmergedPullRequest(db.DefaultContext, 1, 9223372036854775807, "branch1", "master", issues_model.PullRequestFlowGithub)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
2022-01-04 01:15:58 +05:30
|
|
|
func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "branch2")
|
2022-01-04 01:15:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, true, exist)
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
exist, err = issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "not_exist_branch")
|
2022-01-04 01:15:58 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, false, exist)
|
|
|
|
}
|
|
|
|
|
2017-01-01 23:45:09 +05:30
|
|
|
func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
Fix cannot reopen after pushing commits to a closed PR (#23189)
Close: #22784
1. On GH, we can reopen a PR which was closed before after pushing
commits. After reopening PR, we can see the commits that were pushed
after closing PR in the time line. So the case of
[issue](https://github.com/go-gitea/gitea/issues/22784) is a bug which
needs to be fixed.
2. After closing a PR and pushing commits, `headBranchSha` is not equal
to `sha`(which is the last commit ID string of reference). If the
judgement exists, the button of reopen will not display. So, skip the
judgement if the status of PR is closed.
![image](https://user-images.githubusercontent.com/33891828/222037529-651fccf9-0bba-433e-b2f0-79c17e0cc812.png)
3. Even if PR is already close, we should still insert comment record
into DB when we push commits.
So we should still call function `CreatePushPullComment()`.
https://github.com/go-gitea/gitea/blob/067b0c2664d127c552ccdfd264257caca4907a77/services/pull/pull.go#L260-L282
So, I add a switch(`includeClosed`) to the
`GetUnmergedPullRequestsByHeadInfo` func to control whether the status
of PR must be open. In this case, by setting `includeClosed` to `true`,
we can query the closed PR.
![image](https://user-images.githubusercontent.com/33891828/222621045-bb80987c-10c5-4eac-aa0c-1fb9c6aefb51.png)
4. In the loop of comments, I use the`latestCloseCommentID` variable to
record the last occurrence of the close comment.
In the go template, if the status of PR is closed, the comments whose
type is `CommentTypePullRequestPush(29)` after `latestCloseCommentID`
won't be rendered.
![image](https://user-images.githubusercontent.com/33891828/222058913-c91cf3e3-819b-40c5-8015-654b31eeccff.png)
e.g.
1). The initial status of the PR is opened.
![image](https://user-images.githubusercontent.com/33891828/222453617-33c5093e-f712-4cd6-8489-9f87e2075869.png)
2). Then I click the button of `Close`. PR is closed now.
![image](https://user-images.githubusercontent.com/33891828/222453694-25c588a9-c121-4897-9ae5-0b13cf33d20b.png)
3). I try to push a commit to this PR, even though its current status is
closed.
![image](https://user-images.githubusercontent.com/33891828/222453916-361678fb-7321-410d-9e37-5a26e8095638.png)
But in comments list, this commit do not display.This is as expected :)
![image](https://user-images.githubusercontent.com/33891828/222454169-7617a791-78d2-404e-be5e-77d555f93313.png)
4). Click the `Reopen` button, the commit which is pushed after closing
PR display now.
![image](https://user-images.githubusercontent.com/33891828/222454533-897893b6-b96e-4701-b5cb-b1800f382b8f.png)
---------
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-03-03 18:46:58 +05:30
|
|
|
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(1, "branch2", false)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, prs, 1)
|
|
|
|
for _, pr := range prs {
|
|
|
|
assert.Equal(t, int64(1), pr.HeadRepoID)
|
|
|
|
assert.Equal(t, "branch2", pr.HeadBranch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetUnmergedPullRequestsByBaseInfo(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
prs, err := issues_model.GetUnmergedPullRequestsByBaseInfo(1, "master")
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Len(t, prs, 1)
|
|
|
|
pr := prs[0]
|
|
|
|
assert.Equal(t, int64(2), pr.ID)
|
|
|
|
assert.Equal(t, int64(1), pr.BaseRepoID)
|
|
|
|
assert.Equal(t, "master", pr.BaseBranch)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPullRequestByIndex(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
pr, err := issues_model.GetPullRequestByIndex(db.DefaultContext, 1, 2)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(1), pr.BaseRepoID)
|
|
|
|
assert.Equal(t, int64(2), pr.Index)
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
_, err = issues_model.GetPullRequestByIndex(db.DefaultContext, 9223372036854775807, 9223372036854775807)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
|
2021-10-05 20:11:48 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
_, err = issues_model.GetPullRequestByIndex(db.DefaultContext, 1, 0)
|
2021-10-05 20:11:48 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPullRequestByID(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
pr, err := issues_model.GetPullRequestByID(db.DefaultContext, 1)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(1), pr.ID)
|
|
|
|
assert.Equal(t, int64(2), pr.IssueID)
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
_, err = issues_model.GetPullRequestByID(db.DefaultContext, 9223372036854775807)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetPullRequestByIssueID(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
pr, err := issues_model.GetPullRequestByIssueID(db.DefaultContext, 2)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), pr.IssueID)
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
_, err = issues_model.GetPullRequestByIssueID(db.DefaultContext, 9223372036854775807)
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.Error(t, err)
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.True(t, issues_model.IsErrPullRequestNotExist(err))
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequest_Update(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2017-02-07 17:17:55 +05:30
|
|
|
pr.BaseBranch = "baseBranch"
|
|
|
|
pr.HeadBranch = "headBranch"
|
2017-01-01 23:45:09 +05:30
|
|
|
pr.Update()
|
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: pr.ID})
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.Equal(t, "baseBranch", pr.BaseBranch)
|
|
|
|
assert.Equal(t, "headBranch", pr.HeadBranch)
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, pr)
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequest_UpdateCols(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2022-06-13 15:07:59 +05:30
|
|
|
pr := &issues_model.PullRequest{
|
2017-01-01 23:45:09 +05:30
|
|
|
ID: 1,
|
|
|
|
BaseBranch: "baseBranch",
|
|
|
|
HeadBranch: "headBranch",
|
|
|
|
}
|
2020-01-10 11:20:23 +05:30
|
|
|
assert.NoError(t, pr.UpdateCols("head_branch"))
|
2017-01-01 23:45:09 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
2017-01-01 23:45:09 +05:30
|
|
|
assert.Equal(t, "master", pr.BaseBranch)
|
|
|
|
assert.Equal(t, "headBranch", pr.HeadBranch)
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.CheckConsistencyFor(t, pr)
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequestList_LoadAttributes(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-01-01 23:45:09 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
prs := []*issues_model.PullRequest{
|
2022-08-16 07:52:25 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1}),
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}),
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, issues_model.PullRequestList(prs).LoadAttributes())
|
2017-01-01 23:45:09 +05:30
|
|
|
for _, pr := range prs {
|
|
|
|
assert.NotNil(t, pr.Issue)
|
|
|
|
assert.Equal(t, pr.IssueID, pr.Issue.ID)
|
|
|
|
}
|
2017-01-09 08:45:07 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, issues_model.PullRequestList([]*issues_model.PullRequest{}).LoadAttributes())
|
2017-01-01 23:45:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// TODO TestAddTestPullRequestTask
|
|
|
|
|
2018-08-14 00:34:39 +05:30
|
|
|
func TestPullRequest_IsWorkInProgress(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2018-08-14 00:34:39 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
2022-11-19 13:42:33 +05:30
|
|
|
pr.LoadIssue(db.DefaultContext)
|
2018-08-14 00:34:39 +05:30
|
|
|
|
|
|
|
assert.False(t, pr.IsWorkInProgress())
|
|
|
|
|
|
|
|
pr.Issue.Title = "WIP: " + pr.Issue.Title
|
|
|
|
assert.True(t, pr.IsWorkInProgress())
|
|
|
|
|
|
|
|
pr.Issue.Title = "[wip]: " + pr.Issue.Title
|
|
|
|
assert.True(t, pr.IsWorkInProgress())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPullRequest_GetWorkInProgressPrefixWorkInProgress(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2018-08-14 00:34:39 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
2022-11-19 13:42:33 +05:30
|
|
|
pr.LoadIssue(db.DefaultContext)
|
2018-08-14 00:34:39 +05:30
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.Empty(t, pr.GetWorkInProgressPrefix(db.DefaultContext))
|
2018-08-14 00:34:39 +05:30
|
|
|
|
|
|
|
original := pr.Issue.Title
|
|
|
|
pr.Issue.Title = "WIP: " + original
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.Equal(t, "WIP:", pr.GetWorkInProgressPrefix(db.DefaultContext))
|
2018-08-14 00:34:39 +05:30
|
|
|
|
|
|
|
pr.Issue.Title = "[wip] " + original
|
2022-11-19 13:42:33 +05:30
|
|
|
assert.Equal(t, "[wip]", pr.GetWorkInProgressPrefix(db.DefaultContext))
|
2018-08-14 00:34:39 +05:30
|
|
|
}
|
2022-06-13 15:07:59 +05:30
|
|
|
|
|
|
|
func TestDeleteOrphanedObjects(t *testing.T) {
|
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
|
|
|
|
countBefore, err := db.GetEngine(db.DefaultContext).Count(&issues_model.PullRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = db.GetEngine(db.DefaultContext).Insert(&issues_model.PullRequest{IssueID: 1000}, &issues_model.PullRequest{IssueID: 1001}, &issues_model.PullRequest{IssueID: 1003})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
orphaned, err := db.CountOrphanedObjects(db.DefaultContext, "pull_request", "issue", "pull_request.issue_id=issue.id")
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 3, orphaned)
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
err = db.DeleteOrphanedObjects(db.DefaultContext, "pull_request", "issue", "pull_request.issue_id=issue.id")
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
countAfter, err := db.GetEngine(db.DefaultContext).Count(&issues_model.PullRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, countBefore, countAfter)
|
|
|
|
}
|