@@ -736,7 +736,9 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea
736736 return nil , err
737737 }
738738
739- prs := sortPullRequestsByState (resp .Repository .PullRequests .Nodes )
739+ prs := resp .Repository .PullRequests .Nodes
740+ sortPullRequestsByState (prs )
741+
740742 for _ , pr := range prs {
741743 if pr .HeadLabel () == headBranch {
742744 if baseBranch != "" {
@@ -751,6 +753,13 @@ func PullRequestForBranch(client *Client, repo ghrepo.Interface, baseBranch, hea
751753 return nil , & NotFoundError {fmt .Errorf ("no pull requests found for branch %q" , headBranch )}
752754}
753755
756+ // sortPullRequestsByState sorts a PullRequest slice by open-first
757+ func sortPullRequestsByState (prs []PullRequest ) {
758+ sort .SliceStable (prs , func (a , b int ) bool {
759+ return prs [a ].State == "OPEN"
760+ })
761+ }
762+
754763// CreatePullRequest creates a pull request in a GitHub repository
755764func CreatePullRequest (client * Client , repo * Repository , params map [string ]interface {}) (* PullRequest , error ) {
756765 query := `
@@ -1152,14 +1161,6 @@ func BranchDeleteRemote(client *Client, repo ghrepo.Interface, branch string) er
11521161 return client .REST (repo .RepoHost (), "DELETE" , path , nil , nil )
11531162}
11541163
1155- // sortPullRequestsByState ensures that OPEN PRs precede non-open states (MERGED, CLOSED)
1156- func sortPullRequestsByState (prs []PullRequest ) []PullRequest {
1157- sort .SliceStable (prs , func (a , b int ) bool {
1158- return prs [a ].State == "OPEN"
1159- })
1160- return prs
1161- }
1162-
11631164func min (a , b int ) int {
11641165 if a < b {
11651166 return a
0 commit comments