Skip to content

Commit

Permalink
Resolve status update issue for GitLab instances with relative paths
Browse files Browse the repository at this point in the history
Issue:
For GitLab instances hosted under a relative path
(e.g., https://example.servehttp.com/gitlab),
status updates on MR fail to propagate correctly.
Although initial events like Repository CR creation,
starting PipelineRuns based on webhooks from GitLab,
reporting status on Pipeline start works fine.
subsequent updates (e.g., marking the PipelineRun as Finished)
do not reflect in GitLab, leaving the status stuck on Running state.

Root Cause:
The sourceProjectID and targetProjectID in the event object
were being reset to  for GitLab instances with relative paths,
causing API requests to GitLab
(https://example.servehttp.com/gitlab/api/v4/projects/gitlab/root/testpac)
to fail with a 404 error.

With this PR changes now status is getting updated successfully.

Signed-off-by: savitaashture <sashture@redhat.com>
  • Loading branch information
savitaashture committed Jan 8, 2025
1 parent e0d0ad7 commit 3478eff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/provider/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ func (v *Provider) SetClient(_ context.Context, run *params.Run, runevent *info.
}
v.Token = &runevent.Provider.Token

// If sourceProjectID and targetProjectID are not present in provider, we should first attempt to retrieve them from runevent.
if v.sourceProjectID == 0 && runevent.SourceProjectID != 0 {
v.sourceProjectID = runevent.SourceProjectID
}
if v.targetProjectID == 0 && runevent.TargetProjectID != 0 {
v.targetProjectID = runevent.TargetProjectID
}

// if we don't have sourceProjectID (ie: incoming-webhook) then try to set
// it ASAP if we can.
if v.sourceProjectID == 0 && runevent.Organization != "" && runevent.Repository != "" {
Expand Down
2 changes: 2 additions & 0 deletions pkg/provider/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ func TestSetClientDetectAPIURL(t *testing.T) {
assert.ErrorContains(t, err, "no git_provider.secret has been set")

event.Provider.Token = "hello"
event.TargetProjectID = 10
event.SourceProjectID = 10

v.repoURL, event.URL, event.Provider.URL = "", "", ""
event.URL = fmt.Sprintf("%s/hello-this-is-me-ze/project", fakehost)
Expand Down

0 comments on commit 3478eff

Please sign in to comment.