X Tutup
Skip to content

Commit 624c44e

Browse files
authored
Merge pull request cli#63 from github/branch-from-fork
Use `OWNER:BRANCH` syntax for cross-repo PRs
2 parents 1479ff4 + 0c2d887 commit 624c44e

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

api/queries.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ type PullRequest struct {
1717
State string
1818
URL string
1919
HeadRefName string
20-
Reviews struct {
20+
21+
IsCrossRepository bool
22+
HeadRepositoryOwner struct {
23+
Login string
24+
}
25+
26+
Reviews struct {
2127
Nodes []struct {
2228
State string
2329
Author struct {
2430
Login string
2531
}
2632
}
2733
}
34+
2835
Commits struct {
2936
Nodes []struct {
3037
Commit struct {
@@ -47,6 +54,13 @@ type PullRequest struct {
4754
}
4855
}
4956

57+
func (pr PullRequest) HeadLabel() string {
58+
if pr.IsCrossRepository {
59+
return fmt.Sprintf("%s:%s", pr.HeadRepositoryOwner.Login, pr.HeadRefName)
60+
}
61+
return pr.HeadRefName
62+
}
63+
5064
type PullRequestReviewStatus struct {
5165
ChangesRequested bool
5266
Approved bool
@@ -245,6 +259,11 @@ func PullRequests(client *Client, ghRepo Repo, currentBranch, currentUsername st
245259
title
246260
url
247261
headRefName
262+
headRefName
263+
headRepositoryOwner {
264+
login
265+
}
266+
isCrossRepository
248267
commits(last: 1) {
249268
nodes {
250269
commit {
@@ -481,6 +500,10 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
481500
state
482501
url
483502
headRefName
503+
headRepositoryOwner {
504+
login
505+
}
506+
isCrossRepository
484507
}
485508
}
486509
pageInfo {

command/pr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ func prList(cmd *cobra.Command, args []string) error {
200200
case "MERGED":
201201
prNum = utils.Magenta(prNum)
202202
}
203-
prBranch := utils.Cyan(truncate(branchWidth, pr.HeadRefName))
203+
prBranch := utils.Cyan(truncate(branchWidth, pr.HeadLabel()))
204204
fmt.Fprintf(out, "%s %-*s %s\n", prNum, titleWidth, truncate(titleWidth, pr.Title), prBranch)
205205
} else {
206-
fmt.Fprintf(out, "%d\t%s\t%s\n", pr.Number, pr.Title, pr.HeadRefName)
206+
fmt.Fprintf(out, "%d\t%s\t%s\n", pr.Number, pr.Title, pr.HeadLabel())
207207
}
208208
}
209209
return nil
@@ -250,7 +250,7 @@ func prView(cmd *cobra.Command, args []string) error {
250250
func printPrs(prs ...api.PullRequest) {
251251
for _, pr := range prs {
252252
prNumber := fmt.Sprintf("#%d", pr.Number)
253-
fmt.Printf(" %s %s %s", utils.Yellow(prNumber), truncate(50, pr.Title), utils.Cyan("["+pr.HeadRefName+"]"))
253+
fmt.Printf(" %s %s %s", utils.Yellow(prNumber), truncate(50, pr.Title), utils.Cyan("["+pr.HeadLabel()+"]"))
254254

255255
checks := pr.ChecksStatus()
256256
reviews := pr.ReviewStatus()

command/pr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestPRList(t *testing.T) {
6666
}
6767

6868
eq(t, out.String(), `32 New feature feature
69-
29 Fixed bad bug bug-fix
69+
29 Fixed bad bug hubot:bug-fix
7070
28 Improve documentation docs
7171
`)
7272
}

test/fixtures/prList.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
"number": 29,
1717
"title": "Fixed bad bug",
1818
"url": "https://github.com/monalisa/hello/pull/29",
19-
"headRefName": "bug-fix"
19+
"headRefName": "bug-fix",
20+
"isCrossRepository": true,
21+
"headRepositoryOwner": {
22+
"login": "hubot"
23+
}
2024
}
2125
},
2226
{

0 commit comments

Comments
 (0)
X Tutup