@@ -52,13 +52,16 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xor
52
52
53
53
// GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
54
54
// by given head information (repo and branch).
55
- func GetUnmergedPullRequestsByHeadInfo (repoID int64 , branch string ) ([]* PullRequest , error ) {
55
+ // arg `includeClosed` controls whether the SQL returns closed PRs
56
+ func GetUnmergedPullRequestsByHeadInfo (repoID int64 , branch string , includeClosed bool ) ([]* PullRequest , error ) {
56
57
prs := make ([]* PullRequest , 0 , 2 )
57
- return prs , db .GetEngine (db .DefaultContext ).
58
- Where ("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?" ,
59
- repoID , branch , false , false , PullRequestFlowGithub ).
58
+ sess := db .GetEngine (db .DefaultContext ).
60
59
Join ("INNER" , "issue" , "issue.id = pull_request.issue_id" ).
61
- Find (& prs )
60
+ Where ("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND flow = ?" , repoID , branch , false , PullRequestFlowGithub )
61
+ if ! includeClosed {
62
+ sess .Where ("issue.is_closed = ?" , false )
63
+ }
64
+ return prs , sess .Find (& prs )
62
65
}
63
66
64
67
// CanMaintainerWriteToBranch check whether user is a maintainer and could write to the branch
@@ -71,7 +74,7 @@ func CanMaintainerWriteToBranch(p access_model.Permission, branch string, user *
71
74
return false
72
75
}
73
76
74
- prs , err := GetUnmergedPullRequestsByHeadInfo (p .Units [0 ].RepoID , branch )
77
+ prs , err := GetUnmergedPullRequestsByHeadInfo (p .Units [0 ].RepoID , branch , false )
75
78
if err != nil {
76
79
return false
77
80
}
0 commit comments