Skip to content

Commit 7ca0bd9

Browse files
authored
fix: correctly update pending and running commit status (#2341)
* fix(gitlab): set parent status to success when CI is triggered Set parent status to success when /ok-to-test is approved by admin. Signed-off-by: ab-ghosh <abhi.ghosh3108@gmail.com>
1 parent c690b58 commit 7ca0bd9

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

pkg/pipelineascode/match.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ func (p *PacRun) verifyRepoAndUser(ctx context.Context) (*v1alpha1.Repository, e
107107
if allowed, err := p.checkAccessOrError(ctx, repo, status, "via "+p.event.TriggerTarget.String()); !allowed {
108108
return nil, err
109109
}
110+
// When /ok-to-test is approved, update the parent "Pipelines as Code CI" status to success
111+
// to indicate the approval was successful before pipelines start running.
112+
if p.event.EventType == opscomments.OkToTestCommentEventType.String() {
113+
approvalStatus := provider.StatusOpts{
114+
Status: CompletedStatus,
115+
Title: "Approved",
116+
Conclusion: successConclusion,
117+
DetailsURL: p.event.URL,
118+
}
119+
if err := p.vcx.CreateStatus(ctx, p.event, approvalStatus); err != nil {
120+
p.logger.Warnf("failed to update parent status on /ok-to-test approval: %v", err)
121+
}
122+
}
110123
}
111124
return repo, nil
112125
}

pkg/pipelineascode/pipelineascode.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
CompletedStatus = "completed"
3232
inProgressStatus = "in_progress"
3333
queuedStatus = "queued"
34+
successConclusion = "success"
3435
failureConclusion = "failure"
3536
pendingConclusion = "pending"
3637
neutralConclusion = "neutral"

pkg/provider/gitlab/gitlab.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
300300
statusOpts.Conclusion = "success"
301301
statusOpts.Title = "completed"
302302
case "pending":
303+
statusOpts.Conclusion = "pending"
304+
}
305+
// When the pipeline is actually running (in_progress), show it as running
306+
// not pending. Pending is only for waiting states like /ok-to-test approval.
307+
if statusOpts.Status == "in_progress" {
303308
statusOpts.Conclusion = "running"
304309
}
305310
if statusOpts.DetailsURL != "" {

0 commit comments

Comments
 (0)