Skip to content

Conversation

@iamazeem
Copy link
Contributor

@iamazeem iamazeem commented Mar 18, 2025

Fixes #4535.
AC: #4535 (comment)

@iamazeem iamazeem requested a review from a team as a code owner March 18, 2025 11:44
@iamazeem iamazeem requested a review from BagToad March 18, 2025 11:44
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Mar 18, 2025
@BagToad BagToad force-pushed the 4535-gh-run-watch-compact-flag branch from 22e092a to 37690a7 Compare April 14, 2025 17:17
@babakks babakks self-requested a review May 19, 2025 09:31
Copy link
Member

@babakks babakks left a 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.

Comment on lines 41 to 58
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))
}
Copy link
Member

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.

@iamazeem iamazeem requested a review from babakks May 22, 2025 09:47
@iamazeem
Copy link
Contributor Author

@babakks: Changes added according to the updated AC. Please review. Thanks!

Copy link
Member

@babakks babakks left a 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!

run-watch-compact

However, it still needs a couple of small improvements, and also one test case in TestWatchRun to ensure the behaviour is as expected.

return strings.Join(lines, "\n")
}

func RenderJobsInCompactMode(cs *iostreams.ColorScheme, jobs []Job) string {
Copy link
Member

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

Comment on lines 84 to 86
if job.Status == InProgress {
lines = append(lines, inProgressStepLine)
}
Copy link
Member

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:

Suggested change
if job.Status == InProgress {
lines = append(lines, inProgressStepLine)
}
if inProgressStepLine != "" {
lines = append(lines, inProgressStepLine)
}

Comment on lines 52 to 57
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.
Copy link
Member

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.

Suggested change
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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +69 to +70
# Watch a run in compact mode
$ gh run watch --compact
Copy link
Member

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.

},
}
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")
Copy link
Member

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:

Suggested change
cmd.Flags().BoolVar(&opts.Compact, "compact", false, "Enable compact mode")
cmd.Flags().BoolVar(&opts.Compact, "compact", false, "Show only relevant/failed steps")

Comment on lines 270 to 271
verbose := true
fmt.Fprintln(out, shared.RenderJobs(cs, jobs, verbose))
Copy link
Member

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.

Suggested change
verbose := true
fmt.Fprintln(out, shared.RenderJobs(cs, jobs, verbose))
fmt.Fprintln(out, shared.RenderJobs(cs, jobs, true))

Comment on lines +60 to +68
{
name: "compact status",
cli: "1234 --compact",
wants: WatchOptions{
Interval: defaultInterval,
RunID: "1234",
Compact: true,
},
},
Copy link
Member

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. 🙏

Copy link
Contributor Author

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!

@iamazeem iamazeem requested a review from babakks May 23, 2025 05:23
Copy link
Member

@babakks babakks left a 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.

@babakks
Copy link
Member

babakks commented May 23, 2025

Since this might take a while and I'm going to add a couple of tests for the functions in presentation.go (and it'll need review from other folks), I'm merging this PR now. This PR is fine since it confirms with the A/C, and also the existing render function does not have proper tests, so this PR is not inconsistent with our current state.

UPDATE: Just pushed a quick docs improvement to this.

@babakks babakks merged commit 1e6a2b1 into cli:trunk May 23, 2025
9 checks passed
@iamazeem iamazeem deleted the 4535-gh-run-watch-compact-flag branch May 23, 2025 10:03
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jun 13, 2025
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 [@&#8203;timrogers](https://github.com/timrogers) in cli/cli#11056
-   Fix pr edit when URL is provided by [@&#8203;williammartin](https://github.com/williammartin) in cli/cli#11057
-   Fix const in MR finder tests by [@&#8203;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 [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#10745
-   \[gh run watch] Support `--compact` flag by [@&#8203;iamazeem](https://github.com/iamazeem) in cli/cli#10629
-   Fix brew update notifications by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11024

##### 🐛 Fixes

-   Revert "\[gh config] Escape pipe symbol in Long desc for website manual" by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11004
-   Fix formatting in allowed values for `gh config --help` by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#11003
-   fix: `gh gist edit` panic when no file in a gist by [@&#8203;phanen](https://github.com/phanen) in cli/cli#10627
-   Add retry logic when fetching TUF content in `gh attestation` commands by [@&#8203;malancas](https://github.com/malancas) in cli/cli#10943

##### 📚 Docs & Chores

-   Update README.md by [@&#8203;irhdab](https://github.com/irhdab) in cli/cli#11022
-   Add tests for `RenderJobs` and `RenderJobsCompact` by [@&#8203;babakks](https://github.com/babakks) in cli/cli#11013
-   Add example usage of `--head` option to `pr list` docs by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10979
-   Mention `pr create` will print the created MR's URL by [@&#8203;babakks](https://github.com/babakks) in cli/cli#10980
-   Add Digest to ReleaseAsset struct by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#11030

##### :dependabot: Dependencies

-   Bump `go-gh` to v2.12.1 by [@&#8203;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 [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#10825
-   Update sigstore-go dependency to v1.0.0 by [@&#8203;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 [@&#8203;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 [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#11032

#### New Contributors

-   [@&#8203;irhdab](https://github.com/irhdab) made their first contribution in cli/cli#11022
-   [@&#8203;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-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: add a --compact flag to gh run watch

4 participants