Skip to content

Commit

Permalink
clarify comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rhariady committed Feb 18, 2025
1 parent 7c90cc2 commit 298fe33
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions server/events/vcs/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,32 +443,29 @@ func (g *GitlabClient) UpdateStatus(logger logging.SimpleLogging, repo models.Re
return err
}
if len(commitStatuses) > 0 {
// Create a slice to hold all the unique pipelineIds
var pipelineIds []int

// Loop through the map and collect unique pipelineId
// Loop through the commitStatuses and collect unique pipelineId
for _, commitStatus := range commitStatuses {
// only add pipelineId to slices if it's not in the slices yet
if !(slices.Contains(pipelineIds, commitStatus.PipelineId)) {
pipelineIds = append(pipelineIds, commitStatus.PipelineId)
}
}

// Ensure that all commit statuses has identical pipeline ID reflected by only one pipeline ID
// Check that all commit statuses has identical pipeline ID reflected by only one item in pipelineIds
if len(pipelineIds) == 1 {
logger.Info("Exactly one PipelineID found for commit %s and ref %s, setting new status PipelineID to %d", pull.HeadCommit, pull.HeadBranch, pipelineIds[0])

// Set the pipeline ID to the last pipeline that ran for the commit
// Set the pipeline ID to the only item in pipelineIds
setCommitStatusOptions.PipelineID = gitlab.Ptr(pipelineIds[0])
break
} else {
logger.Warn("Commit %s has statuses from more than one PipelineID (ids=%v) for ref %s. Set PipelineID from the last commit status: %s", pull.HeadCommit, pipelineIds, pull.HeadBranch, commitStatuses[0].PipelineId)

// Set the pipeline ID to the last pipeline that ran for the commit
// Set the pipeline ID from the latest commit status
setCommitStatusOptions.PipelineID = gitlab.Ptr(commitStatuses[0].PipelineId)
break
}

break
}
if i != retries {
logger.Info("No pipeline found for commit %s and ref %s, retrying in %s", pull.HeadCommit, pull.HeadBranch, delay)
Expand Down

0 comments on commit 298fe33

Please # to comment.