forked from forgejo/forgejo
Don't delete branch if other PRs with this branch are open (#18164)
fix #18149 Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
parent
650a50a7ba
commit
637c3ec5d8
5 changed files with 68 additions and 1 deletions
|
@ -59,6 +59,16 @@ func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequ
|
|||
Find(&prs)
|
||||
}
|
||||
|
||||
// HasUnmergedPullRequestsByHeadInfo checks if there are open and not merged pull request
|
||||
// by given head information (repo and branch)
|
||||
func HasUnmergedPullRequestsByHeadInfo(repoID int64, branch string) (bool, error) {
|
||||
return db.GetEngine(db.DefaultContext).
|
||||
Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?",
|
||||
repoID, branch, false, false, PullRequestFlowGithub).
|
||||
Join("INNER", "issue", "issue.id = pull_request.issue_id").
|
||||
Exist(&PullRequest{})
|
||||
}
|
||||
|
||||
// GetUnmergedPullRequestsByBaseInfo returns all pull requests that are open and has not been merged
|
||||
// by given base information (repo and branch).
|
||||
func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequest, error) {
|
||||
|
|
|
@ -107,6 +107,18 @@ func TestGetUnmergedPullRequest(t *testing.T) {
|
|||
assert.True(t, IsErrPullRequestNotExist(err))
|
||||
}
|
||||
|
||||
func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
exist, err := HasUnmergedPullRequestsByHeadInfo(1, "branch2")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, exist)
|
||||
|
||||
exist, err = HasUnmergedPullRequestsByHeadInfo(1, "not_exist_branch")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, false, exist)
|
||||
}
|
||||
|
||||
func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
prs, err := GetUnmergedPullRequestsByHeadInfo(1, "branch2")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue