@@ -6,13 +6,21 @@ import (
6
6
"github.com/cli/go-gh"
7
7
"github.com/cli/go-gh/pkg/api"
8
8
"github.com/cli/go-gh/pkg/repository"
9
+ "log"
9
10
"strconv"
10
11
)
11
12
12
13
type Run struct {
13
- WorkflowId int `json:"workflow_id"`
14
- JobsUrl string `json:"jobs_url"`
15
- Id int `json:"id"`
14
+ WorkflowId int `json:"workflow_id"`
15
+ JobsUrl string `json:"jobs_url"`
16
+ Id int `json:"id"`
17
+ Event string `json:"event"`
18
+ DisplayTitle string `json:"display_title"`
19
+ HeadBranch string `json:"head_branch"`
20
+ HtmlUrl string `json:"html_url"`
21
+ Name string `json:"name"`
22
+ Path string `json:"path"`
23
+ Status string `json:"status"`
16
24
}
17
25
18
26
type WorkflowRuns struct {
@@ -22,6 +30,7 @@ type WorkflowRuns struct {
22
30
23
31
type Job struct {
24
32
Id int `json:"id"`
33
+ Name string `json:"name"`
25
34
CheckRunUrl string `json:"check_run_url"`
26
35
Conclusion string `json:"conclusion"`
27
36
Status string `json:"status"`
@@ -33,7 +42,7 @@ type WorkflowJobs struct {
33
42
Jobs []Job `json:"jobs"`
34
43
}
35
44
36
- type Annotations [] struct {
45
+ type Annotation struct {
37
46
Path string `json:"path"`
38
47
BlobHref string `json:"blob_href"`
39
48
Title string `json:"title"`
@@ -46,6 +55,18 @@ type Annotations []struct {
46
55
EndColumn int `json:"end_column"`
47
56
}
48
57
58
+ type Record struct {
59
+ Repository string `json:"repository"`
60
+ WorkflowName string `json:"workflow_name"`
61
+ WorkflowEvent string `json:"workflow_event"`
62
+ WorkflowPath string `json:"workflow_path"`
63
+ WorkflowUrl string `json:"workflow_url"`
64
+ JobName string `json:"job_name"`
65
+ JobConclusion string `json:"job_conclusion"`
66
+ AnnotationLevel string `json:"annotation_level"`
67
+ Message string `json:"message"`
68
+ }
69
+
49
70
func latest (workflowRuns WorkflowRuns ) []Run {
50
71
var latestRuns []Run
51
72
for _ , run := range workflowRuns .Runs {
@@ -94,20 +115,36 @@ func getJobs(client api.RESTClient, repository repository.Repository, run Run) W
94
115
return jobs
95
116
}
96
117
97
- func getAnnotations (client api.RESTClient , repository repository.Repository , job Job ) Annotations {
118
+ func getAnnotations (client api.RESTClient , repository repository.Repository , job Job ) [] Annotation {
98
119
var res []interface {}
99
120
path := "repos/" + repository .Owner () + "/" + repository .Name () + "/check-runs/" + strconv .Itoa (job .Id ) + "/annotations"
100
121
client .Get (path , & res )
101
122
102
123
jsonStr , _ := json .Marshal (res )
103
- var annotations Annotations
124
+ var annotations [] Annotation
104
125
if err := json .Unmarshal ([]byte (jsonStr ), & annotations ); err != nil {
105
126
panic (err )
106
127
}
107
128
108
129
return annotations
109
130
}
110
131
132
+ func toRecord (repository repository.Repository , run Run , job Job , annotation Annotation ) Record {
133
+ r := Record {
134
+ Repository : repository .Owner () + "/" + repository .Name (),
135
+ WorkflowName : run .Name ,
136
+ WorkflowEvent : run .Event ,
137
+ WorkflowPath : run .Path ,
138
+ WorkflowUrl : run .HtmlUrl ,
139
+ JobName : job .Name ,
140
+ JobConclusion : job .Conclusion ,
141
+ AnnotationLevel : annotation .AnnotationLevel ,
142
+ Message : annotation .Message ,
143
+ }
144
+
145
+ return r
146
+ }
147
+
111
148
func main () {
112
149
client , err := gh .RESTClient (nil )
113
150
if err != nil {
@@ -116,19 +153,31 @@ func main() {
116
153
}
117
154
currentRepository , _ := gh .CurrentRepository ()
118
155
119
- //fmt.Printf("%+v\n", workflowRunsRes)
120
-
121
156
workflowRuns := getRuns (client , currentRepository )
122
157
latestRuns := latest (workflowRuns )
123
- fmt .Printf ("%+v\n " , latestRuns )
124
158
159
+ var summary []Record
160
+
161
+ //fmt.Printf("Repository: %s/%s\n", currentRepository.Owner(), currentRepository.Name())
125
162
for _ , run := range latestRuns {
126
- jobs := getJobs ( client , currentRepository , run )
163
+ //fmt.Printf("Workflow(%s): %s(%s)\n", run.Event , run.Name, run.Path )
127
164
165
+ jobs := getJobs (client , currentRepository , run )
128
166
for _ , job := range jobs .Jobs {
167
+ //fmt.Printf("\tJob name: %s, %s\n", job.Name, job.Conclusion)
129
168
annotations := getAnnotations (client , currentRepository , job )
130
- fmt .Print ("\n ===========================================\n " )
131
- fmt .Printf ("%+v\n " , annotations )
169
+ for _ , annotation := range annotations {
170
+ //fmt.Printf("\t\t%s: %s\n", annotation.AnnotationLevel, annotation.Message)
171
+ r := toRecord (currentRepository , run , job , annotation )
172
+ summary = append (summary , r )
173
+ }
132
174
}
133
175
}
176
+
177
+ j , err := json .Marshal (summary )
178
+ if err != nil {
179
+ log .Fatal (err )
180
+ }
181
+
182
+ fmt .Printf ("%s" , string (j ))
134
183
}
0 commit comments