(opts *ViewOptions, client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow, ref string)
| 157 | } |
| 158 | |
| 159 | func 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 | |
| 205 | func viewWorkflowInfo(opts *ViewOptions, client *api.Client, repo ghrepo.Interface, workflow *shared.Workflow) error { |
| 206 | wr, err := runShared.GetRuns(client, repo, &runShared.FilterOptions{ |
no test coverage detected