summaryrefslogtreecommitdiffstats
path: root/models/pull_list.go
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2022-01-04 03:45:58 +0800
committerGitHub <noreply@github.com>2022-01-03 20:45:58 +0100
commit637c3ec5d82f9d727724cc362aea37eeb2f64b40 (patch)
tree2b3af5ec2e6595d037a78b8a45e0a95210ab7d14 /models/pull_list.go
parent650a50a7ba8efcd8d02c4c93e5abc19f27e6c4b5 (diff)
downloadgitea-637c3ec5d82f9d727724cc362aea37eeb2f64b40.tar.gz
gitea-637c3ec5d82f9d727724cc362aea37eeb2f64b40.zip
Don't delete branch if other PRs with this branch are open (#18164)
fix #18149 Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'models/pull_list.go')
-rw-r--r--models/pull_list.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/models/pull_list.go b/models/pull_list.go
index 7c5b83ae5f..9d4d428928 100644
--- a/models/pull_list.go
+++ b/models/pull_list.go
@@ -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) {