-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
99 lines (80 loc) · 2.06 KB
/
printer.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
package main
import (
"fmt"
"os"
"strings"
"time"
"github.com/jedib0t/go-pretty/table"
)
// Print a table of latest 10 deployments
func printDeployments(deployments []Deployment) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{
"#",
"CompletedOn",
"Environment",
"Status",
"Changes",
})
i := 0
for _, element := range deployments {
buildId := element.Release.Artifacts[0].DefinitionReference.Version.Id
changes := getBuildChangesById(buildId)
parsedTime, _ := time.Parse(AzureTimeLayout, element.CompletedOn)
t.AppendRow([]interface{}{
element.Id,
parsedTime.In(desiredLocationForDateTime).Format(DesiredTimeLayout),
element.ReleaseEnvironment.Name,
element.DeploymentStatus,
changes[0].Message,
})
i = i + 1
if i > 10 {
break
}
}
t.Render()
}
// Print a table of latest 10 builds
func printBuilds(builds []Build) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "Started", "Finished", "Branch", "Changes"})
i := 0
for _, element := range builds {
lastChangeMessage := ""
changes := getBuildChangesById(fmt.Sprintf("%d", element.Id))
if len(changes) > 0 {
lastChange := changes[0]
lastChangeMessage = lastChange.Message
}
branchName := element.SourceBranch
if strings.Contains(element.SourceBranch, "/") {
splittedBranchRefs := strings.Split(element.SourceBranch, "/")
branchName = splittedBranchRefs[len(splittedBranchRefs)-1]
}
startTime := ""
if element.StartTime != "" {
parsedStartTime, _ := time.Parse(AzureTimeLayout, element.StartTime)
startTime = parsedStartTime.In(desiredLocationForDateTime).Format(DesiredTimeLayout)
}
finishTime := ""
if element.FinishTime != "" {
parsedFinishTime, _ := time.Parse(AzureTimeLayout, element.FinishTime)
finishTime = parsedFinishTime.In(desiredLocationForDateTime).Format(DesiredTimeLayout)
}
t.AppendRow([]interface{}{
element.Id,
startTime,
finishTime,
branchName,
lastChangeMessage,
})
i = i + 1
if i > 10 {
break
}
}
t.Render()
}