diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index b5c59d812..1e42c1f5a 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -74,6 +74,7 @@ export async function createPullRequest(inputs: Inputs): Promise { // Add a remote for the fork const remoteUrl = utils.getRemoteUrl( baseRemote.protocol, + baseRemote.hostname, branchRepository ) await git.exec(['remote', 'add', 'fork', remoteUrl]) diff --git a/src/utils.ts b/src/utils.ts index 433c0beb2..7a83a033f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -32,6 +32,7 @@ export function getRepoPath(relativePath?: string): string { } interface RemoteDetail { + hostname: string protocol: string repository: string } @@ -46,18 +47,21 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail { throw new Error('Could not parse GitHub Server name') } + const hostname = githubServerMatch[1] + const httpsUrlPattern = new RegExp( - '^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(\\.git)?$', + '^https?://.*@?' + hostname + '/(.+/.+?)(\\.git)?$', 'i' ) const sshUrlPattern = new RegExp( - '^git@' + githubServerMatch[1] + ':(.+/.+)\\.git$', + '^git@' + hostname + ':(.+/.+)\\.git$', 'i' ) const httpsMatch = remoteUrl.match(httpsUrlPattern) if (httpsMatch) { return { + hostname, protocol: 'HTTPS', repository: httpsMatch[1] } @@ -66,6 +70,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail { const sshMatch = remoteUrl.match(sshUrlPattern) if (sshMatch) { return { + hostname, protocol: 'SSH', repository: sshMatch[1] } @@ -76,10 +81,10 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail { ) } -export function getRemoteUrl(protocol: string, repository: string): string { +export function getRemoteUrl(protocol: string, hostname: string, repository: string): string { return protocol == 'HTTPS' - ? `https://github.com/${repository}` - : `git@github.com:${repository}.git` + ? `https://${hostname}/${repository}` + : `git@${hostname}:${repository}.git` } export function secondsSinceEpoch(): number {