@@ -52,13 +52,16 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xor
5252
5353// GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
5454// 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 ) {
5657 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 ).
6059 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 )
6265}
6366
6467// 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 *
7174 return false
7275 }
7376
74- prs , err := GetUnmergedPullRequestsByHeadInfo (p .Units [0 ].RepoID , branch )
77+ prs , err := GetUnmergedPullRequestsByHeadInfo (p .Units [0 ].RepoID , branch , false )
7578 if err != nil {
7679 return false
7780 }
0 commit comments