@@ -160,26 +160,27 @@ func NewServer(serverConfig ServerConfig) (*Server, error) {
160
160
func (s * Server ) HandleRoot (w http.ResponseWriter , r * http.Request ) {
161
161
162
162
requestID := randStringBytes (6 )
163
- s .Logger .Infof (requestID , " ---START---" )
163
+ s .Logger .Infof ("%s ---START---", requestID )
164
164
165
165
body , err := ioutil .ReadAll (r .Body )
166
166
if err != nil {
167
- s .Logger .Errorf (requestID , err .Error ())
168
- http .Error (w , "could not read body" , http .StatusInternalServerError )
167
+ msg := "could not read body"
168
+ s .Logger .Errorf ("%s %s: %s" , requestID , msg , err )
169
+ http .Error (w , msg , http .StatusInternalServerError )
169
170
return
170
171
}
171
172
172
173
if err := validatePayload (r .Header , body , []byte (s .WebhookSecret )); err != nil {
173
174
msg := "failed to validate incoming request"
174
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
175
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
175
176
http .Error (w , msg , http .StatusBadRequest )
176
177
return
177
178
}
178
179
179
180
req := & requestBitbucket {}
180
181
if err := json .Unmarshal (body , & req ); err != nil {
181
182
msg := fmt .Sprintf ("cannot parse JSON: %s" , err )
182
- s .Logger .Errorf (requestID , msg )
183
+ s .Logger .Errorf ("%s %s" , requestID , msg )
183
184
http .Error (w , msg , http .StatusBadRequest )
184
185
return
185
186
}
@@ -208,7 +209,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
208
209
change .Ref .Type ,
209
210
allowedChangeRefType ,
210
211
)
211
- s .Logger .Warnf (requestID , msg )
212
+ s .Logger .Warnf ("%s %s" , requestID , msg )
212
213
// According to MDN (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418),
213
214
// "some websites use this response for requests they do not wish to handle [...]".
214
215
http .Error (w , msg , http .StatusTeapot )
@@ -230,7 +231,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
230
231
commitSHA = req .PullRequest .FromRef .LatestCommit
231
232
} else {
232
233
msg := fmt .Sprintf ("Unsupported event key: %s" , req .EventKey )
233
- s .Logger .Warnf (requestID , msg )
234
+ s .Logger .Warnf ("%s %s" , requestID , msg )
234
235
http .Error (w , msg , http .StatusBadRequest )
235
236
return
236
237
}
@@ -266,7 +267,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
266
267
csha , err := getCommitSHA (s .BitbucketClient , pData .Project , pData .Repository , pData .GitFullRef )
267
268
if err != nil {
268
269
msg := "could not get commit SHA"
269
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
270
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
270
271
http .Error (w , msg , http .StatusInternalServerError )
271
272
return
272
273
}
@@ -277,7 +278,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
277
278
skip := shouldSkip (s .BitbucketClient , pData .Project , pData .Repository , commitSHA )
278
279
if skip {
279
280
msg := "Commit should be skipped"
280
- s .Logger .Infof (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
281
+ s .Logger .Infof ("%s %s : %s" , requestID , msg , err )
281
282
// According to MDN (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418),
282
283
// "some websites use this response for requests they do not wish to handle [..]".
283
284
http .Error (w , msg , http .StatusTeapot )
@@ -286,7 +287,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
286
287
prInfo , err := extractPullRequestInfo (s .BitbucketClient , pData .Project , pData .Repository , commitSHA )
287
288
if err != nil {
288
289
msg := "Could not extract PR info"
289
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
290
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
290
291
http .Error (w , msg , http .StatusInternalServerError )
291
292
return
292
293
}
@@ -302,7 +303,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
302
303
303
304
if err != nil {
304
305
msg := fmt .Sprintf ("could not download ODS config for repo %s" , pData .Repository )
305
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
306
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
306
307
http .Error (w , msg , http .StatusInternalServerError )
307
308
return
308
309
}
@@ -313,7 +314,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
313
314
env , err := odsConfig .Environment (pData .Environment )
314
315
if err != nil {
315
316
msg := fmt .Sprintf ("environment misconfiguration: %s" , err )
316
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
317
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
317
318
http .Error (w , msg , http .StatusInternalServerError )
318
319
return
319
320
}
@@ -328,7 +329,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
328
329
_ , err := s .TektonClient .CreatePipeline (r .Context (), newPipeline , metav1.CreateOptions {})
329
330
if err != nil {
330
331
msg := fmt .Sprintf ("cannot create pipeline %s" , newPipeline .Name )
331
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
332
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
332
333
http .Error (w , msg , http .StatusInternalServerError )
333
334
return
334
335
}
@@ -337,7 +338,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
337
338
_ , err := s .TektonClient .UpdatePipeline (r .Context (), newPipeline , metav1.UpdateOptions {})
338
339
if err != nil {
339
340
msg := fmt .Sprintf ("cannot update pipeline %s" , newPipeline .Name )
340
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
341
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
341
342
http .Error (w , msg , http .StatusInternalServerError )
342
343
return
343
344
}
@@ -347,7 +348,7 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
347
348
err = s .createPVCIfRequired (r .Context (), pData )
348
349
if err != nil {
349
350
msg := "cannot create workspace PVC"
350
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
351
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
351
352
http .Error (w , msg , http .StatusInternalServerError )
352
353
return
353
354
}
@@ -356,45 +357,45 @@ func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request) {
356
357
// parallel pipeline runs.
357
358
s .Mutex .Lock ()
358
359
defer s .Mutex .Unlock ()
359
- s .Logger .Infof (requestID , fmt . Sprintf ( " Starting pruning of pipeline runs related to repository %s ..." , pData .Repository ) )
360
+ s .Logger .Infof ("%s Starting pruning of pipeline runs related to repository %s ..." , requestID , pData .Repository )
360
361
ctxt , cancel := context .WithTimeout (context .Background (), 5 * time .Minute )
361
362
defer cancel ()
362
363
pipelineRuns , err := listPipelineRuns (s .TektonClient , ctxt , pData .Repository )
363
364
if err != nil {
364
365
msg := "could not retrieve existing pipeline runs"
365
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
366
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
366
367
http .Error (w , msg , http .StatusInternalServerError )
367
368
return
368
369
}
369
- s .Logger .Debugf (requestID , fmt . Sprintf ( " Found %d pipeline runs related to repository %s." , len (pipelineRuns .Items ), pData .Repository ) )
370
+ s .Logger .Debugf ("%s Found %d pipeline runs related to repository %s." , requestID , len (pipelineRuns .Items ), pData .Repository )
370
371
371
372
if s .PipelineRunPruner != nil {
372
373
go func () {
373
374
ctxt , cancel := context .WithTimeout (context .Background (), 5 * time .Minute )
374
375
defer cancel ()
375
376
err = s .PipelineRunPruner .Prune (ctxt , pipelineRuns .Items )
376
377
if err != nil {
377
- s .Logger .Warnf (fmt . Sprintf (
378
+ s .Logger .Warnf (
378
379
"Pruning pipeline runs of repository %s failed: %s" ,
379
380
pData .Repository , err ,
380
- ))
381
+ )
381
382
}
382
383
}()
383
384
}
384
385
385
- s .Logger .Infof (requestID , fmt . Sprintf ( "% +v" , pData ) )
386
+ s .Logger .Infof ("%s % +v" , requestID , pData )
386
387
387
388
_ , err = createPipelineRun (s .TektonClient , r .Context (), pData )
388
389
if err != nil {
389
390
msg := "cannot create pipeline run"
390
- s .Logger .Errorf (requestID , fmt . Sprintf ( "%s: %s" , msg , err ) )
391
+ s .Logger .Errorf ("%s %s : %s" , requestID , msg , err )
391
392
http .Error (w , msg , http .StatusInternalServerError )
392
393
return
393
394
}
394
395
395
396
err = json .NewEncoder (w ).Encode (pData )
396
397
if err != nil {
397
- s .Logger .Errorf (requestID , fmt . Sprintf ( " cannot write body: %s" , err ) )
398
+ s .Logger .Errorf ("%s cannot write body: %s" , requestID , err )
398
399
return
399
400
}
400
401
}
0 commit comments