cli/pkg/cmd/run/shared/presentation.go
Isaac Shalom f1be4dc51c
Fix looking up workflow name for workflow runs (#6266)
The API field `WorkflowRun.name` is not guaranteed to correspond to the workflow name anymore. This introduces additional API lookups that resolve Workflows by their ID and look up their name in a future-proof fashion.

It also adds two new JSON fields for export: `displayTitle` and `workflowName`.

Co-authored-by: Christina Guo <61271066+guo-chris@users.noreply.github.com>
Co-authored-by: Mislav Marohnić <mislav@github.com>
2022-09-21 20:41:19 +02:00

54 lines
1.6 KiB
Go

package shared
import (
"fmt"
"strings"
"github.com/cli/cli/v2/pkg/iostreams"
)
func RenderRunHeader(cs *iostreams.ColorScheme, run Run, ago, prNumber string) string {
title := fmt.Sprintf("%s %s%s",
cs.Bold(run.HeadBranch), run.WorkflowName(), prNumber)
symbol, symbolColor := Symbol(cs, run.Status, run.Conclusion)
id := cs.Cyanf("%d", run.ID)
header := ""
header += fmt.Sprintf("%s %s · %s\n", symbolColor(symbol), title, id)
header += fmt.Sprintf("Triggered via %s %s", run.Event, ago)
return header
}
func RenderJobs(cs *iostreams.ColorScheme, jobs []Job, verbose bool) string {
lines := []string{}
for _, job := range jobs {
elapsed := job.CompletedAt.Sub(job.StartedAt)
elapsedStr := fmt.Sprintf(" in %s", elapsed)
if elapsed < 0 {
elapsedStr = ""
}
symbol, symbolColor := Symbol(cs, job.Status, job.Conclusion)
id := cs.Cyanf("%d", job.ID)
lines = append(lines, fmt.Sprintf("%s %s%s (ID %s)", symbolColor(symbol), cs.Bold(job.Name), elapsedStr, id))
if verbose || IsFailureState(job.Conclusion) {
for _, step := range job.Steps {
stepSymbol, stepSymColor := Symbol(cs, step.Status, step.Conclusion)
lines = append(lines, fmt.Sprintf(" %s %s", stepSymColor(stepSymbol), step.Name))
}
}
}
return strings.Join(lines, "\n")
}
func RenderAnnotations(cs *iostreams.ColorScheme, annotations []Annotation) string {
lines := []string{}
for _, a := range annotations {
lines = append(lines, fmt.Sprintf("%s %s", AnnotationSymbol(cs, a), a.Message))
lines = append(lines, cs.Grayf("%s: %s#%d\n", a.JobName, a.Path, a.StartLine))
}
return strings.Join(lines, "\n")
}