diff --git a/api/queries.go b/api/queries.go index 7bd121441..624f60897 100644 --- a/api/queries.go +++ b/api/queries.go @@ -38,6 +38,7 @@ type PullRequest struct { } } } + Commits struct { Nodes []struct { Commit struct { @@ -60,6 +61,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 @@ -258,6 +266,11 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st title url headRefName + headRefName + headRepositoryOwner { + login + } + isCrossRepository commits(last: 1) { nodes { commit { @@ -536,6 +549,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 6ffa56e8e..c58877760 100644 --- a/command/pr.go +++ b/command/pr.go @@ -209,10 +209,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 @@ -353,7 +353,7 @@ func prCheckout(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" + } } }, {