Skip to content

Commit

Permalink
getServerUrl refers to the GITHUB_SERVER_URL environment variable (#169)
Browse files Browse the repository at this point in the history
* getServerUrl refers to the GITHUB_SERVER_URL environment variable

* fix indent

* fix error

* eslint fix
  • Loading branch information
srz-zumix authored May 6, 2023
1 parent dab8151 commit ee5f49d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ async function capture(cmd: string, args: string[]): Promise<ExecResult> {
}
}

export function getServerUrlObj(repositoryUrl: string | undefined): URL {
const urlValue =
repositoryUrl && repositoryUrl.trim().length > 0
? repositoryUrl
: process.env['GITHUB_SERVER_URL'] ?? DEFAULT_GITHUB_URL;
return new URL(urlValue);
}

export function getServerUrl(repositoryUrl: string | undefined): string {
const urlObj = repositoryUrl ? new URL(repositoryUrl) : new URL(DEFAULT_GITHUB_URL);
return repositoryUrl ? urlObj.origin : DEFAULT_GITHUB_URL;
return getServerUrlObj(repositoryUrl).origin;
}

export function getServerName(repositoryUrl: string | undefined): string {
const urlObj = repositoryUrl ? new URL(repositoryUrl) : new URL(DEFAULT_GITHUB_URL);
return repositoryUrl ? urlObj.hostname : DEFAULT_GITHUB_URL.replace('https://', '');
return getServerUrlObj(repositoryUrl).hostname;
}

export async function cmd(additionalGitOptions: string[], ...args: string[]): Promise<string> {
Expand Down

0 comments on commit ee5f49d

Please sign in to comment.