|
1 | 1 | 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 |
3 | 32 | return null;
|
4 | 33 | }
|
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 | + } |
7 | 52 | }
|
| 53 | + |
| 54 | + // HTTP(S) URLs (e.g., https://github.com/owner/repo) |
8 | 55 | try {
|
9 | 56 | 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 |
11 | 59 | if (
|
12 |
| - url.host === "github.com" && |
| 60 | + url.host.toLowerCase() === "github.com" && |
13 | 61 | parts[0] === "enterprises" &&
|
14 | 62 | parts.length >= 4
|
15 | 63 | ) {
|
16 |
| - // https://github.com/enterprises/{enterprise_slug}/{owner}/{repo} |
17 | 64 | return {
|
18 | 65 | origin: url.origin,
|
19 | 66 | enterprise: parts[1],
|
20 | 67 | owner: parts[2],
|
21 | 68 | repo: parts[3],
|
22 | 69 | };
|
23 | 70 | } else if (parts.length >= 2) {
|
24 |
| - // https://github.com/{owner}/{repo} |
| 71 | + // Standard HTTP(S) URL: https://host/owner/repo |
25 | 72 | return {
|
26 | 73 | origin: url.origin,
|
27 | 74 | owner: parts[0],
|
28 | 75 | repo: parts[1],
|
29 | 76 | };
|
30 | 77 | }
|
31 |
| - return null; |
32 | 78 | } 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 |
38 | 80 | }
|
| 81 | + |
| 82 | + // If none of the above matched, return null |
| 83 | + return null; |
39 | 84 | }
|
40 | 85 |
|
41 | 86 | function generateWorkflow({
|
|
0 commit comments