From 5f152a349dff5617a51638d352f7c7ad8596503d Mon Sep 17 00:00:00 2001 From: Toshiya Doi Date: Thu, 27 Feb 2020 00:07:48 +0900 Subject: [PATCH] Print merged and closed PRs of the current branch along with an opening PR --- api/queries_pr.go | 12 +++++++----- command/pr.go | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/queries_pr.go b/api/queries_pr.go index 4dc79acbd..fcfb3c914 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 { @@ -262,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) } } } @@ -280,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 1515e88a7..7cd12796a 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)