MCPcopy Create free account
hub / github.com/cli/cli / watchRun

Function watchRun

pkg/cmd/run/watch/watch.go:95–213  ·  view source on GitHub ↗
(opts *WatchOptions)

Source from the content-addressed store, hash-verified

93}
94
95func watchRun(opts *WatchOptions) error {
96 c, err := opts.HttpClient()
97 if err != nil {
98 return fmt.Errorf("failed to create http client: %w", err)
99 }
100 client := api.NewClientFromHTTP(c)
101
102 repo, err := opts.BaseRepo()
103 if err != nil {
104 return fmt.Errorf("failed to determine base repo: %w", err)
105 }
106
107 cs := opts.IO.ColorScheme()
108
109 runID := opts.RunID
110 var run *shared.Run
111
112 if opts.Prompt {
113 runs, err := shared.GetRunsWithFilter(client, repo, nil, 10, func(run shared.Run) bool {
114 return run.Status != shared.Completed
115 })
116 if err != nil {
117 return fmt.Errorf("failed to get runs: %w", err)
118 }
119 if len(runs) == 0 {
120 return fmt.Errorf("found no in progress runs to watch")
121 }
122 if runID, err = shared.SelectRun(opts.Prompter, cs, runs); err != nil {
123 return err
124 }
125 // TODO silly stopgap until dust settles and SelectRun can just return a run
126 for _, r := range runs {
127 if fmt.Sprintf("%d", r.ID) == runID {
128 run = &r
129 break
130 }
131 }
132 } else {
133 run, err = shared.GetRun(client, repo, runID, 0)
134 if err != nil {
135 return fmt.Errorf("failed to get run: %w", err)
136 }
137 }
138
139 if run.Status == shared.Completed {
140 fmt.Fprintf(opts.IO.Out, "Run %s (%s) has already completed with '%s'\n", cs.Bold(run.WorkflowName()), cs.Cyanf("%d", run.ID), run.Conclusion)
141 if opts.ExitStatus && run.Conclusion != shared.Success {
142 return cmdutil.SilentError
143 }
144 return nil
145 }
146
147 prNumber := ""
148 number, err := shared.PullRequestForRun(client, repo, *run)
149 if err == nil {
150 prNumber = fmt.Sprintf(" %s#%d", ghrepo.FullName(repo), number)
151 }
152

Callers 2

TestWatchRunFunction · 0.85
NewCmdWatchFunction · 0.85

Calls 15

WorkflowNameMethod · 0.95
NewClientFromHTTPFunction · 0.92
GetRunsWithFilterFunction · 0.92
SelectRunFunction · 0.92
GetRunFunction · 0.92
PullRequestForRunFunction · 0.92
FullNameFunction · 0.92
SymbolFunction · 0.92
renderRunFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80
CyanfMethod · 0.80

Tested by 1

TestWatchRunFunction · 0.68