(input: string)
| 130 | * Also accepts plain "owner/repo" strings for backward compatibility. |
| 131 | */ |
| 132 | export function parseGitHubRepository(input: string): string | null { |
| 133 | const trimmed = input.trim() |
| 134 | |
| 135 | // Try parsing as a full remote URL first. |
| 136 | // Only return results for github.com hosts — existing callers (VS Code extension, |
| 137 | // bridge) assume this function is GitHub.com-specific. Use parseGitRemote() directly |
| 138 | // for GHE support. |
| 139 | const parsed = parseGitRemote(trimmed) |
| 140 | if (parsed) { |
| 141 | if (parsed.host !== 'github.com') return null |
| 142 | return `${parsed.owner}/${parsed.name}` |
| 143 | } |
| 144 | |
| 145 | // If no URL pattern matched, check if it's already in owner/repo format |
| 146 | if ( |
| 147 | !trimmed.includes('://') && |
| 148 | !trimmed.includes('@') && |
| 149 | trimmed.includes('/') |
| 150 | ) { |
| 151 | const parts = trimmed.split('/') |
| 152 | if (parts.length === 2 && parts[0] && parts[1]) { |
| 153 | // Remove .git extension if present |
| 154 | const repo = parts[1].replace(/\.git$/, '') |
| 155 | return `${parts[0]}/${repo}` |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | logForDebugging(`Could not parse repository from: ${trimmed}`) |
| 160 | return null |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Checks whether a hostname looks like a real domain name rather than an |
no test coverage detected