diff --git a/pkg/cmd/pr/checkout/checkout.go b/pkg/cmd/pr/checkout/checkout.go index 71af45dda..88850b940 100644 --- a/pkg/cmd/pr/checkout/checkout.go +++ b/pkg/cmd/pr/checkout/checkout.go @@ -342,8 +342,9 @@ func resolvePR(httpClient *http.Client, baseRepo ghrepo.Interface, prompter shar func promptForPR(prompter shared.Prompter, jobs api.PullRequestAndTotalCount) (*api.PullRequest, error) { candidates := []string{} for _, pr := range jobs.PullRequests { - candidates = append(candidates, fmt.Sprintf("#%d %s [%s]", + candidates = append(candidates, fmt.Sprintf("%d\t%s\t%s [%s]", pr.Number, + shared.PrStateWithDraft(&pr), text.RemoveExcessiveWhitespace(pr.Title), pr.HeadLabel(), )) diff --git a/pkg/cmd/pr/checkout/checkout_test.go b/pkg/cmd/pr/checkout/checkout_test.go index 33173252e..f2b379912 100644 --- a/pkg/cmd/pr/checkout/checkout_test.go +++ b/pkg/cmd/pr/checkout/checkout_test.go @@ -239,9 +239,9 @@ func Test_checkoutRun(t *testing.T) { }, promptStubs: func(pm *prompter.MockPrompter) { pm.RegisterSelect("Select a pull request", - []string{"#32 New feature [feature]", "#29 Fixed bad bug [bug-fix]", "#28 Improve documentation [docs]"}, + []string{"32\tDRAFT\tNew feature [feature]", "29\tOPEN\tFixed bad bug [bug-fix]", "28\tOPEN\tImprove documentation [docs]"}, func(_, _ string, opts []string) (int, error) { - return prompter.IndexFor(opts, "#32 New feature [feature]") + return prompter.IndexFor(opts, "32\tDRAFT\tNew feature [feature]") }) }, runStubs: func(cs *run.CommandStubber) { diff --git a/pkg/cmd/pr/checkout/fixtures/prList.json b/pkg/cmd/pr/checkout/fixtures/prList.json index f915df136..84928722c 100644 --- a/pkg/cmd/pr/checkout/fixtures/prList.json +++ b/pkg/cmd/pr/checkout/fixtures/prList.json @@ -1,67 +1,66 @@ { - "data": { - "repository": { - "pullRequests": { - "totalCount": 3, - "nodes": [ - { - "number": 32, - "title": "New feature", - "url": "https://github.com/OWNER/REPO/pull/32", - "createdAt": "2022-08-24T20:01:12Z", - "headRefName": "feature", - "state": "OPEN", - "isDraft": true, - "isCrossRepository": false, - "headRepository": { - "name": "REPO" - }, - "headRepositoryOwner": { - "login": "OWNER" - }, - "maintainerCanModify": true + "data": { + "repository": { + "pullRequests": { + "totalCount": 3, + "nodes": [ + { + "number": 32, + "title": "New feature", + "url": "https://github.com/OWNER/REPO/pull/32", + "createdAt": "2022-08-24T20:01:12Z", + "headRefName": "feature", + "state": "OPEN", + "isDraft": true, + "isCrossRepository": false, + "headRepository": { + "name": "REPO" }, - { - "number": 29, - "title": "Fixed bad bug", - "url": "https://github.com/OWNER/REPO/pull/29", - "createdAt": "2022-07-20T19:01:12Z", - "headRefName": "bug-fix", - "state": "OPEN", - "isDraft": false, - "isCrossRepository": false, - "headRepository": { - "name": "REPO" - }, - "headRepositoryOwner": { - "login": "OWNER" - }, - "maintainerCanModify": true + "headRepositoryOwner": { + "login": "OWNER" }, - { - "number": 28, - "state": "MERGED", - "isDraft": false, - "title": "Improve documentation", - "createdAt": "2020-01-26T19:01:12Z", - "url": "https://github.com/OWNER/REPO/pull/28", - "isCrossRepository": false, - "headRefName": "docs", - "headRepository": { - "name": "REPO" - }, - "headRepositoryOwner": { - "login": "OWNER" - }, - "maintainerCanModify": true - } - ], - "pageInfo": { - "hasNextPage": false, - "endCursor": "" + "maintainerCanModify": true + }, + { + "number": 29, + "title": "Fixed bad bug", + "url": "https://github.com/OWNER/REPO/pull/29", + "createdAt": "2022-07-20T19:01:12Z", + "headRefName": "bug-fix", + "state": "OPEN", + "isDraft": false, + "isCrossRepository": false, + "headRepository": { + "name": "REPO" + }, + "headRepositoryOwner": { + "login": "OWNER" + }, + "maintainerCanModify": true + }, + { + "number": 28, + "state": "OPEN", + "isDraft": false, + "title": "Improve documentation", + "createdAt": "2020-01-26T19:01:12Z", + "url": "https://github.com/OWNER/REPO/pull/28", + "isCrossRepository": false, + "headRefName": "docs", + "headRepository": { + "name": "REPO" + }, + "headRepositoryOwner": { + "login": "OWNER" + }, + "maintainerCanModify": true } + ], + "pageInfo": { + "hasNextPage": false, + "endCursor": "" } } } } - \ No newline at end of file +} diff --git a/pkg/cmd/pr/list/list.go b/pkg/cmd/pr/list/list.go index 401e168e3..e5ebe50fb 100644 --- a/pkg/cmd/pr/list/list.go +++ b/pkg/cmd/pr/list/list.go @@ -222,7 +222,7 @@ func listRun(opts *ListOptions) error { table.AddField(text.RemoveExcessiveWhitespace(pr.Title)) table.AddField(pr.HeadLabel(), tableprinter.WithColor(cs.Cyan)) if !isTTY { - table.AddField(prStateWithDraft(&pr)) + table.AddField(shared.PrStateWithDraft(&pr)) } table.AddTimeField(opts.Now(), pr.CreatedAt, cs.Gray) table.EndRow() @@ -234,11 +234,3 @@ func listRun(opts *ListOptions) error { return nil } - -func prStateWithDraft(pr *api.PullRequest) string { - if pr.IsDraft && pr.State == "OPEN" { - return "DRAFT" - } - - return pr.State -} diff --git a/pkg/cmd/pr/shared/display.go b/pkg/cmd/pr/shared/display.go index 7bd306104..02482951c 100644 --- a/pkg/cmd/pr/shared/display.go +++ b/pkg/cmd/pr/shared/display.go @@ -17,6 +17,14 @@ func StateTitleWithColor(cs *iostreams.ColorScheme, pr api.PullRequest) string { return prStateColorFunc(text.Title(pr.State)) } +func PrStateWithDraft(pr *api.PullRequest) string { + if pr.IsDraft && pr.State == "OPEN" { + return "DRAFT" + } + + return pr.State +} + func ColorForPRState(pr api.PullRequest) string { switch pr.State { case "OPEN":