forked from KevinSnyderCodes/github-deployment-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
110 lines (94 loc) · 2.42 KB
/
metadata.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
101
102
103
104
105
106
107
108
109
110
package resource
import (
"strconv"
"github.com/shipt/go-github/v32/github"
)
func metadataFromDeployment(deployment *github.Deployment, statuses []*github.DeploymentStatus) []MetadataPair {
metadata := []MetadataPair{}
if deployment.ID != nil {
id := *deployment.ID
nameMeta := MetadataPair{
Name: "id",
Value: strconv.FormatInt(id, 10),
}
metadata = append(metadata, nameMeta)
}
if deployment.Ref != nil && *deployment.Ref != "" {
refMeta := MetadataPair{
Name: "ref",
Value: *deployment.Ref,
}
metadata = append(metadata, refMeta)
}
if deployment.SHA != nil && *deployment.SHA != "" {
shaMeta := MetadataPair{
Name: "sha",
Value: *deployment.SHA,
}
metadata = append(metadata, shaMeta)
}
if deployment.Task != nil && *deployment.Task != "" {
taskMeta := MetadataPair{
Name: "task",
Value: *deployment.Task,
}
metadata = append(metadata, taskMeta)
}
if deployment.Environment != nil && *deployment.Environment != "" {
envMeta := MetadataPair{
Name: "environment",
Value: *deployment.Environment,
}
metadata = append(metadata, envMeta)
}
if deployment.Description != nil && *deployment.Description != "" {
descMeta := MetadataPair{
Name: "description",
Value: *deployment.Description,
}
metadata = append(metadata, descMeta)
}
if deployment.Creator != nil {
creatorMeta := MetadataPair{
Name: "creator",
Value: *deployment.Creator.Login,
}
metadata = append(metadata, creatorMeta)
}
if deployment.CreatedAt != nil {
createdtAtMeta := MetadataPair{
Name: "created_at",
Value: deployment.CreatedAt.Format("2006-01-02 15:04:05"),
}
metadata = append(metadata, createdtAtMeta)
}
if len(statuses) > 0 {
if statuses[0].ID != nil {
id := *statuses[0].ID
nameMeta := MetadataPair{
Name: "status_id",
Value: strconv.FormatInt(id, 10),
}
metadata = append(metadata, nameMeta)
}
if statuses[0].State != nil && *statuses[0].State != "" {
envMeta := MetadataPair{
Name: "status",
Value: *statuses[0].State,
}
metadata = append(metadata, envMeta)
}
if statuses[0].CreatedAt != nil {
createdtAtMeta := MetadataPair{
Name: "status_created_at",
Value: statuses[0].CreatedAt.Format("2006-01-02 15:04:05"),
}
metadata = append(metadata, createdtAtMeta)
}
}
metadata = append(metadata, MetadataPair{
Name: "status_count",
Value: strconv.Itoa(len(statuses)),
})
return metadata
}