@@ -397,14 +397,13 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
397
397
gitlabState = gitlab .Success
398
398
}
399
399
400
- // refTarget is set to the head pipeline of the MR if it exists, or else it is set to the head branch
401
- // of the MR. This is needed because the commit status is only shown in the MR if the pipeline is
402
- // assigned to an MR reference.
403
- // Try to get the MR details a couple of times in case the pipeline is not yet assigned to the MR
404
- refTarget := pull .HeadBranch
405
-
406
- retries := 1
407
- delay := 2 * time .Second
400
+ // create these pointers here so that they can be nil when they get to the request and are omitted
401
+ var refTarget * string
402
+ var pipelineID * int
403
+
404
+ retries := 2
405
+ delay := 5 * time .Second
406
+
408
407
var mr * gitlab.MergeRequest
409
408
var err error
410
409
@@ -414,17 +413,24 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
414
413
return err
415
414
}
416
415
if mr .HeadPipeline != nil {
417
- logger .Debug ("Head pipeline found for merge request %d, source '%s'. refTarget '%s'" ,
418
- pull .Num , mr .HeadPipeline .Source , mr .HeadPipeline .Ref )
419
- refTarget = mr .HeadPipeline .Ref
416
+ logger .Info ("Head pipeline found for merge request %d, source '%s'. pipelineID '%s'" ,
417
+ pull .Num , mr .HeadPipeline .Source , mr .HeadPipeline .ID )
418
+ pipelineID = gitlab .Ptr (mr .HeadPipeline .ID )
419
+
420
+ // let's check to see if the pipeline sha matches the head commit.
421
+ if mr .HeadPipeline .SHA != pull .HeadCommit {
422
+ logger .Err ("Head pipeline SHA does not match pull head commit" )
423
+ }
420
424
break
421
425
}
422
426
if i != retries {
423
- logger .Debug ("Head pipeline not found for merge request %d. Retrying in %s" ,
427
+ logger .Info ("Head pipeline not found for merge request %d. Retrying in %s" ,
424
428
pull .Num , delay )
425
429
time .Sleep (delay )
426
430
} else {
427
- logger .Debug ("Head pipeline not found for merge request %d." ,
431
+ headBranch := pull .HeadBranch
432
+ refTarget = gitlab .Ptr (headBranch )
433
+ logger .Warn ("Head pipeline not found for merge request %d." ,
428
434
pull .Num )
429
435
}
430
436
}
@@ -434,7 +440,8 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
434
440
Context : gitlab .Ptr (src ),
435
441
Description : gitlab .Ptr (description ),
436
442
TargetURL : & url ,
437
- Ref : gitlab .Ptr (refTarget ),
443
+ PipelineID : pipelineID ,
444
+ Ref : refTarget ,
438
445
})
439
446
if resp != nil {
440
447
logger .Debug ("POST /projects/%s/statuses/%s returned: %d" , repo .FullName , pull .HeadCommit , resp .StatusCode )
@@ -461,7 +468,7 @@ func (g *GitlabClient) WaitForSuccessPipeline(logger logging.SimpleLogging, ctx
461
468
case <- ctx .Done ():
462
469
// validation check time out
463
470
cancel ()
464
- return //ctx.Err()
471
+ return // ctx.Err()
465
472
466
473
default :
467
474
mr , _ := g .GetMergeRequest (logger , pull .BaseRepo .FullName , pull .Num )
0 commit comments