diff options
| author | Lee James <[email protected]> | 2025-08-07 12:00:46 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-07 16:00:46 +0000 |
| commit | 8d848dca4a52d169b3dfea2f66e7e5f69ee5e45c (patch) | |
| tree | bbb82f3a1e8024e6c116c1ca3b5a5313fa31ab02 /packages/cli/src/utils/gitUtils.ts | |
| parent | 6ae75c9f32a968efa50857a8f24b958a58a84fd6 (diff) | |
feat: open repo secrets page in addition to README (#5684)
Diffstat (limited to 'packages/cli/src/utils/gitUtils.ts')
| -rw-r--r-- | packages/cli/src/utils/gitUtils.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/cli/src/utils/gitUtils.ts b/packages/cli/src/utils/gitUtils.ts index 30ca2245..f5f9cb92 100644 --- a/packages/cli/src/utils/gitUtils.ts +++ b/packages/cli/src/utils/gitUtils.ts @@ -91,3 +91,28 @@ export const getLatestGitHubRelease = async ( ); } }; + +/** + * getGitHubRepoInfo returns the owner and repository for a GitHub repo. + * @returns the owner and repository of the github repo. + * @throws error if the exec command fails. + */ +export function getGitHubRepoInfo(): { owner: string; repo: string } { + const remoteUrl = execSync('git remote get-url origin', { + encoding: 'utf-8', + }).trim(); + + // Matches either https://github.com/owner/repo.git or [email protected]:owner/repo.git + const match = remoteUrl.match( + /(?:https?:\/\/|git@)github\.com(?::|\/)([^/]+)\/([^/]+?)(?:\.git)?$/, + ); + + // If the regex fails match, throw an error. + if (!match || !match[1] || !match[2]) { + throw new Error( + `Owner & repo could not be extracted from remote URL: ${remoteUrl}`, + ); + } + + return { owner: match[1], repo: match[2] }; +} |
