issue #2329: include PR status in the prompt's options
This commit is contained in:
parent
4bc90101cd
commit
5109336963
5 changed files with 71 additions and 71 deletions
|
|
@ -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(),
|
||||
))
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue