gunk-dev/the-valley

checks_display.go

source28abc5737165main's published tip history
1.2 KiB
1package cmd
2
3import (
4 "fmt"
5 "strings"
6
7 "the-valley/flow/internal/integration"
8 "the-valley/flow/internal/run"
9 "the-valley/flow/internal/valley"
10)
11
12// maxFailedChecksW bounds the failed check names a dashboard row shows
13// after its CI label.
14const maxFailedChecksW = 40
15
16// checksCI is what a valley change's checks read in the CI column, as a
17// PR's CI does: passing, failing or pending; "" when the valley lists none.
18func checksCI(c *valley.Checks) string {
19 if c == nil {
20 return ""
21 }
22 switch c.State {
23 case valley.ChecksPassed:
24 return "passing"
25 case valley.ChecksFailed:
26 return "failing"
27 case valley.ChecksPending:
28 return "pending"
29 }
30 return ""
31}
32
33// failingChecks names, once per change of states, the changes whose active
34// version's checks failed, and the checks that did.
35func failingChecks(states []*run.State, changes map[integration.ChangeKey]integration.Result) []string {
36 var out []string
37 for _, k := range followedChanges(states) {
38 c := changes[k].Change
39 if c == nil || checksCI(c.Checks) != "failing" {
40 continue
41 }
42 name := c.Handle
43 if name == "" {
44 name = c.ChangeID
45 }
46 out = append(out, fmt.Sprintf("%s %s v%d: %s", k.Repo, name, c.Version, strings.Join(c.Checks.FailedNames(), ", ")))
47 }
48 return out
49}