* [gh run watch] Support `--compact` flag * [gh run watch] Support `--compact` flag * Add changes for updated AC * Incorporate review changes * docs(run watch): fill up the line to 80 chars Signed-off-by: Babak K. Shandiz <babakks@github.com> --------- Signed-off-by: Babak K. Shandiz <babakks@github.com> Co-authored-by: Babak K. Shandiz <babakks@github.com>
102 lines
2.9 KiB
Go
102 lines
2.9 KiB
Go
package shared
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/cli/cli/v2/pkg/iostreams"
|
|
)
|
|
|
|
func RenderRunHeader(cs *iostreams.ColorScheme, run Run, ago, prNumber string, attempt uint64) 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)
|
|
|
|
attemptLabel := ""
|
|
if attempt > 0 {
|
|
attemptLabel = fmt.Sprintf(" (Attempt #%d)", attempt)
|
|
}
|
|
|
|
header := ""
|
|
header += fmt.Sprintf("%s %s ยท %s%s\n", symbolColor(symbol), title, id, attemptLabel)
|
|
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 RenderJobsCompact(cs *iostreams.ColorScheme, jobs []Job) 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 job.Status == Completed && job.Conclusion == Success {
|
|
continue
|
|
}
|
|
|
|
var inProgressStepLine string
|
|
var failedStepLines []string
|
|
|
|
for _, step := range job.Steps {
|
|
stepSymbol, stepSymColor := Symbol(cs, step.Status, step.Conclusion)
|
|
stepLine := fmt.Sprintf(" %s %s", stepSymColor(stepSymbol), step.Name)
|
|
|
|
if IsFailureState(step.Conclusion) {
|
|
failedStepLines = append(failedStepLines, stepLine)
|
|
}
|
|
|
|
if step.Status == InProgress {
|
|
inProgressStepLine = stepLine
|
|
}
|
|
}
|
|
|
|
lines = append(lines, failedStepLines...)
|
|
|
|
if inProgressStepLine != "" {
|
|
lines = append(lines, inProgressStepLine)
|
|
}
|
|
}
|
|
|
|
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))
|
|
// Following newline is essential for spacing between annotations
|
|
lines = append(lines, cs.Mutedf("%s: %s#%d\n", a.JobName, a.Path, a.StartLine))
|
|
}
|
|
|
|
return strings.Join(lines, "\n")
|
|
}
|