Skip to content

fix(git): avoid misclassifying GitLab repository URLs - #4002

Draft
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/gitlab-provider-detection
Draft

fix(git): avoid misclassifying GitLab repository URLs#4002
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/gitlab-provider-detection

Conversation

@Elvand-Lie

Copy link
Copy Markdown
Contributor

Changes

Fix automatic Git provider detection so repository path text cannot be mistaken for the provider hostname.

Previously, GitProviderName searched the complete repository URL with strings.Contains. Because GitHub was checked first, a valid GitLab URL such as https://gitlab.com/foo/github-actions could incorrectly be classified as GitHub.

Provider detection now parses normal transport and SCP-style Git URLs using the repository's existing github.com/chainguard-dev/git-urls dependency, considers only the parsed hostname, and compares provider names as complete, case-insensitive hostname labels.

This preserves GitHub and GitLab detection while preventing repository paths, user information, and partial hostname labels from influencing the result. For example:

https://gitlab.com/foo/github-actions
  -> GitLab

https://github.com/foo/gitlab-runner
  -> GitHub

git@gitlab.com:foo/github-actions.git
  -> GitLab

https://example.com/foo/github-actions
  -> unsupported

https://notgithub.example.com/foo/bar
  -> unsupported

Validation completed with Go 1.26.5 in the official golang:1.26 Linux/ARM64 container:

  • go test ./pkg/git
  • go vet ./pkg/git
  • go test ./cmd/... ./pkg/git/...
  • gofmt -d
  • git diff --check
  • make check-whitespace check-eof

No dependency was added; github.com/chainguard-dev/git-urls was already used by the repository.

/kind bug

Release Note

Fixed automatic Git provider detection so repository path text cannot cause GitLab URLs to be mistaken for GitHub.

Docs

NONE

Signed-off-by: Elvand-Lie <elvandlie@gmail.com>
@knative-prow knative-prow Bot added do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. kind/bug Bugs labels Aug 10, 2026
@knative-prow
knative-prow Bot requested a review from dsimansk August 10, 2026 19:59
@knative-prow

knative-prow Bot commented Aug 10, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Elvand-Lie
Once this PR has been reviewed and has the lgtm label, please assign lkingland for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow
knative-prow Bot requested a review from jrangelramos August 10, 2026 19:59
@knative-prow knative-prow Bot added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Aug 10, 2026
@knative-prow

knative-prow Bot commented Aug 10, 2026

Copy link
Copy Markdown

Hi @Elvand-Lie. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. kind/bug Bugs needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant