22
22
)
23
23
)
24
24
25
- type workflowsReturn struct {
26
- TotalCount int `json:"total_count"`
27
- Workflows []workflow `json:"workflows"`
28
- }
29
-
30
- type workflow struct {
31
- ID int `json:"id"`
32
- NodeID string `json:"node_id"`
33
- Name string `json:"name"`
34
- Path string `json:"path"`
35
- State string `json:"state"`
36
- }
37
-
38
25
type UBUNTU struct {
39
26
TotalMs float64 `json:"total_ms"`
40
27
}
@@ -59,41 +46,25 @@ func GetBillableFromGithub() {
59
46
client := & http.Client {}
60
47
for {
61
48
for _ , repo := range config .Github .Repositories {
62
- var p workflowsReturn
63
- req , _ := http .NewRequest ("GET" , "https://api.github.com/repos/" + repo + "/actions/workflows" , nil )
64
- req .Header .Set ("Authorization" , "token " + config .Github .Token )
65
- resp , err := client .Do (req )
66
- defer resp .Body .Close ()
67
- if err != nil {
68
- log .Fatal (err )
69
- }
70
- if resp .StatusCode != 200 {
71
- log .Fatalf ("the status code returned by the server is different from 200: %d" , resp .StatusCode )
72
- }
73
- err = json .NewDecoder (resp .Body ).Decode (& p )
74
- if err != nil {
75
- log .Fatal (err )
76
- }
77
-
78
- for _ , w := range p .Workflows {
49
+ for k , v := range workflows [repo ] {
79
50
var bill Bill
80
- req , _ := http .NewRequest ("GET" , "https://api.github.com/repos/" + repo + "/actions/workflows/" + strconv .Itoa (w . ID )+ "/timing" , nil )
51
+ req , _ := http .NewRequest ("GET" , "https://api.github.com/repos/" + repo + "/actions/workflows/" + strconv .Itoa (k )+ "/timing" , nil )
81
52
req .Header .Set ("Authorization" , "token " + config .Github .Token )
82
- resp2 , err := client .Do (req )
83
- defer resp2 .Body .Close ()
53
+ resp , err := client .Do (req )
54
+ defer resp .Body .Close ()
84
55
if err != nil {
85
56
log .Fatal (err )
86
57
}
87
58
if resp .StatusCode != 200 {
88
59
log .Fatalf ("the status code returned by the server is different from 200: %d" , resp .StatusCode )
89
60
}
90
- err = json .NewDecoder (resp2 .Body ).Decode (& bill )
61
+ err = json .NewDecoder (resp .Body ).Decode (& bill )
91
62
if err != nil {
92
63
log .Fatal (err )
93
64
}
94
- WorkflowBillGauge .WithLabelValues (repo , strconv .Itoa (w .ID ), w .NodeID , w .Name , w .State , "MACOS" ).Set (bill .Billable .MACOS .TotalMs / 1000 )
95
- WorkflowBillGauge .WithLabelValues (repo , strconv .Itoa (w .ID ), w .NodeID , w .Name , w .State , "WINDOWS" ).Set (bill .Billable .WINDOWS .TotalMs / 1000 )
96
- WorkflowBillGauge .WithLabelValues (repo , strconv .Itoa (w .ID ), w .NodeID , w .Name , w .State , "UBUNTU" ).Set (bill .Billable .UBUNTU .TotalMs / 1000 )
65
+ WorkflowBillGauge .WithLabelValues (repo , strconv .Itoa (v .ID ), v .NodeID , v .Name , v .State , "MACOS" ).Set (bill .Billable .MACOS .TotalMs / 1000 )
66
+ WorkflowBillGauge .WithLabelValues (repo , strconv .Itoa (v .ID ), v .NodeID , v .Name , v .State , "WINDOWS" ).Set (bill .Billable .WINDOWS .TotalMs / 1000 )
67
+ WorkflowBillGauge .WithLabelValues (repo , strconv .Itoa (v .ID ), v .NodeID , v .Name , v .State , "UBUNTU" ).Set (bill .Billable .UBUNTU .TotalMs / 1000 )
97
68
}
98
69
}
99
70
0 commit comments