-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[gh run watch] Support --compact flag
#10629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
22e092a to
37690a7
Compare
babakks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work on this PR, @iamazeem! 🎉
While I was reviewing the PR, I noticed there is no A/C on the issue, and also the expected experience described in the issue needs to be improved. I have commented on the issue and I'll wait for you and others in the team to have your thoughts on it. Then we can come back to this PR and give it a review.
pkg/cmd/run/shared/presentation.go
Outdated
| for _, step := range job.Steps { | ||
| stepSymbol, stepSymColor := Symbol(cs, step.Status, step.Conclusion) | ||
| lines = append(lines, fmt.Sprintf(" %s %s", stepSymColor(stepSymbol), step.Name)) | ||
|
|
||
| if compact { | ||
| if step.Status == InProgress || step.Status == Completed { | ||
| stepLogs = append(stepLogs, fmt.Sprintf(" %s %s", stepSymColor(stepSymbol), step.Name)) | ||
|
|
||
| if len(stepLogs) > 1 { | ||
| stepLogs = stepLogs[len(stepLogs)-1:] | ||
| } | ||
|
|
||
| if IsFailureState(step.Conclusion) { | ||
| break | ||
| } | ||
| } | ||
| } else { | ||
| stepLogs = append(stepLogs, fmt.Sprintf(" %s %s", stepSymColor(stepSymbol), step.Name)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @BagToad and I were checking the PR, we decided that it's best to have two separate functions for rendering in normal and compact modes. It'd be easier to read the code, and less conflated.
…cli into 4535-gh-run-watch-compact-flag
|
@babakks: Changes added according to the updated AC. Please review. Thanks! |
babakks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, @iamazeem! 🙏
It looks good and addresses the A/C. Thanks again!
However, it still needs a couple of small improvements, and also one test case in TestWatchRun to ensure the behaviour is as expected.
pkg/cmd/run/shared/presentation.go
Outdated
| return strings.Join(lines, "\n") | ||
| } | ||
|
|
||
| func RenderJobsInCompactMode(cs *iostreams.ColorScheme, jobs []Job) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it less verbose, please:
s/RenderJobsInCompactMode/RenderJobsCompact
pkg/cmd/run/shared/presentation.go
Outdated
| if job.Status == InProgress { | ||
| lines = append(lines, inProgressStepLine) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this if-statement is a bit confusing, since we already now the step is still in progress. Instead we should check if inProgressStepLine is not empty:
| if job.Status == InProgress { | |
| lines = append(lines, inProgressStepLine) | |
| } | |
| if inProgressStepLine != "" { | |
| lines = append(lines, inProgressStepLine) | |
| } |
pkg/cmd/run/watch/watch.go
Outdated
| By default, all the steps are shown with each refresh. | ||
| With the %[1]s--compact%[1]s flag: | ||
| - For a successfully completed job, not steps are shown. | ||
| - For a failed job, all the failed steps are shown. | ||
| - For an ongoing job with no failed steps, only the currently running step is shown. | ||
| - For an ongoing job with failed steps, the failed steps along with the currently running step are shown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the user doesn't need to see the details of the --compact mode here. Just saying it removes irrelevant steps from the output is enough.
| By default, all the steps are shown with each refresh. | |
| With the %[1]s--compact%[1]s flag: | |
| - For a successfully completed job, not steps are shown. | |
| - For a failed job, all the failed steps are shown. | |
| - For an ongoing job with no failed steps, only the currently running step is shown. | |
| - For an ongoing job with failed steps, the failed steps along with the currently running step are shown. | |
| By default, all steps are displayed. The %[1]s--compact%[1]s option can be used | |
| to only show the relevant/failed steps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Watch a run in compact mode | ||
| $ gh run watch --compact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: This can be pulled up to appear after the simple gh run watch example.
pkg/cmd/run/watch/watch.go
Outdated
| }, | ||
| } | ||
| cmd.Flags().BoolVar(&opts.ExitStatus, "exit-status", false, "Exit with non-zero status if run fails") | ||
| cmd.Flags().BoolVar(&opts.Compact, "compact", false, "Enable compact mode") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description should be a bit more:
| cmd.Flags().BoolVar(&opts.Compact, "compact", false, "Enable compact mode") | |
| cmd.Flags().BoolVar(&opts.Compact, "compact", false, "Show only relevant/failed steps") |
pkg/cmd/run/watch/watch.go
Outdated
| verbose := true | ||
| fmt.Fprintln(out, shared.RenderJobs(cs, jobs, verbose)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temp var verbose is redundant here.
| verbose := true | |
| fmt.Fprintln(out, shared.RenderJobs(cs, jobs, verbose)) | |
| fmt.Fprintln(out, shared.RenderJobs(cs, jobs, true)) |
| { | ||
| name: "compact status", | ||
| cli: "1234 --compact", | ||
| wants: WatchOptions{ | ||
| Interval: defaultInterval, | ||
| RunID: "1234", | ||
| Compact: true, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need a test case in TestWatchRun to cover the changes we made.
I think it's okay to just have a single test case that covers all cases. I know adding such tests is a bit annoying. 😄 So, let me know if I can help with that. 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@babakks: Regarding tests, I looked into it.
Apparently, there needs to be separate tests for in-progress and completed scenarios. 🤔
It'd be great if you added tests. Thanks!
babakks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
I'm going to add the test we talked about and will then merge this.
Signed-off-by: Babak K. Shandiz <[email protected]>
|
Since this might take a while and I'm going to add a couple of tests for the functions in UPDATE: Just pushed a quick docs improvement to this. |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [cli/cli](https://github.com/cli/cli) | minor | `v2.73.0` -> `v2.74.1` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>cli/cli (cli/cli)</summary> ### [`v2.74.1`](https://github.com/cli/cli/releases/tag/v2.74.1): GitHub CLI 2.74.1 [Compare Source](cli/cli@v2.74.0...v2.74.1) #### What's Changed - Document support for `@copilot` in `gh [pr|issue] edit --add-assignee` and `--remove-assignee` by [@​timrogers](https://github.com/timrogers) in cli/cli#11056 - Fix pr edit when URL is provided by [@​williammartin](https://github.com/williammartin) in cli/cli#11057 - Fix const in MR finder tests by [@​babakks](https://github.com/babakks) in cli/cli#11091 **Full Changelog**: cli/cli@v2.74.0...v2.74.1 ### [`v2.74.0`](https://github.com/cli/cli/releases/tag/v2.74.0): GitHub CLI 2.74.0 [Compare Source](cli/cli@v2.73.0...v2.74.0) #### Security A security vulnerability has been identified in a core `gh` dependency, `go-gh`, where an attacker-controlled GitHub Enterprise Server could result in executing arbitrary commands on a user's machine by replacing HTTP URLs provided by GitHub with local file paths for browsing. This issue is addressed in this `gh` release by updating `go-gh` to a fixed version. For more information, see GHSA-g9f5-x53j-h563 #### What's changed ##### ✨ Features - Add `preview prompter` command by [@​BagToad](https://github.com/BagToad) in cli/cli#10745 - \[gh run watch] Support `--compact` flag by [@​iamazeem](https://github.com/iamazeem) in cli/cli#10629 - Fix brew update notifications by [@​BagToad](https://github.com/BagToad) in cli/cli#11024 ##### 🐛 Fixes - Revert "\[gh config] Escape pipe symbol in Long desc for website manual" by [@​BagToad](https://github.com/BagToad) in cli/cli#11004 - Fix formatting in allowed values for `gh config --help` by [@​BagToad](https://github.com/BagToad) in cli/cli#11003 - fix: `gh gist edit` panic when no file in a gist by [@​phanen](https://github.com/phanen) in cli/cli#10627 - Add retry logic when fetching TUF content in `gh attestation` commands by [@​malancas](https://github.com/malancas) in cli/cli#10943 ##### 📚 Docs & Chores - Update README.md by [@​irhdab](https://github.com/irhdab) in cli/cli#11022 - Add tests for `RenderJobs` and `RenderJobsCompact` by [@​babakks](https://github.com/babakks) in cli/cli#11013 - Add example usage of `--head` option to `pr list` docs by [@​babakks](https://github.com/babakks) in cli/cli#10979 - Mention `pr create` will print the created MR's URL by [@​babakks](https://github.com/babakks) in cli/cli#10980 - Add Digest to ReleaseAsset struct by [@​bdehamer](https://github.com/bdehamer) in cli/cli#11030 #####Dependencies - Bump `go-gh` to v2.12.1 by [@​BagToad](https://github.com/BagToad) in cli/cli#11043 - chore(deps): bump github.com/gabriel-vasile/mimetype from 1.4.8 to 1.4.9 by [@​dependabot](https://github.com/dependabot) in cli/cli#10825 - Update sigstore-go dependency to v1.0.0 by [@​malancas](https://github.com/malancas) in cli/cli#11028 - chore(deps): bump github.com/sigstore/protobuf-specs from 0.4.1 to 0.4.2 by [@​dependabot](https://github.com/dependabot) in cli/cli#10999 - chore(deps): bump github.com/yuin/goldmark from 1.7.8 to 1.7.12 by [@​dependabot](https://github.com/dependabot) in cli/cli#11032 #### New Contributors - [@​irhdab](https://github.com/irhdab) made their first contribution in cli/cli#11022 - [@​phanen](https://github.com/phanen) made their first contribution in cli/cli#10627 **Full Changelog**: cli/cli@v2.73.0...v2.74.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC41MC4wIiwidXBkYXRlZEluVmVyIjoiNDAuNTAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->

Fixes #4535.
AC: #4535 (comment)