From 0c2d8879d1a18ad1d4f6395c8cbf1a23eaaee80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 14 Nov 2019 16:46:59 +0100 Subject: [PATCH] Use `OWNER:BRANCH` syntax for cross-repo PRs This affects `pr status` and `pr list`. --- api/queries.go | 25 ++++++++++++++++++++++++- command/pr.go | 6 +++--- command/pr_test.go | 2 +- test/fixtures/prList.json | 6 +++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/api/queries.go b/api/queries.go index 78b34b7e7..94a41af94 100644 --- a/api/queries.go +++ b/api/queries.go @@ -17,7 +17,13 @@ type PullRequest struct { State string URL string HeadRefName string - Reviews struct { + + IsCrossRepository bool + HeadRepositoryOwner struct { + Login string + } + + Reviews struct { Nodes []struct { State string Author struct { @@ -25,6 +31,7 @@ type PullRequest struct { } } } + Commits struct { Nodes []struct { Commit struct { @@ -47,6 +54,13 @@ type PullRequest struct { } } +func (pr PullRequest) HeadLabel() string { + if pr.IsCrossRepository { + return fmt.Sprintf("%s:%s", pr.HeadRepositoryOwner.Login, pr.HeadRefName) + } + return pr.HeadRefName +} + type PullRequestReviewStatus struct { ChangesRequested bool Approved bool @@ -245,6 +259,11 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st title url headRefName + headRefName + headRepositoryOwner { + login + } + isCrossRepository commits(last: 1) { nodes { commit { @@ -442,6 +461,10 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([] state url headRefName + headRepositoryOwner { + login + } + isCrossRepository } } pageInfo { diff --git a/command/pr.go b/command/pr.go index 037e2892b..63e10807c 100644 --- a/command/pr.go +++ b/command/pr.go @@ -199,10 +199,10 @@ func prList(cmd *cobra.Command, args []string) error { case "MERGED": prNum = utils.Magenta(prNum) } - prBranch := utils.Cyan(truncate(branchWidth, pr.HeadRefName)) + prBranch := utils.Cyan(truncate(branchWidth, pr.HeadLabel())) fmt.Fprintf(out, "%s %-*s %s\n", prNum, titleWidth, truncate(titleWidth, pr.Title), prBranch) } else { - fmt.Fprintf(out, "%d\t%s\t%s\n", pr.Number, pr.Title, pr.HeadRefName) + fmt.Fprintf(out, "%d\t%s\t%s\n", pr.Number, pr.Title, pr.HeadLabel()) } } return nil @@ -249,7 +249,7 @@ func prView(cmd *cobra.Command, args []string) error { func printPrs(prs ...api.PullRequest) { for _, pr := range prs { prNumber := fmt.Sprintf("#%d", pr.Number) - fmt.Printf(" %s %s %s", utils.Yellow(prNumber), truncate(50, pr.Title), utils.Cyan("["+pr.HeadRefName+"]")) + fmt.Printf(" %s %s %s", utils.Yellow(prNumber), truncate(50, pr.Title), utils.Cyan("["+pr.HeadLabel()+"]")) checks := pr.ChecksStatus() reviews := pr.ReviewStatus() diff --git a/command/pr_test.go b/command/pr_test.go index 863632ee9..47851a5e8 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -66,7 +66,7 @@ func TestPRList(t *testing.T) { } eq(t, out.String(), `32 New feature feature -29 Fixed bad bug bug-fix +29 Fixed bad bug hubot:bug-fix 28 Improve documentation docs `) } diff --git a/test/fixtures/prList.json b/test/fixtures/prList.json index 7ff9502a0..2808a5a8e 100644 --- a/test/fixtures/prList.json +++ b/test/fixtures/prList.json @@ -16,7 +16,11 @@ "number": 29, "title": "Fixed bad bug", "url": "https://github.com/monalisa/hello/pull/29", - "headRefName": "bug-fix" + "headRefName": "bug-fix", + "isCrossRepository": true, + "headRepositoryOwner": { + "login": "hubot" + } } }, {