Merge pull request #63 from github/branch-from-fork

Use `OWNER:BRANCH` syntax for cross-repo PRs
This commit is contained in:
Mislav Marohnić 2019-11-15 09:28:00 +01:00 committed by GitHub
commit 624c44efda
4 changed files with 33 additions and 6 deletions

View file

@ -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 {
@ -481,6 +500,10 @@ func PullRequestList(client *Client, vars map[string]interface{}, limit int) ([]
state
url
headRefName
headRepositoryOwner {
login
}
isCrossRepository
}
}
pageInfo {

View file

@ -200,10 +200,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
@ -250,7 +250,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()

View file

@ -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
`)
}

View file

@ -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"
}
}
},
{