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

Function watchRun

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

Source from the content-addressed store, hash-verified

106}
107
108func watchRun(opts *WatchOptions) error {
109 c, err := opts.HttpClient()
110 if err != nil {
111 return fmt.Errorf("failed to create http client: %w", err)
112 }
113 client := api.NewClientFromHTTP(c)
114
115 repo, err := opts.BaseRepo()
116 if err != nil {
117 return fmt.Errorf("failed to determine base repo: %w", err)
118 }
119
120 cs := opts.IO.ColorScheme()
121
122 runID := opts.RunID
123 var run *shared.Run
124
125 if opts.Prompt {
126 runs, err := shared.GetRunsWithFilter(client, repo, nil, 10, func(run shared.Run) bool {
127 return run.Status != shared.Completed
128 })
129 if err != nil {
130 return fmt.Errorf("failed to get runs: %w", err)
131 }
132 if len(runs) == 0 {
133 return fmt.Errorf("found no in progress runs to watch")
134 }
135 if runID, err = shared.SelectRun(opts.Prompter, cs, runs); err != nil {
136 return err
137 }
138 // TODO silly stopgap until dust settles and SelectRun can just return a run
139 for _, r := range runs {
140 if fmt.Sprintf("%d", r.ID) == runID {
141 run = &r
142 break
143 }
144 }
145 } else {
146 run, err = shared.GetRun(client, repo, runID, 0)
147 if err != nil {
148 return fmt.Errorf("failed to get run: %w", err)
149 }
150 }
151
152 if run.Status == shared.Completed {
153 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)
154 if opts.ExitStatus && run.Conclusion != shared.Success {
155 return cmdutil.SilentError
156 }
157 return nil
158 }
159
160 prNumber := ""
161 number, err := shared.PullRequestForRun(client, repo, *run)
162 if err == nil {
163 prNumber = fmt.Sprintf(" %s#%d", ghrepo.FullName(repo), number)
164 // Agents tend to watch runs when asked to wait for the checks of a pull request to finish. The hint is printed
165 // before watching starts, so it is not lost when a long watch is stopped.

Callers 3

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
GenerateRepoURLFunction · 0.92
SymbolFunction · 0.92
renderRunFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80

Tested by 2

TestWatchRunFunction · 0.68