fix: remove GitHub hardcoding and generalize for non-GitHub git providers (#1216)
* fix: remove GitHub hardcoding and generalize for non-GitHub git providers * fix: guard SSH path extraction against missing colon separator --------- Co-authored-by: artac <artac@artacs-MacBook-Pro.local>
This commit is contained in:
committed by
GitHub
co-authored by
artac
parent
51c4ec693b
commit
f059bc8dd6
@@ -32,13 +32,17 @@ const generateCatalogId = () => `custom:${Date.now()}-${Math.random().toString(1
|
||||
|
||||
const guessLabelFromSource = (value: string) => {
|
||||
const trimmed = value.trim();
|
||||
const ssh = trimmed.match(/^git@github\.com:([^/\s]+)\/([^\s#]+)$/i);
|
||||
if (ssh) {
|
||||
return `${ssh[1]}/${ssh[2].replace(/\.git$/i, '')}`;
|
||||
const urlFormat = trimmed.startsWith("https://")
|
||||
? "https"
|
||||
: trimmed.startsWith("git@")
|
||||
? "ssh"
|
||||
: "shorthand";
|
||||
|
||||
if (urlFormat === 'ssh') {
|
||||
return `${trimmed.split(":")[1].replace(/\.git$/i, '')}`;
|
||||
}
|
||||
const https = trimmed.match(/^https?:\/\/github\.com\/([^/\s]+)\/([^\s#]+)$/i);
|
||||
if (https) {
|
||||
return `${https[1]}/${https[2].replace(/\.git$/i, '')}`;
|
||||
if (urlFormat === 'https') {
|
||||
return trimmed.split('/').slice(3).filter(Boolean).join('/').replace(/\.git$/i, '');
|
||||
}
|
||||
const shorthand = trimmed.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);
|
||||
if (shorthand) {
|
||||
|
||||
Reference in New Issue
Block a user