()
| 30 | * GitHub host should use this variant. |
| 31 | */ |
| 32 | export async function detectCurrentRepositoryWithHost(): Promise<ParsedRepository | null> { |
| 33 | const cwd = getCwd() |
| 34 | |
| 35 | if (repositoryWithHostCache.has(cwd)) { |
| 36 | return repositoryWithHostCache.get(cwd) ?? null |
| 37 | } |
| 38 | |
| 39 | try { |
| 40 | const remoteUrl = await getRemoteUrl() |
| 41 | logForDebugging(`Git remote URL: ${remoteUrl}`) |
| 42 | if (!remoteUrl) { |
| 43 | logForDebugging('No git remote URL found') |
| 44 | repositoryWithHostCache.set(cwd, null) |
| 45 | return null |
| 46 | } |
| 47 | |
| 48 | const parsed = parseGitRemote(remoteUrl) |
| 49 | logForDebugging( |
| 50 | `Parsed repository: ${parsed ? `${parsed.host}/${parsed.owner}/${parsed.name}` : null} from URL: ${remoteUrl}`, |
| 51 | ) |
| 52 | repositoryWithHostCache.set(cwd, parsed) |
| 53 | return parsed |
| 54 | } catch (error) { |
| 55 | logForDebugging(`Error detecting repository: ${error}`) |
| 56 | repositoryWithHostCache.set(cwd, null) |
| 57 | return null |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Synchronously returns the cached github.com repository for the current cwd |
no test coverage detected