Skip to content

Commit a1cedfc

Browse files
author
Nate Smith
authored
Merge pull request cli#3741 from jack1142/patch-1
Include issue number alongside the title in `gh issue/pr view`
2 parents 4d90005 + 6a74eb1 commit a1cedfc

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

pkg/cmd/issue/view/view.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func printRawIssuePreview(out io.Writer, issue *api.Issue) error {
160160
milestoneTitle = issue.Milestone.Title
161161
}
162162
fmt.Fprintf(out, "milestone:\t%s\n", milestoneTitle)
163+
fmt.Fprintf(out, "number:\t%d\n", issue.Number)
163164
fmt.Fprintln(out, "--")
164165
fmt.Fprintln(out, issue.Body)
165166
return nil
@@ -172,7 +173,7 @@ func printHumanIssuePreview(opts *ViewOptions, issue *api.Issue) error {
172173
cs := opts.IO.ColorScheme()
173174

174175
// Header (Title and State)
175-
fmt.Fprintln(out, cs.Bold(issue.Title))
176+
fmt.Fprintf(out, "%s #%d\n", cs.Bold(issue.Title), issue.Number)
176177
fmt.Fprintf(out,
177178
"%s • %s opened %s • %s\n",
178179
issueStateTitleWithColor(cs, issue.State),

pkg/cmd/issue/view/view_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func TestIssueView_nontty_Preview(t *testing.T) {
112112
`comments:\t9`,
113113
`author:\tmarseilles`,
114114
`assignees:`,
115+
`number:\t123\n`,
115116
`\*\*bold story\*\*`,
116117
},
117118
},
@@ -126,6 +127,7 @@ func TestIssueView_nontty_Preview(t *testing.T) {
126127
`labels:\tone, two, three, four, five`,
127128
`projects:\tProject 1 \(column A\), Project 2 \(column B\), Project 3 \(column C\), Project 4 \(Awaiting triage\)\n`,
128129
`milestone:\tuluru\n`,
130+
`number:\t123\n`,
129131
`\*\*bold story\*\*`,
130132
},
131133
},
@@ -136,6 +138,7 @@ func TestIssueView_nontty_Preview(t *testing.T) {
136138
`state:\tOPEN`,
137139
`author:\tmarseilles`,
138140
`labels:\ttarot`,
141+
`number:\t123\n`,
139142
},
140143
},
141144
"Closed issue": {
@@ -146,6 +149,7 @@ func TestIssueView_nontty_Preview(t *testing.T) {
146149
`\*\*bold story\*\*`,
147150
`author:\tmarseilles`,
148151
`labels:\ttarot`,
152+
`number:\t123\n`,
149153
`\*\*bold story\*\*`,
150154
},
151155
},
@@ -178,7 +182,7 @@ func TestIssueView_tty_Preview(t *testing.T) {
178182
"Open issue without metadata": {
179183
fixture: "./fixtures/issueView_preview.json",
180184
expectedOutputs: []string{
181-
`ix of coins`,
185+
`ix of coins #123`,
182186
`Open.*marseilles opened about 9 years ago.*9 comments`,
183187
`bold story`,
184188
`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`,
@@ -187,7 +191,7 @@ func TestIssueView_tty_Preview(t *testing.T) {
187191
"Open issue with metadata": {
188192
fixture: "./fixtures/issueView_previewWithMetadata.json",
189193
expectedOutputs: []string{
190-
`ix of coins`,
194+
`ix of coins #123`,
191195
`Open.*marseilles opened about 9 years ago.*9 comments`,
192196
`8 \x{1f615} • 7 \x{1f440} • 6 \x{2764}\x{fe0f} • 5 \x{1f389} • 4 \x{1f604} • 3 \x{1f680} • 2 \x{1f44e} • 1 \x{1f44d}`,
193197
`Assignees:.*marseilles, monaco\n`,
@@ -201,7 +205,7 @@ func TestIssueView_tty_Preview(t *testing.T) {
201205
"Open issue with empty body": {
202206
fixture: "./fixtures/issueView_previewWithEmptyBody.json",
203207
expectedOutputs: []string{
204-
`ix of coins`,
208+
`ix of coins #123`,
205209
`Open.*marseilles opened about 9 years ago.*9 comments`,
206210
`No description provided`,
207211
`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`,
@@ -210,7 +214,7 @@ func TestIssueView_tty_Preview(t *testing.T) {
210214
"Closed issue": {
211215
fixture: "./fixtures/issueView_previewClosedState.json",
212216
expectedOutputs: []string{
213-
`ix of coins`,
217+
`ix of coins #123`,
214218
`Closed.*marseilles opened about 9 years ago.*9 comments`,
215219
`bold story`,
216220
`View this issue on GitHub: https://github.com/OWNER/REPO/issues/123`,
@@ -310,7 +314,7 @@ func TestIssueView_tty_Comments(t *testing.T) {
310314
"IssueByNumber": "./fixtures/issueView_previewSingleComment.json",
311315
},
312316
expectedOutputs: []string{
313-
`some title`,
317+
`some title #123`,
314318
`some body`,
315319
`———————— Not showing 5 comments ————————`,
316320
`marseilles \(Collaborator\) • Jan 1, 2020 • Newest comment`,
@@ -326,7 +330,7 @@ func TestIssueView_tty_Comments(t *testing.T) {
326330
"CommentsForIssue": "./fixtures/issueView_previewFullComments.json",
327331
},
328332
expectedOutputs: []string{
329-
`some title`,
333+
`some title #123`,
330334
`some body`,
331335
`monalisa • Jan 1, 2020 • Edited`,
332336
`1 \x{1f615} • 2 \x{1f440} • 3 \x{2764}\x{fe0f} • 4 \x{1f389} • 5 \x{1f604} • 6 \x{1f680} • 7 \x{1f44e} • 8 \x{1f44d}`,
@@ -386,6 +390,7 @@ func TestIssueView_nontty_Comments(t *testing.T) {
386390
`state:\tOPEN`,
387391
`author:\tmarseilles`,
388392
`comments:\t6`,
393+
`number:\t123`,
389394
`some body`,
390395
},
391396
},

pkg/cmd/pr/view/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func printHumanPrPreview(opts *ViewOptions, pr *api.PullRequest) error {
170170
cs := opts.IO.ColorScheme()
171171

172172
// Header (Title and State)
173-
fmt.Fprintln(out, cs.Bold(pr.Title))
173+
fmt.Fprintf(out, "%s #%d\n", cs.Bold(pr.Title), pr.Number)
174174
fmt.Fprintf(out,
175175
"%s • %s wants to merge %s into %s from %s • %s %s \n",
176176
shared.StateTitleWithColor(cs, *pr),

pkg/cmd/pr/view/view_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func TestPRView_Preview(t *testing.T) {
350350
"PullRequestByNumber": "./fixtures/prViewPreview.json",
351351
},
352352
expectedOutputs: []string{
353-
`Blueberries are from a fork`,
353+
`Blueberries are from a fork #12`,
354354
`Open.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
355355
`blueberries taste good`,
356356
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
@@ -363,7 +363,7 @@ func TestPRView_Preview(t *testing.T) {
363363
"PullRequestByNumber": "./fixtures/prViewPreviewWithMetadataByNumber.json",
364364
},
365365
expectedOutputs: []string{
366-
`Blueberries are from a fork`,
366+
`Blueberries are from a fork #12`,
367367
`Open.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
368368
`Reviewers:.*1 \(.*Requested.*\)\n`,
369369
`Assignees:.*marseilles, monaco\n`,
@@ -382,7 +382,7 @@ func TestPRView_Preview(t *testing.T) {
382382
"ReviewsForPullRequest": "./fixtures/prViewPreviewManyReviews.json",
383383
},
384384
expectedOutputs: []string{
385-
`Blueberries are from a fork`,
385+
`Blueberries are from a fork #12`,
386386
`Reviewers: DEF \(Commented\), def \(Changes requested\), ghost \(Approved\), hubot \(Commented\), xyz \(Approved\), 123 \(Requested\), abc \(Requested\), my-org\/team-1 \(Requested\)`,
387387
`blueberries taste good`,
388388
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
@@ -395,7 +395,7 @@ func TestPRView_Preview(t *testing.T) {
395395
"PullRequestByNumber": "./fixtures/prViewPreviewClosedState.json",
396396
},
397397
expectedOutputs: []string{
398-
`Blueberries are from a fork`,
398+
`Blueberries are from a fork #12`,
399399
`Closed.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
400400
`blueberries taste good`,
401401
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
@@ -408,7 +408,7 @@ func TestPRView_Preview(t *testing.T) {
408408
"PullRequestByNumber": "./fixtures/prViewPreviewMergedState.json",
409409
},
410410
expectedOutputs: []string{
411-
`Blueberries are from a fork`,
411+
`Blueberries are from a fork #12`,
412412
`Merged.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
413413
`blueberries taste good`,
414414
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
@@ -421,7 +421,7 @@ func TestPRView_Preview(t *testing.T) {
421421
"PullRequestByNumber": "./fixtures/prViewPreviewDraftState.json",
422422
},
423423
expectedOutputs: []string{
424-
`Blueberries are from a fork`,
424+
`Blueberries are from a fork #12`,
425425
`Draft.*nobody wants to merge 12 commits into master from blueberries.+100.-10`,
426426
`blueberries taste good`,
427427
`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`,
@@ -501,7 +501,7 @@ func TestPRView_tty_Comments(t *testing.T) {
501501
"ReviewsForPullRequest": "./fixtures/prViewPreviewReviews.json",
502502
},
503503
expectedOutputs: []string{
504-
`some title`,
504+
`some title #12`,
505505
`1 \x{1f615} • 2 \x{1f440} • 3 \x{2764}\x{fe0f}`,
506506
`some body`,
507507
`———————— Not showing 9 comments ————————`,
@@ -521,7 +521,7 @@ func TestPRView_tty_Comments(t *testing.T) {
521521
"CommentsForPullRequest": "./fixtures/prViewPreviewFullComments.json",
522522
},
523523
expectedOutputs: []string{
524-
`some title`,
524+
`some title #12`,
525525
`some body`,
526526
`monalisa • Jan 1, 2020 • Edited`,
527527
`1 \x{1f615} • 2 \x{1f440} • 3 \x{2764}\x{fe0f} • 4 \x{1f389} • 5 \x{1f604} • 6 \x{1f680} • 7 \x{1f44e} • 8 \x{1f44d}`,

0 commit comments

Comments
 (0)