@@ -52,13 +52,15 @@ 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+ func GetUnmergedPullRequestsByHeadInfo (repoID int64 , branch string , mustOpenedPR bool ) ([]* PullRequest , error ) {
5656 prs := make ([]* PullRequest , 0 , 2 )
57- return prs , db .GetEngine (db .DefaultContext ).
58- Where ("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND flow = ?" ,
59- repoID , branch , false , PullRequestFlowGithub ).
57+ sess := db .GetEngine (db .DefaultContext ).
6058 Join ("INNER" , "issue" , "issue.id = pull_request.issue_id" ).
61- Find (& prs )
59+ Where ("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND flow = ?" , repoID , branch , false , PullRequestFlowGithub )
60+ if mustOpenedPR {
61+ sess .Where ("issue.is_closed = ?" , false )
62+ }
63+ return prs , sess .Find (& prs )
6264}
6365
6466// CanMaintainerWriteToBranch check whether user is a maintainer and could write to the branch
@@ -71,7 +73,7 @@ func CanMaintainerWriteToBranch(p access_model.Permission, branch string, user *
7173 return false
7274 }
7375
74- prs , err := GetUnmergedPullRequestsByHeadInfo (p .Units [0 ].RepoID , branch )
76+ prs , err := GetUnmergedPullRequestsByHeadInfo (p .Units [0 ].RepoID , branch , true )
7577 if err != nil {
7678 return false
7779 }
0 commit comments