(url: string)
| 22 | } |
| 23 | |
| 24 | function parseGitHubUrl(url: string): { |
| 25 | owner: string; |
| 26 | repo: string; |
| 27 | branch: string; |
| 28 | path: string; |
| 29 | } | null { |
| 30 | try { |
| 31 | const urlObj = new URL(url); |
| 32 | const parts = urlObj.pathname.split("/").filter(Boolean); |
| 33 | |
| 34 | // Handle raw.githubusercontent.com URLs |
| 35 | // Format: https://raw.githubusercontent.com/owner/repo/refs/heads/branch/path/SKILL.md |
| 36 | if (urlObj.hostname === "raw.githubusercontent.com") { |
| 37 | if (parts.length < 5) return null; |
| 38 | |
| 39 | const owner = parts[0]; |
| 40 | const repo = parts[1]; |
| 41 | |
| 42 | // Handle refs/heads/branch format |
| 43 | if (parts[2] === "refs" && parts[3] === "heads") { |
| 44 | const branch = parts[4]; |
| 45 | // Get directory path (exclude the filename like SKILL.md) |
| 46 | const pathParts = parts.slice(5); |
| 47 | // Remove the last part if it looks like a file (has extension) |
| 48 | if (pathParts.length > 0 && pathParts[pathParts.length - 1].includes(".")) { |
| 49 | pathParts.pop(); |
| 50 | } |
| 51 | const path = pathParts.join("/"); |
| 52 | return { owner, repo, branch, path }; |
| 53 | } |
| 54 | |
| 55 | // Handle direct branch format: owner/repo/branch/path |
| 56 | const branch = parts[2]; |
| 57 | const pathParts = parts.slice(3); |
| 58 | if (pathParts.length > 0 && pathParts[pathParts.length - 1].includes(".")) { |
| 59 | pathParts.pop(); |
| 60 | } |
| 61 | const path = pathParts.join("/"); |
| 62 | return { owner, repo, branch, path }; |
| 63 | } |
| 64 | |
| 65 | // Handle github.com tree URLs |
| 66 | // Format: https://github.com/owner/repo/tree/branch/path |
| 67 | if (urlObj.hostname === "github.com") { |
| 68 | if (parts.length < 4 || parts[2] !== "tree") return null; |
| 69 | |
| 70 | const owner = parts[0]; |
| 71 | const repo = parts[1]; |
| 72 | const branch = parts[3]; |
| 73 | const path = parts.slice(4).join("/"); |
| 74 | |
| 75 | return { owner, repo, branch, path }; |
| 76 | } |
| 77 | |
| 78 | return null; |
| 79 | } catch { |
| 80 | return null; |
| 81 | } |
no outgoing calls
no test coverage detected