Skip to content

Commit 65524f1

Browse files
committed
review feedback
1 parent c8e481e commit 65524f1

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

pkg/cmd/run/watch/watch.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewCmdWatch(f *cmdutil.Factory, runF func(*WatchOptions) error) *cobra.Comm
4141

4242
cmd := &cobra.Command{
4343
Use: "watch <run-selector>",
44-
Short: "Runs until a run completes, showing its progress",
44+
Short: "Watch a run until it completes, showing its progress",
4545
Annotations: map[string]string{
4646
"IsActions": "true",
4747
},
@@ -82,11 +82,13 @@ func watchRun(opts *WatchOptions) error {
8282
return fmt.Errorf("failed to determine base repo: %w", err)
8383
}
8484

85+
out := opts.IO.Out
86+
cs := opts.IO.ColorScheme()
87+
8588
runID := opts.RunID
8689
var run *shared.Run
8790

8891
if opts.Prompt {
89-
cs := opts.IO.ColorScheme()
9092
runs, err := shared.GetRunsWithFilter(client, repo, 10, func(run shared.Run) bool {
9193
return run.Status != shared.Completed
9294
})
@@ -115,6 +117,7 @@ func watchRun(opts *WatchOptions) error {
115117
}
116118

117119
if run.Status == shared.Completed {
120+
fmt.Fprintf(out, "Run %s (%s) has already completed with '%s'\n", cs.Bold(run.Name), cs.Cyanf("%d", run.ID), run.Conclusion)
118121
return nil
119122
}
120123

@@ -124,11 +127,9 @@ func watchRun(opts *WatchOptions) error {
124127
prNumber = fmt.Sprintf(" #%d", number)
125128
}
126129

127-
if runtime.GOOS == "windows" {
128-
opts.IO.EnableVirtualTerminalProcessing()
129-
}
130+
opts.IO.EnableVirtualTerminalProcessing()
130131
// clear entire screen
131-
fmt.Fprintf(opts.IO.Out, "\x1b[2J")
132+
fmt.Fprintf(out, "\x1b[2J")
132133

133134
annotationCache := map[int][]shared.Annotation{}
134135

@@ -145,6 +146,14 @@ func watchRun(opts *WatchOptions) error {
145146
time.Sleep(duration)
146147
}
147148

149+
symbol, symbolColor := shared.Symbol(cs, run.Status, run.Conclusion)
150+
id := cs.Cyanf("%d", run.ID)
151+
152+
if opts.IO.IsStdoutTTY() {
153+
fmt.Fprintln(out)
154+
fmt.Fprintf(out, "%s Run %s (%s) completed with '%s'\n", symbolColor(symbol), cs.Bold(run.Name), id, run.Conclusion)
155+
}
156+
148157
if opts.ExitStatus && run.Conclusion != shared.Success {
149158
return cmdutil.SilentError
150159
}
@@ -160,14 +169,14 @@ func renderRun(opts WatchOptions, client *api.Client, repo ghrepo.Interface, run
160169

161170
run, err = shared.GetRun(client, repo, fmt.Sprintf("%d", run.ID))
162171
if err != nil {
163-
return run, fmt.Errorf("failed to get run: %w", err)
172+
return nil, fmt.Errorf("failed to get run: %w", err)
164173
}
165174

166175
ago := opts.Now().Sub(run.CreatedAt)
167176

168177
jobs, err := shared.GetJobs(client, repo, *run)
169178
if err != nil {
170-
return run, fmt.Errorf("failed to get jobs: %w", err)
179+
return nil, fmt.Errorf("failed to get jobs: %w", err)
171180
}
172181

173182
var annotations []shared.Annotation
@@ -192,7 +201,7 @@ func renderRun(opts WatchOptions, client *api.Client, repo ghrepo.Interface, run
192201
}
193202

194203
if annotationErr != nil {
195-
return run, fmt.Errorf("failed to get annotations: %w", annotationErr)
204+
return nil, fmt.Errorf("failed to get annotations: %w", annotationErr)
196205
}
197206

198207
if runtime.GOOS == "windows" {
@@ -210,7 +219,7 @@ func renderRun(opts WatchOptions, client *api.Client, repo ghrepo.Interface, run
210219
fmt.Fprintln(out, shared.RenderRunHeader(cs, *run, utils.FuzzyAgo(ago), prNumber))
211220
fmt.Fprintln(out)
212221

213-
if len(jobs) == 0 && run.Conclusion == shared.Failure {
222+
if len(jobs) == 0 {
214223
return run, nil
215224
}
216225

pkg/cmd/run/watch/watch_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func TestWatchRun(t *testing.T) {
178178
onlyWindows bool
179179
skipWindows bool
180180
}{
181-
// TODO exit status respected
182181
{
183182
name: "run ID provided run already completed",
184183
opts: &WatchOptions{
@@ -189,10 +188,11 @@ func TestWatchRun(t *testing.T) {
189188
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
190189
httpmock.JSONResponse(shared.FailedRun))
191190
},
192-
wantOut: "",
191+
wantOut: "Run failed (1234) has already completed with 'failure'\n",
193192
},
194193
{
195194
name: "prompt, no in progress runs",
195+
tty: true,
196196
opts: &WatchOptions{
197197
Prompt: true,
198198
},
@@ -212,6 +212,7 @@ func TestWatchRun(t *testing.T) {
212212
{
213213
name: "interval respected",
214214
skipWindows: true,
215+
tty: true,
215216
opts: &WatchOptions{
216217
Interval: 0,
217218
Prompt: true,
@@ -220,7 +221,7 @@ func TestWatchRun(t *testing.T) {
220221
askStubs: func(as *prompt.AskStubber) {
221222
as.StubOne(1)
222223
},
223-
wantOut: "\x1b[2J\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n- trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n✓ trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n",
224+
wantOut: "\x1b[2J\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n- trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n✓ trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n\n✓ Run more runs (2) completed with 'success'\n",
224225
},
225226
{
226227
name: "interval respected, windows",
@@ -237,6 +238,7 @@ func TestWatchRun(t *testing.T) {
237238
},
238239
{
239240
name: "exit status respected",
241+
tty: true,
240242
skipWindows: true,
241243
opts: &WatchOptions{
242244
Interval: 0,
@@ -247,7 +249,7 @@ func TestWatchRun(t *testing.T) {
247249
askStubs: func(as *prompt.AskStubber) {
248250
as.StubOne(1)
249251
},
250-
wantOut: "\x1b[2J\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n- trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n\n\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\nX trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n",
252+
wantOut: "\x1b[2J\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n- trunk more runs · 2\nTriggered via push about 59 minutes ago\n\n\x1b[0;0H\x1b[JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\nX trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n\nX Run more runs (2) completed with 'failure'\n",
251253
wantErr: true,
252254
errMsg: "SilentError",
253255
},
@@ -263,7 +265,7 @@ func TestWatchRun(t *testing.T) {
263265
askStubs: func(as *prompt.AskStubber) {
264266
as.StubOne(1)
265267
},
266-
wantOut: "\x1b[2J\x1b[2JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n- trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n\n\x1b[2JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\nX trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n",
268+
wantOut: "\x1b[2J\x1b[2JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\n- trunk more runs · 2\nTriggered via push about 59 minutes ago\n\n\x1b[2JRefreshing run status every 0 seconds. Press Ctrl+C to quit.\n\nX trunk more runs · 2\nTriggered via push about 59 minutes ago\n\nJOBS\nX sad job in 4m34s (ID 20)\n ✓ barf the quux\n X quux the barf\n\nANNOTATIONS\nX the job is sad\nsad job: blaze.py#420\n\n",
267269
wantErr: true,
268270
errMsg: "SilentError",
269271
},

0 commit comments

Comments
 (0)