New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fix: parse the git url correctly to detect the git type #3437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/assign
if (url.includes('github.com')) { | ||
if (url.includes('https://github.com/') || url.includes('@github.com:')) { | ||
return GitTypes.github; | ||
} | ||
if (url.includes('bitbucket.org')) { | ||
if (url.includes('https://bitbucket.org/') || url.includes('@bitbucket.org:')) { | ||
return GitTypes.bitbucket; | ||
} | ||
if (url.includes('gitlab.com')) { | ||
if (url.includes('https://gitlab.com/') || url.includes('@gitlab.com:')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of repeating code with one minor difference, this makes it harder to maintain and if we need to add more checks, it's a bit of a mess.
If you rebase on top of master, you'll get #3429 and perhaps you can just add the prefix/suffix check to the renamed urlRegex
(now gitUrlRegex
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what Andrew is saying by repeating code
is to do something along these lines instead:
function hasDomain(domain: string): boolean {
return url.includes(`http://${domain}/`) || url.includes(`@${domain}:`);
}
if (hasDomain('github.com')) {
return GitTypes.github;
}
if (hasDomain('bitbucket.org')) {
return GitTypes.bitbucket;
}
if (hasDomain('gitlab.com')) {
return GitTypes.gitlab;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct @christianvogt - I do wonder if there is something better we can do here, but that is definitely the bare min in my mind to make this acceptable. Saves on repeat and gives us a clean spot to expand the logic uniformly (if the future desires it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewballantyne, christianvogt, vikram-raj The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Bug fix - https://jira.coreos.com/browse/ODC-2303
Update the
detectGitType
function to parse the git url correctly. and update the unit test.