diff --git a/api/queries_pr.go b/api/queries_pr.go index 09a26f13a..265378b1e 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -10,7 +10,7 @@ import ( type PullRequestsPayload struct { ViewerCreated PullRequestAndTotalCount ReviewRequested PullRequestAndTotalCount - CurrentPR *PullRequest + CurrentPRs []PullRequest } type PullRequestAndTotalCount struct { @@ -151,6 +151,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu fragment pr on PullRequest { number title + state url headRefName headRepositoryOwner { @@ -187,7 +188,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu queryPrefix := ` query($owner: String!, $repo: String!, $headRefName: String!, $viewerQuery: String!, $reviewerQuery: String!, $per_page: Int = 10) { repository(owner: $owner, name: $repo) { - pullRequests(headRefName: $headRefName, states: OPEN, first: $per_page) { + pullRequests(headRefName: $headRefName, first: $per_page, orderBy: { field: CREATED_AT, direction: DESC }) { totalCount edges { node { @@ -261,11 +262,13 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu reviewRequested = append(reviewRequested, edge.Node) } - var currentPR = resp.Repository.PullRequest - if currentPR == nil { + var currentPRs []PullRequest + if resp.Repository.PullRequest != nil { + currentPRs = append(currentPRs, *resp.Repository.PullRequest) + } else { for _, edge := range resp.Repository.PullRequests.Edges { if edge.Node.HeadLabel() == currentPRHeadRef { - currentPR = &edge.Node + currentPRs = append(currentPRs, edge.Node) } } } @@ -279,7 +282,7 @@ func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, cu PullRequests: reviewRequested, TotalCount: resp.ReviewRequested.TotalCount, }, - CurrentPR: currentPR, + CurrentPRs: currentPRs, } return &payload, nil diff --git a/command/pr.go b/command/pr.go index a318154be..1df366364 100644 --- a/command/pr.go +++ b/command/pr.go @@ -97,8 +97,8 @@ func prStatus(cmd *cobra.Command, args []string) error { fmt.Fprintln(out, "") printHeader(out, "Current branch") - if prPayload.CurrentPR != nil { - printPrs(out, 0, *prPayload.CurrentPR) + if prPayload.CurrentPRs != nil { + printPrs(out, 0, prPayload.CurrentPRs...) } else { message := fmt.Sprintf(" There is no pull request associated with %s", utils.Cyan("["+currentPRHeadRef+"]")) printMessage(out, message) @@ -397,6 +397,10 @@ func printPrs(w io.Writer, totalCount int, prs ...api.PullRequest) { prNumberColorFunc := utils.Green if pr.IsDraft { prNumberColorFunc = utils.Gray + } else if pr.State == "MERGED" { + prNumberColorFunc = utils.Magenta + } else if pr.State == "CLOSED" { + prNumberColorFunc = utils.Red } fmt.Fprintf(w, " %s %s %s", prNumberColorFunc(prNumber), text.Truncate(50, replaceExcessiveWhitespace(pr.Title)), utils.Cyan("["+pr.HeadLabel()+"]"))