Skip to content

Commit 367c1c4

Browse files
authored
Merge pull request #7 from matlab-actions/ssh
Add support for more repository address formats
2 parents 32c7e78 + 7c78452 commit 367c1c4

File tree

2 files changed

+308
-76
lines changed

2 files changed

+308
-76
lines changed

public/scripts/workflow.js

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,86 @@
11
function parseRepositoryURL(repoURL) {
2-
if (repoURL.startsWith("git@") || repoURL.startsWith("ssh://")) {
2+
repoURL = repoURL.trim().replace(/\.git$/i, "");
3+
4+
// SSH and git protocol (e.g., [email protected]:owner/repo or git://host/owner/repo)
5+
const m = repoURL.match(
6+
/^(git@|ssh:\/\/git@|git:\/\/)([^:/]+)[:/]((?:[^/]+\/)+[^/]+)$/i,
7+
);
8+
if (m) {
9+
const host = m[2];
10+
const parts = m[3].split("/").filter(Boolean);
11+
// GitHub Enterprise SSH URL: git@github.com:enterprises/enterprise/owner/repo
12+
if (
13+
host.toLowerCase() === "github.com" &&
14+
parts[0] === "enterprises" &&
15+
parts.length >= 4
16+
) {
17+
return {
18+
origin: `https://github.com`,
19+
enterprise: parts[1],
20+
owner: parts[2],
21+
repo: parts[3],
22+
};
23+
} else if (parts.length === 2) {
24+
// Standard SSH URL: git@host:owner/repo
25+
return {
26+
origin: `https://${host}`,
27+
owner: parts[0],
28+
repo: parts[1],
29+
};
30+
}
31+
// Unrecognized SSH format
332
return null;
433
}
5-
if (repoURL.endsWith(".git")) {
6-
repoURL = repoURL.slice(0, -4);
34+
35+
// Shorthand and domain/owner/repo (e.g., owner/repo or host/owner/repo)
36+
if (!/^\w+:\/\//.test(repoURL)) {
37+
const parts = repoURL.split("/").filter(Boolean);
38+
if (parts.length === 2) {
39+
// owner/repo shorthand (assume github.com)
40+
return {
41+
origin: "https://github.com",
42+
owner: parts[0],
43+
repo: parts[1],
44+
};
45+
} else if (parts.length >= 3 && parts[0].includes(".")) {
46+
// treat as URL, fall through to URL parsing
47+
repoURL = "https://" + repoURL;
48+
} else {
49+
// Unrecognized shorthand
50+
return null;
51+
}
752
}
53+
54+
// HTTP(S) URLs (e.g., https://github.com/owner/repo)
855
try {
956
const url = new URL(repoURL);
10-
let parts = url.pathname.split("/").filter(Boolean);
57+
const parts = url.pathname.split("/").filter(Boolean);
58+
// GitHub Enterprise HTTP URL: https://github.com/enterprises/enterprise/owner/repo
1159
if (
12-
url.host === "github.com" &&
60+
url.host.toLowerCase() === "github.com" &&
1361
parts[0] === "enterprises" &&
1462
parts.length >= 4
1563
) {
16-
// https://github.com/enterprises/{enterprise_slug}/{owner}/{repo}
1764
return {
1865
origin: url.origin,
1966
enterprise: parts[1],
2067
owner: parts[2],
2168
repo: parts[3],
2269
};
2370
} else if (parts.length >= 2) {
24-
// https://github.com/{owner}/{repo}
71+
// Standard HTTP(S) URL: https://host/owner/repo
2572
return {
2673
origin: url.origin,
2774
owner: parts[0],
2875
repo: parts[1],
2976
};
3077
}
31-
return null;
3278
} catch {
33-
// {owner}/{repo}
34-
const parts = repoURL.split("/").filter(Boolean);
35-
return parts.length === 2
36-
? { owner: parts[0], repo: parts[1], origin: "https://github.com" }
37-
: null;
79+
// Not a valid URL, fall through
3880
}
81+
82+
// If none of the above matched, return null
83+
return null;
3984
}
4085

4186
function generateWorkflow({

0 commit comments

Comments
 (0)