From b77c37df0f17b596d07569e455d454b64e3bc75e Mon Sep 17 00:00:00 2001 From: yasudanaoya <43776161+yasudanaoya@users.noreply.github.com> Date: Thu, 27 Jan 2022 17:19:37 +0900 Subject: [PATCH] feat: add job id, into run view suggest command (#5105) * feat: add job id, into run view suggest command * fix: dry * fix: run id to job id * Change "a" to "the" when referencing a single job Co-authored-by: Sam Coe --- pkg/cmd/run/view/view.go | 4 +++- pkg/cmd/run/view/view_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index 73dea9e6a..a01e8c2f2 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -362,8 +362,10 @@ func runView(opts *ViewOptions) error { fmt.Fprintln(out) if shared.IsFailureState(run.Conclusion) { fmt.Fprintf(out, "To see what failed, try: gh run view %d --log-failed\n", run.ID) + } else if len(jobs) == 1 { + fmt.Fprintf(out, "For more information about the job, try: gh run view --job=%d\n", jobs[0].ID) } else { - fmt.Fprintln(out, "For more information about a job, try: gh run view --job=") + fmt.Fprintf(out, "For more information about a job, try: gh run view --job=\n") } fmt.Fprintf(out, cs.Gray("View this run on GitHub: %s\n"), run.URL) diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index 2a0540985..c93b6099f 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -207,7 +207,7 @@ func TestViewRun(t *testing.T) { httpmock.REST("GET", "repos/OWNER/REPO/check-runs/10/annotations"), httpmock.JSONResponse([]shared.Annotation{})) }, - wantOut: "\n✓ trunk successful #2898 · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n\nFor more information about a job, try: gh run view --job=\nView this run on GitHub: https://github.com/runs/3\n", + wantOut: "\n✓ trunk successful #2898 · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n\nFor more information about the job, try: gh run view --job=10\nView this run on GitHub: https://github.com/runs/3\n", }, { name: "exit status, failed run", @@ -308,7 +308,7 @@ func TestViewRun(t *testing.T) { httpmock.REST("GET", "repos/OWNER/REPO/check-runs/10/annotations"), httpmock.JSONResponse([]shared.Annotation{})) }, - wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n\nFor more information about a job, try: gh run view --job=\nView this run on GitHub: https://github.com/runs/3\n", + wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n\nFor more information about the job, try: gh run view --job=10\nView this run on GitHub: https://github.com/runs/3\n", }, { name: "verbose", @@ -381,7 +381,7 @@ func TestViewRun(t *testing.T) { opts: &ViewOptions{ Prompt: true, }, - wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n\nFor more information about a job, try: gh run view --job=\nView this run on GitHub: https://github.com/runs/3\n", + wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n\nFor more information about the job, try: gh run view --job=10\nView this run on GitHub: https://github.com/runs/3\n", }, { name: "interactive with log",