MCPcopy
hub / github.com/cli/cli / watchRun

Function watchRun

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

Source from the content-addressed store, hash-verified

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

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