X Tutup
Skip to content

Commit d204ae7

Browse files
committed
spinner tracks io itself
1 parent 0ee23dc commit d204ae7

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

pkg/cmd/run/list/list.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ type ListOptions struct {
2222
HttpClient func() (*http.Client, error)
2323
BaseRepo func() (ghrepo.Interface, error)
2424

25-
ShowProgress bool
26-
PlainOutput bool
25+
PlainOutput bool
2726

2827
Limit int
2928
}
@@ -44,7 +43,6 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
4443
opts.BaseRepo = f.BaseRepo
4544

4645
terminal := opts.IO.IsStdoutTTY() && opts.IO.IsStdinTTY()
47-
opts.ShowProgress = terminal
4846
opts.PlainOutput = !terminal
4947

5048
if opts.Limit < 1 {
@@ -65,9 +63,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
6563
}
6664

6765
func listRun(opts *ListOptions) error {
68-
if opts.ShowProgress {
69-
opts.IO.StartProgressIndicator()
70-
}
66+
opts.IO.StartProgressIndicator()
7167
baseRepo, err := opts.BaseRepo()
7268
if err != nil {
7369
return fmt.Errorf("failed to determine base repo: %w", err)
@@ -89,9 +85,7 @@ func listRun(opts *ListOptions) error {
8985
cs := opts.IO.ColorScheme()
9086
out := opts.IO.Out
9187

92-
if opts.ShowProgress {
93-
opts.IO.StopProgressIndicator()
94-
}
88+
opts.IO.StopProgressIndicator()
9589

9690
if len(runs) == 0 {
9791
if !opts.PlainOutput {

pkg/cmd/run/shared/shared.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (a Annotation) Symbol(cs *iostreams.ColorScheme) string {
9797
case "failure":
9898
return cs.FailureIcon()
9999
case "warning":
100-
return cs.Yellow("!")
100+
return cs.WarningIcon()
101101
default:
102102
return "TODO"
103103
}

pkg/cmd/run/view/view.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type ViewOptions struct {
2525
Verbose bool
2626
ExitStatus bool
2727

28-
Prompt bool
29-
ShowProgress bool
28+
Prompt bool
3029

3130
Now func() time.Time
3231
}
@@ -57,12 +56,11 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
5756
opts.BaseRepo = f.BaseRepo
5857

5958
terminal := opts.IO.IsStdoutTTY() && opts.IO.IsStdinTTY()
60-
opts.ShowProgress = terminal
6159

6260
if len(args) > 0 {
6361
opts.RunID = args[0]
6462
} else if !terminal {
65-
return &cmdutil.FlagError{Err: errors.New("expected a run ID")}
63+
return &cmdutil.FlagError{Err: errors.New("run ID required when not running interactively")}
6664
} else {
6765
opts.Prompt = true
6866
}
@@ -102,9 +100,7 @@ func runView(opts *ViewOptions) error {
102100
}
103101
}
104102

105-
if opts.ShowProgress {
106-
opts.IO.StartProgressIndicator()
107-
}
103+
opts.IO.StartProgressIndicator()
108104

109105
run, err := shared.GetRun(client, repo, runID)
110106
if err != nil {
@@ -138,9 +134,7 @@ func runView(opts *ViewOptions) error {
138134
return fmt.Errorf("failed to get annotations: %w", annotationErr)
139135
}
140136

141-
if opts.ShowProgress {
142-
opts.IO.StopProgressIndicator()
143-
}
137+
opts.IO.StopProgressIndicator()
144138

145139
out := opts.IO.Out
146140
cs := opts.IO.ColorScheme()
@@ -166,7 +160,7 @@ func runView(opts *ViewOptions) error {
166160
fmt.Fprintln(out)
167161
fmt.Fprintf(out, "For more information, see: %s\n", cs.Bold(run.URL))
168162

169-
if opts.ExitStatus && shared.IsFailureState(run.Conclusion) {
163+
if opts.ExitStatus {
170164
return cmdutil.SilentError
171165
}
172166
return nil

pkg/cmd/run/view/view_test.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ func TestNewCmdView(t *testing.T) {
3333
name: "blank tty",
3434
tty: true,
3535
wants: ViewOptions{
36-
Prompt: true,
37-
ShowProgress: true,
36+
Prompt: true,
3837
},
3938
},
4039
{
@@ -50,9 +49,8 @@ func TestNewCmdView(t *testing.T) {
5049
cli: "-v",
5150
tty: true,
5251
wants: ViewOptions{
53-
Verbose: true,
54-
Prompt: true,
55-
ShowProgress: true,
52+
Verbose: true,
53+
Prompt: true,
5654
},
5755
},
5856
{
@@ -96,7 +94,6 @@ func TestNewCmdView(t *testing.T) {
9694
assert.NoError(t, err)
9795

9896
assert.Equal(t, tt.wants.RunID, gotOpts.RunID)
99-
assert.Equal(t, tt.wants.ShowProgress, gotOpts.ShowProgress)
10097
assert.Equal(t, tt.wants.Prompt, gotOpts.Prompt)
10198
assert.Equal(t, tt.wants.ExitStatus, gotOpts.ExitStatus)
10299
assert.Equal(t, tt.wants.Verbose, gotOpts.Verbose)
@@ -119,9 +116,8 @@ func TestViewRun(t *testing.T) {
119116
name: "associate with PR",
120117
tty: true,
121118
opts: &ViewOptions{
122-
RunID: "3",
123-
Prompt: false,
124-
ShowProgress: true,
119+
RunID: "3",
120+
Prompt: false,
125121
},
126122
httpStubs: func(reg *httpmock.Registry) {
127123
reg.Register(
@@ -205,10 +201,9 @@ func TestViewRun(t *testing.T) {
205201
name: "verbose",
206202
tty: true,
207203
opts: &ViewOptions{
208-
RunID: "1234",
209-
Prompt: false,
210-
ShowProgress: true,
211-
Verbose: true,
204+
RunID: "1234",
205+
Prompt: false,
206+
Verbose: true,
212207
},
213208
httpStubs: func(reg *httpmock.Registry) {
214209
reg.Register(
@@ -264,8 +259,7 @@ func TestViewRun(t *testing.T) {
264259
as.StubOne(2)
265260
},
266261
opts: &ViewOptions{
267-
Prompt: true,
268-
ShowProgress: true,
262+
Prompt: true,
269263
},
270264
wantOut: "\n✓ trunk successful · 3\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job (ID 10)\n\nFor more information about a job, try: gh job view <job-id>\nview this run on GitHub: runs/3\n",
271265
},

0 commit comments

Comments
 (0)
X Tutup