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:
When we have /gitlab relative path in the API we are getting
the wrong organization info because there is a function which
get Organization and Repository info again from URL

so for a GitLab API https://example.servehttp.com/gitlab/root/testpac
initially Organization and Repository value from GitLab coming
as root and testpac

But later in the event.go file we are refetching Organization and
Repository from event.URL because of that
Organization is coming as gitlab/root and
Repository as testpac.

that's why getting project info api call ex:
(https://example.servehttp.com/gitlab/api/v4/projects/gitlab/root/testpac)
is failing with 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 9, 2025
1 parent e0d0ad7 commit cdab005
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pkg/formatting/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package formatting
import (
"fmt"
"net/url"
"path/filepath"
"strings"

"golang.org/x/text/cases"
Expand Down Expand Up @@ -51,7 +50,7 @@ func GetRepoOwnerSplitted(u string) (string, string, error) {
if len(parts) < 3 {
return "", "", fmt.Errorf("invalid repo url at least a organization/project and a repo needs to be specified: %s", u)
}
org := filepath.Join(parts[0 : len(parts)-1]...)
org := parts[len(parts)-2]
repo := parts[len(parts)-1]
return org, repo, nil
}
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
6 changes: 3 additions & 3 deletions pkg/reconciler/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func buildEventFromPipelineRun(pr *tektonv1.PipelineRun) *info.Event {
event.URL = prAnno[keys.RepoURL]
// it's safer to get repo, org from repo.url since we have to remove the / and other chars in labels which drops
// the SubPath that gitlab is using.
repo, org, _ := formatting.GetRepoOwnerSplitted(event.URL)
event.Organization = repo
event.Repository = org
org, repo, _ := formatting.GetRepoOwnerSplitted(event.URL)
event.Organization = org
event.Repository = repo
event.EventType = prAnno[keys.EventType]
event.TriggerTarget = triggertype.StringToType(prAnno[keys.EventType])
event.BaseBranch = prAnno[keys.Branch]
Expand Down

0 comments on commit cdab005

Please sign in to comment.