-
Notifications
You must be signed in to change notification settings - Fork 298
/
buildstatus.go
100 lines (88 loc) · 2.3 KB
/
buildstatus.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package hud
import (
"time"
"github.com/gdamore/tcell"
"github.com/tilt-dev/tilt/internal/hud/view"
"github.com/tilt-dev/tilt/internal/rty"
"github.com/tilt-dev/tilt/pkg/model"
)
type buildStatus struct {
edits []string
duration time.Duration
status string
deployTime time.Time
reason model.BuildReason
muted bool
}
func (bs buildStatus) defaultTextColor() tcell.Color {
if bs.muted {
return cLightText
}
return tcell.ColorDefault
}
func makeBuildStatus(res view.Resource, triggerMode model.TriggerMode) buildStatus {
status := "Pending"
duration := time.Duration(0)
edits := []string{}
deployTime := time.Time{}
reason := model.BuildReason(0)
if res.IsTiltfile {
return buildStatus{
status: "N/A",
}
}
if !res.CurrentBuild.Empty() && !res.CurrentBuild.Reason.IsCrashOnly() {
status = "In prog."
duration = time.Since(res.CurrentBuild.StartTime)
edits = res.CurrentBuild.Edits
reason = res.CurrentBuild.Reason
} else if !res.PendingBuildSince.IsZero() && !res.PendingBuildReason.IsCrashOnly() {
status = "Pending"
if triggerMode.AutoOnChange() {
duration = time.Since(res.PendingBuildSince)
}
edits = res.PendingBuildEdits
reason = res.PendingBuildReason
} else if !res.LastBuild().FinishTime.IsZero() {
lastBuild := res.LastBuild()
if lastBuild.Error != nil {
status = "Error"
} else {
status = "OK"
}
duration = lastBuild.Duration()
edits = lastBuild.Edits
deployTime = res.LastDeployTime
reason = lastBuild.Reason
}
return buildStatus{
status: status,
duration: duration,
edits: edits,
deployTime: deployTime,
reason: reason,
}
}
func buildStatusCell(bs buildStatus) rty.Component {
textColor := bs.defaultTextColor()
showingDuration := bs.duration != 0
lhsWidth := BuildStatusCellMinWidth
if !showingDuration {
lhsWidth += BuildDurCellMinWidth
}
lhs := rty.NewMinLengthLayout(lhsWidth, rty.DirHor).
Add(rty.ColoredString(bs.status, textColor))
if !showingDuration {
return lhs
}
sb := rty.NewStringBuilder()
sb.Fg(cLightText).Text(" (")
sb.Fg(textColor).Text(formatBuildDuration(bs.duration))
sb.Fg(cLightText).Text(")")
rhs := rty.NewMinLengthLayout(BuildDurCellMinWidth, rty.DirHor).
SetAlign(rty.AlignEnd).
Add(sb.Build())
return rty.NewConcatLayout(rty.DirHor).
Add(lhs).
Add(rhs)
}