From ff7e3fe3cb2ce0beeaacf02b23fe730b80f591da Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Tue, 22 Nov 2022 11:09:37 +0900 Subject: [PATCH] fix: code formatting --- dist/index.js | 15 +++++++++------ src/utils.ts | 11 ++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index 81ec939..aff221f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -339,7 +339,7 @@ function createPullRequest(inputs) { throw new Error(`Repository '${branchRepository}' is not a fork of '${baseRemote.repository}'. Unable to continue.`); } // Add a remote for the fork - const remoteUrl = utils.getRemoteUrl(baseRemote.protocol, branchRepository); + const remoteUrl = utils.getRemoteUrl(baseRemote.protocol, baseRemote.hostname, branchRepository); yield git.exec(['remote', 'add', 'fork', remoteUrl]); } core.endGroup(); @@ -1247,11 +1247,13 @@ function getRemoteDetail(remoteUrl) { if (!githubServerMatch) { throw new Error('Could not parse GitHub Server name'); } - const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(\\.git)?$', 'i'); - const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+)\\.git$', 'i'); + const hostname = githubServerMatch[1]; + const httpsUrlPattern = new RegExp('^https?://.*@?' + hostname + '/(.+/.+?)(\\.git)?$', 'i'); + const sshUrlPattern = new RegExp('^git@' + hostname + ':(.+/.+)\\.git$', 'i'); const httpsMatch = remoteUrl.match(httpsUrlPattern); if (httpsMatch) { return { + hostname, protocol: 'HTTPS', repository: httpsMatch[1] }; @@ -1259,6 +1261,7 @@ function getRemoteDetail(remoteUrl) { const sshMatch = remoteUrl.match(sshUrlPattern); if (sshMatch) { return { + hostname, protocol: 'SSH', repository: sshMatch[1] }; @@ -1266,10 +1269,10 @@ function getRemoteDetail(remoteUrl) { throw new Error(`The format of '${remoteUrl}' is not a valid GitHub repository URL`); } exports.getRemoteDetail = getRemoteDetail; -function getRemoteUrl(protocol, repository) { +function getRemoteUrl(protocol, hostname, repository) { return protocol == 'HTTPS' - ? `https://github.com/${repository}` - : `git@github.com:${repository}.git`; + ? `https://${hostname}/${repository}` + : `git@${hostname}:${repository}.git`; } exports.getRemoteUrl = getRemoteUrl; function secondsSinceEpoch() { diff --git a/src/utils.ts b/src/utils.ts index 7a83a03..b98f8fa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -53,10 +53,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail { '^https?://.*@?' + hostname + '/(.+/.+?)(\\.git)?$', 'i' ) - const sshUrlPattern = new RegExp( - '^git@' + hostname + ':(.+/.+)\\.git$', - 'i' - ) + const sshUrlPattern = new RegExp('^git@' + hostname + ':(.+/.+)\\.git$', 'i') const httpsMatch = remoteUrl.match(httpsUrlPattern) if (httpsMatch) { @@ -81,7 +78,11 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail { ) } -export function getRemoteUrl(protocol: string, hostname: string, repository: string): string { +export function getRemoteUrl( + protocol: string, + hostname: string, + repository: string +): string { return protocol == 'HTTPS' ? `https://${hostname}/${repository}` : `git@${hostname}:${repository}.git`