Skip to content

Commit

Permalink
gitlab: remove project ID lookup for CI Bridge jobs
Browse files Browse the repository at this point in the history
The project ID for Bridge jobs (downstream pipeline) were being retrieved
from the WebURL text butchering plus one additional API request for looking
up the project based on the name.

Few releases ago GitLab started to expose the project ID in the pipeline
object for such jobs. Now, it's possible to get it without any additional
pipeline request.

Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
  • Loading branch information
bmeneg committed Aug 11, 2021
1 parent 501c6d6 commit 778bd48
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,25 +1273,8 @@ func CIJobs(pid interface{}, id int, followBridge bool, bridgeName string) ([]Jo
continue
}

// Unfortunately the GitLab API doesn't exposes the project ID nor name that the
// bridge job points to, since it might be extarnal to the config core.host
// hostname, hence the WebURL is exposed.
// With that, and considering we don't want to support anything outside the
// core.host, we need to massage the WebURL to get the project name that we can
// search for.
// WebURL format:
// <core.host>/<bridged-project-name-with-namespace>/-/pipelines/<id>
projectName := strings.Replace(bridge.DownstreamPipeline.WebURL, host+"/", "", 1)
pipelineText := fmt.Sprintf("/-/pipelines/%d", bridge.DownstreamPipeline.ID)
projectName = strings.Replace(projectName, pipelineText, "", 1)

p, err := FindProject(projectName)
if err != nil {
continue
}

// Switch to the new project name and downstream pipeline id
pid = p.PathWithNamespace
pid = bridge.DownstreamPipeline.ProjectID
id = bridge.DownstreamPipeline.ID

for {
Expand Down

0 comments on commit 778bd48

Please sign in to comment.