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

Function watchRun

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

Source from the content-addressed store, hash-verified

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