github.com/andrewhsu/cli/v2@v2.0.1-0.20210910131313-d4b4061f5b89/pkg/cmd/run/shared/presentation.go (about)

     1  package shared
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/andrewhsu/cli/v2/pkg/iostreams"
     8  )
     9  
    10  func RenderRunHeader(cs *iostreams.ColorScheme, run Run, ago, prNumber string) string {
    11  	title := fmt.Sprintf("%s %s%s",
    12  		cs.Bold(run.HeadBranch), run.Name, prNumber)
    13  	symbol, symbolColor := Symbol(cs, run.Status, run.Conclusion)
    14  	id := cs.Cyanf("%d", run.ID)
    15  
    16  	header := ""
    17  	header += fmt.Sprintf("%s %s ยท %s\n", symbolColor(symbol), title, id)
    18  	header += fmt.Sprintf("Triggered via %s %s", run.Event, ago)
    19  
    20  	return header
    21  }
    22  
    23  func RenderJobs(cs *iostreams.ColorScheme, jobs []Job, verbose bool) string {
    24  	lines := []string{}
    25  	for _, job := range jobs {
    26  		elapsed := job.CompletedAt.Sub(job.StartedAt)
    27  		elapsedStr := fmt.Sprintf(" in %s", elapsed)
    28  		if elapsed < 0 {
    29  			elapsedStr = ""
    30  		}
    31  		symbol, symbolColor := Symbol(cs, job.Status, job.Conclusion)
    32  		id := cs.Cyanf("%d", job.ID)
    33  		lines = append(lines, fmt.Sprintf("%s %s%s (ID %s)", symbolColor(symbol), cs.Bold(job.Name), elapsedStr, id))
    34  		if verbose || IsFailureState(job.Conclusion) {
    35  			for _, step := range job.Steps {
    36  				stepSymbol, stepSymColor := Symbol(cs, step.Status, step.Conclusion)
    37  				lines = append(lines, fmt.Sprintf("  %s %s", stepSymColor(stepSymbol), step.Name))
    38  			}
    39  		}
    40  	}
    41  
    42  	return strings.Join(lines, "\n")
    43  }
    44  
    45  func RenderAnnotations(cs *iostreams.ColorScheme, annotations []Annotation) string {
    46  	lines := []string{}
    47  
    48  	for _, a := range annotations {
    49  		lines = append(lines, fmt.Sprintf("%s %s", AnnotationSymbol(cs, a), a.Message))
    50  		lines = append(lines, cs.Grayf("%s: %s#%d\n", a.JobName, a.Path, a.StartLine))
    51  	}
    52  
    53  	return strings.Join(lines, "\n")
    54  }