forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
present.go
67 lines (54 loc) · 1.29 KB
/
present.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
package getbuilds
import (
"time"
"github.com/concourse/atc"
"github.com/concourse/atc/web"
)
const layout = "2006-01-02 15:04:05 (MST)"
type PresentedBuild struct {
ID int
JobName string
PipelineName string
TeamName string
Status string
BuildName string
StartTime string
EndTime string
CSSClass string
Path string
}
func formatTime(uts int64) string {
if uts == 0 {
return "n/a"
}
convertedTime := time.Unix(uts, 0).UTC()
return convertedTime.Format(layout)
}
func PresentBuilds(builds []atc.Build) []PresentedBuild {
presentedBuilds := []PresentedBuild{}
for _, build := range builds {
var cssClass string
var jobName string
var pipelineName string
if build.JobName == "" {
jobName = "[one off]"
pipelineName = "[one off]"
cssClass = "build-one-off"
} else {
jobName = build.JobName
pipelineName = build.PipelineName
}
presentedBuilds = append(presentedBuilds, PresentedBuild{
ID: build.ID,
JobName: jobName,
PipelineName: pipelineName,
TeamName: build.TeamName,
StartTime: formatTime(build.StartTime),
EndTime: formatTime(build.EndTime),
CSSClass: cssClass,
Status: string(build.Status),
Path: web.PathForBuild(build),
})
}
return presentedBuilds
}