forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresentation.go
More file actions
54 lines (44 loc) · 1.59 KB
/
presentation.go
File metadata and controls
54 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.Name, 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")
}