2222 )
2323)
2424
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-
3825type UBUNTU struct {
3926 TotalMs float64 `json:"total_ms"`
4027}
@@ -59,41 +46,25 @@ func GetBillableFromGithub() {
5946 client := & http.Client {}
6047 for {
6148 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 ] {
7950 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 )
8152 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 ()
8455 if err != nil {
8556 log .Fatal (err )
8657 }
8758 if resp .StatusCode != 200 {
8859 log .Fatalf ("the status code returned by the server is different from 200: %d" , resp .StatusCode )
8960 }
90- err = json .NewDecoder (resp2 .Body ).Decode (& bill )
61+ err = json .NewDecoder (resp .Body ).Decode (& bill )
9162 if err != nil {
9263 log .Fatal (err )
9364 }
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 )
9768 }
9869 }
9970
0 commit comments