44 "bytes"
55 "context"
66 "crypto/hmac"
7- "crypto/sha1"
7+ "crypto/sha1" // nolint: gosec
88 "encoding/hex"
99 "errors"
1010 "fmt"
8282)
8383
8484func init () {
85- //Register metrics with prometheus
85+ // Register metrics with prometheus
8686 prometheus .MustRegister (workflowJobHistogramVec )
8787 prometheus .MustRegister (histogramVec )
8888 prometheus .MustRegister (totalMinutesUsedActions )
@@ -97,11 +97,11 @@ func init() {
9797type GHActionExporter struct {
9898 GHClient * github.Client
9999 Logger log.Logger
100- Opts ServerOpts
100+ Opts Opts
101101 JobObserver WorkflowJobObserver
102102}
103103
104- func NewGHActionExporter (logger log.Logger , opts ServerOpts ) * GHActionExporter {
104+ func NewGHActionExporter (logger log.Logger , opts Opts ) * GHActionExporter {
105105 ctx := context .Background ()
106106 ts := oauth2 .StaticTokenSource (
107107 & oauth2.Token {AccessToken : opts .GitHubAPIToken },
@@ -122,13 +122,13 @@ func (c *GHActionExporter) CollectActionBilling() {
122122 if c .Opts .GitHubOrg != "" {
123123 actionsBilling , _ , err := c .GHClient .Billing .GetActionsBillingOrg (context .TODO (), c .Opts .GitHubOrg )
124124 if err != nil {
125- c .Logger .Log ("msg" , "failed to retrive the actions billing for an org" , "org" , c .Opts .GitHubOrg , "err" , err )
125+ _ = c .Logger .Log ("msg" , "failed to retrieve the actions billing for an org" , "org" , c .Opts .GitHubOrg , "err" , err )
126126 return
127127 }
128128
129129 totalMinutesUsedActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (float64 (actionsBilling .TotalMinutesUsed ))
130130 includedMinutesUsedActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (float64 (actionsBilling .IncludedMinutes ))
131- totalPaidMinutesActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (float64 ( actionsBilling .TotalPaidMinutesUsed ) )
131+ totalPaidMinutesActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (actionsBilling .TotalPaidMinutesUsed )
132132 totalMinutesUsedUbuntuActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (float64 (actionsBilling .MinutesUsedBreakdown .Ubuntu ))
133133 totalMinutesUsedMacOSActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (float64 (actionsBilling .MinutesUsedBreakdown .MacOS ))
134134 totalMinutesUsedWindowsActions .WithLabelValues (c .Opts .GitHubOrg , "" ).Set (float64 (actionsBilling .MinutesUsedBreakdown .Windows ))
@@ -137,13 +137,13 @@ func (c *GHActionExporter) CollectActionBilling() {
137137 if c .Opts .GitHubUser != "" {
138138 actionsBilling , _ , err := c .GHClient .Billing .GetActionsBillingUser (context .TODO (), c .Opts .GitHubUser )
139139 if err != nil {
140- c .Logger .Log ("msg" , "failed to retrive the actions billing for an user" , "user" , c .Opts .GitHubUser , "err" , err )
140+ _ = c .Logger .Log ("msg" , "failed to retrieve the actions billing for an user" , "user" , c .Opts .GitHubUser , "err" , err )
141141 return
142142 }
143143
144144 totalMinutesUsedActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (float64 (actionsBilling .TotalMinutesUsed ))
145145 includedMinutesUsedActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (float64 (actionsBilling .IncludedMinutes ))
146- totalPaidMinutesActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (float64 ( actionsBilling .TotalPaidMinutesUsed ) )
146+ totalPaidMinutesActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (actionsBilling .TotalPaidMinutesUsed )
147147 totalMinutesUsedUbuntuActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (float64 (actionsBilling .MinutesUsedBreakdown .Ubuntu ))
148148 totalMinutesUsedMacOSActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (float64 (actionsBilling .MinutesUsedBreakdown .MacOS ))
149149 totalMinutesUsedWindowsActions .WithLabelValues ("" , c .Opts .GitHubUser ).Set (float64 (actionsBilling .MinutesUsedBreakdown .Windows ))
@@ -156,14 +156,14 @@ func (c *GHActionExporter) HandleGHWebHook(w http.ResponseWriter, r *http.Reques
156156
157157 receivedHash := strings .SplitN (r .Header .Get ("X-Hub-Signature" ), "=" , 2 )
158158 if receivedHash [0 ] != "sha1" {
159- level .Error (c .Logger ).Log ("msg" , "invalid webhook hash signature: SHA1" )
159+ _ = level .Error (c .Logger ).Log ("msg" , "invalid webhook hash signature: SHA1" )
160160 w .WriteHeader (http .StatusForbidden )
161161 return
162162 }
163163
164164 err := validateSignature (c .Opts .GitHubToken , receivedHash , buf )
165165 if err != nil {
166- level .Error (c .Logger ).Log ("msg" , "invalid token" , "err" , err )
166+ _ = level .Error (c .Logger ).Log ("msg" , "invalid token" , "err" , err )
167167 w .WriteHeader (http .StatusForbidden )
168168 return
169169 }
@@ -173,23 +173,23 @@ func (c *GHActionExporter) HandleGHWebHook(w http.ResponseWriter, r *http.Reques
173173 case "ping" :
174174 pingEvent := model .PingEventFromJSON (ioutil .NopCloser (bytes .NewBuffer (buf )))
175175 if pingEvent == nil {
176- level .Info (c .Logger ).Log ("msg" , "ping event" , "hookID" , pingEvent .GetHookID ())
176+ _ = level .Info (c .Logger ).Log ("msg" , "ping event" , "hookID" , pingEvent .GetHookID ())
177177 w .WriteHeader (http .StatusBadRequest )
178178 return
179179 }
180180 w .WriteHeader (http .StatusAccepted )
181- w .Write ([]byte (`{"status": "honk"}` ))
181+ _ , _ = w .Write ([]byte (`{"status": "honk"}` ))
182182 return
183183 case "check_run" :
184184 event := model .CheckRunEventFromJSON (ioutil .NopCloser (bytes .NewBuffer (buf )))
185- level .Info (c .Logger ).Log ("msg" , "got check_run event" , "org" , event .GetRepo ().GetOwner ().GetLogin (), "repo" , event .GetRepo ().GetName (), "workflowName" , event .GetCheckRun ().GetName ())
185+ _ = level .Info (c .Logger ).Log ("msg" , "got check_run event" , "org" , event .GetRepo ().GetOwner ().GetLogin (), "repo" , event .GetRepo ().GetName (), "workflowName" , event .GetCheckRun ().GetName ())
186186 go c .CollectWorkflowRun (event )
187187 case "workflow_job" :
188188 event := model .WorkflowJobEventFromJSON (ioutil .NopCloser (bytes .NewBuffer (buf )))
189- level .Info (c .Logger ).Log ("msg" , "got workflow_job event" , "org" , event .GetRepo ().GetOwner ().GetLogin (), "repo" , event .GetRepo ().GetName (), "runId" , event .GetWorkflowJob ().GetRunID ())
189+ _ = level .Info (c .Logger ).Log ("msg" , "got workflow_job event" , "org" , event .GetRepo ().GetOwner ().GetLogin (), "repo" , event .GetRepo ().GetName (), "runId" , event .GetWorkflowJob ().GetRunID ())
190190 go c .CollectWorkflowJobEvent (event )
191191 default :
192- level .Info (c .Logger ).Log ("msg" , "not implemented" )
192+ _ = level .Info (c .Logger ).Log ("msg" , "not implemented" )
193193 w .WriteHeader (http .StatusNotImplemented )
194194 return
195195 }
0 commit comments