()
| 97 | * @throws error if the exec command fails. |
| 98 | */ |
| 99 | export function getGitHubRepoInfo(): { owner: string; repo: string } { |
| 100 | const remoteUrl = execSync('git remote get-url origin', { |
| 101 | encoding: 'utf-8', |
| 102 | }).trim(); |
| 103 | |
| 104 | // Matches either https://github.com/owner/repo.git or git@github.com:owner/repo.git |
| 105 | const match = remoteUrl.match( |
| 106 | /(?:https?:\/\/|git@)github\.com(?::|\/)([^/]+)\/([^/]+?)(?:\.git)?$/, |
| 107 | ); |
| 108 | |
| 109 | // If the regex fails match, throw an error. |
| 110 | if (!match || !match[1] || !match[2]) { |
| 111 | throw new Error( |
| 112 | `Owner & repo could not be extracted from remote URL: ${remoteUrl}`, |
| 113 | ); |
| 114 | } |
| 115 | |
| 116 | return { owner: match[1], repo: match[2] }; |
| 117 | } |
no outgoing calls
no test coverage detected