MCPcopy
hub / github.com/cli/cli / viewWorkflowContent

Function viewWorkflowContent

pkg/cmd/workflow/view/view.go:159–203  ·  view source on GitHub ↗
(opts *ViewOptions, client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow, ref string)

Source from the content-addressed store, hash-verified

157}
158
159func viewWorkflowContent(opts *ViewOptions, client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow, ref string) error {
160 yamlBytes, err := shared.GetWorkflowContent(client, repo, *workflow, ref)
161 if err != nil {
162 if s, ok := err.(api.HTTPError); ok && s.StatusCode == 404 {
163 if ref != "" {
164 return fmt.Errorf("could not find workflow file %s on %s, try specifying a different ref", workflow.Base(), ref)
165 }
166 return fmt.Errorf("could not find workflow file %s, try specifying a branch or tag using `--ref`", workflow.Base())
167 }
168 return fmt.Errorf("could not get workflow file content: %w", err)
169 }
170
171 yaml := string(yamlBytes)
172
173 if !opts.Raw {
174 cs := opts.IO.ColorScheme()
175 out := opts.IO.Out
176
177 fileName := workflow.Base()
178 fmt.Fprintf(out, "%s - %s\n", cs.Bold(workflow.Name), cs.Muted(fileName))
179 fmt.Fprintf(out, "ID: %s", cs.Cyanf("%d", workflow.ID))
180
181 codeBlock := fmt.Sprintf("```yaml\n%s\n```", yaml)
182 rendered, err := markdown.Render(codeBlock,
183 markdown.WithTheme(opts.IO.TerminalTheme()),
184 markdown.WithoutIndentation(),
185 markdown.WithWrap(0))
186 if err != nil {
187 return err
188 }
189 _, err = fmt.Fprint(opts.IO.Out, rendered)
190 return err
191 }
192
193 if _, err := fmt.Fprint(opts.IO.Out, yaml); err != nil {
194 return err
195 }
196
197 if !strings.HasSuffix(yaml, "\n") {
198 _, err := fmt.Fprint(opts.IO.Out, "\n")
199 return err
200 }
201
202 return nil
203}
204
205func viewWorkflowInfo(opts *ViewOptions, client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow) error {
206 wr, err := runShared.GetRuns(client, repo, &runShared.FilterOptions{

Callers 1

runViewFunction · 0.85

Calls 12

GetWorkflowContentFunction · 0.92
RenderFunction · 0.92
WithThemeFunction · 0.92
WithoutIndentationFunction · 0.92
WithWrapFunction · 0.92
BaseMethod · 0.80
ColorSchemeMethod · 0.80
BoldMethod · 0.80
MutedMethod · 0.80
CyanfMethod · 0.80
TerminalThemeMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected