This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
90 lines (70 loc) · 1.57 KB
/
state.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
package main
import (
"github.com/aws/aws-sdk-go/service/codepipeline"
"time"
)
type PipelineStageState struct {
Name string
State string
HtmlState string
LastChanged string
}
type PipelineState struct {
Name string
Stages []PipelineStageState
}
func AppendIfMissing(slice []string, i string) []string {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}
func allStageNames(pipelineStates []*PipelineState) []string {
var stages []string
for _, pipelineState := range pipelineStates {
for _, stage := range pipelineState.Stages {
stages = AppendIfMissing(stages, stage.Name)
}
}
return stages
}
func stageByName(name string, pipelineStates *PipelineState) PipelineStageState {
for _, stage := range pipelineStates.Stages {
if name == stage.Name {
return stage
}
}
return PipelineStageState{}
}
func getLastStateChange(stageState *codepipeline.StageState, timeFormat string) string {
var result *time.Time
for _, action := range stageState.ActionStates {
if action.LatestExecution.LastStatusChange == nil {
continue
}
if result != nil && result.After(*action.LatestExecution.LastStatusChange) {
continue
}
result = action.LatestExecution.LastStatusChange
}
if result == nil {
now := time.Now()
now.Add(-200000)
return now.Format(timeFormat)
}
return result.Format(timeFormat)
}
func getHtmlStateFor(state string) string {
if state == "Succeeded" {
return "success"
}
if state == "InProgress" {
return "dark"
}
if state == "Failed" {
return "danger"
}
return "warning"
}