From 15b68d176daae473d63f8e6dc64a3eb891e4239a Mon Sep 17 00:00:00 2001 From: Scott Alexander Date: Thu, 31 Mar 2022 01:10:39 -0700 Subject: [PATCH] fix: strip optional '.git' suffix from https server remote name. (#1153) * Strip optional '.git' suffix from https server remote name. * Revert "Strip optional '.git' suffix from https server remote name." This reverts commit c2e9041213985796111bd85229e2375f407c2752. * Strip optional '.git' suffix from https server remote name. --- __test__/utils.unit.test.ts | 6 +++ dist/index.js | 90 ++++++++++++++++++++++++++----------- src/utils.ts | 2 +- 3 files changed, 70 insertions(+), 28 deletions(-) diff --git a/__test__/utils.unit.test.ts b/__test__/utils.unit.test.ts index 3da2439add..64e2d02e41 100644 --- a/__test__/utils.unit.test.ts +++ b/__test__/utils.unit.test.ts @@ -50,6 +50,12 @@ describe('utils tests', () => { ) expect(remote3.protocol).toEqual('SSH') expect(remote3.repository).toEqual('peter-evans/create-pull-request') + + const remote4 = utils.getRemoteDetail( + 'https://github.com/peter-evans/create-pull-request.git' + ) + expect(remote4.protocol).toEqual('HTTPS') + expect(remote4.repository).toEqual('peter-evans/create-pull-request') }) test('getRemoteDetail fails to parse a remote URL', async () => { diff --git a/dist/index.js b/dist/index.js index 790a920ee6..8179616b09 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8,7 +8,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -246,7 +250,11 @@ exports.createOrUpdateBranch = createOrUpdateBranch; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -466,7 +474,11 @@ exports.createPullRequest = createPullRequest; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -599,7 +611,11 @@ exports.GitAuthHelper = GitAuthHelper; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -903,7 +919,11 @@ class GitOutput { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -1054,7 +1074,11 @@ exports.GitHubHelper = GitHubHelper; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -1156,7 +1180,11 @@ function autoProxyAgent(octokit) { var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; @@ -1211,7 +1239,7 @@ function getRemoteDetail(remoteUrl) { if (!githubServerMatch) { throw new Error('Could not parse GitHub Server name'); } - const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', 'i'); + const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$', 'i'); const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+).git$', 'i'); const httpsMatch = remoteUrl.match(httpsUrlPattern); if (httpsMatch) { @@ -3839,8 +3867,14 @@ function copyFile(srcFile, destFile, force) { Object.defineProperty(exports, "__esModule", ({ value: true })); +const REGEX_IS_INSTALLATION_LEGACY = /^v1\./; +const REGEX_IS_INSTALLATION = /^ghs_/; +const REGEX_IS_USER_TO_SERVER = /^ghu_/; async function auth(token) { - const tokenType = token.split(/\./).length === 3 ? "app" : /^v\d+\./.test(token) ? "installation" : "oauth"; + const isApp = token.split(/\./).length === 3; + const isInstallation = REGEX_IS_INSTALLATION_LEGACY.test(token) || REGEX_IS_INSTALLATION.test(token); + const isUserToServer = REGEX_IS_USER_TO_SERVER.test(token); + const tokenType = isApp ? "app" : isInstallation ? "installation" : isUserToServer ? "user-to-server" : "oauth"; return { type: "token", token: token, @@ -3938,7 +3972,7 @@ function _objectWithoutProperties(source, excluded) { return target; } -const VERSION = "3.5.1"; +const VERSION = "3.6.0"; const _excluded = ["authStrategy"]; class Octokit { @@ -4481,18 +4515,22 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); var request = __nccwpck_require__(6234); var universalUserAgent = __nccwpck_require__(5030); -const VERSION = "4.6.4"; +const VERSION = "4.8.0"; -class GraphqlError extends Error { - constructor(request, response) { - const message = response.data.errors[0].message; - super(message); - Object.assign(this, response.data); - Object.assign(this, { - headers: response.headers - }); - this.name = "GraphqlError"; - this.request = request; // Maintains proper stack trace (only available on V8) +function _buildMessageForResponseErrors(data) { + return `Request failed due to following response errors:\n` + data.errors.map(e => ` - ${e.message}`).join("\n"); +} + +class GraphqlResponseError extends Error { + constructor(request, headers, response) { + super(_buildMessageForResponseErrors(response)); + this.request = request; + this.headers = headers; + this.response = response; + this.name = "GraphqlResponseError"; // Expose the errors and response data in their shorthand properties. + + this.errors = response.errors; + this.data = response.data; // Maintains proper stack trace (only available on V8) /* istanbul ignore next */ @@ -4550,10 +4588,7 @@ function graphql(request, query, options) { headers[key] = response.headers[key]; } - throw new GraphqlError(requestOptions, { - headers, - data: response.data - }); + throw new GraphqlResponseError(requestOptions, headers, response.data); } return response.data.data; @@ -4587,6 +4622,7 @@ function withCustomRequest(customRequest) { }); } +exports.GraphqlResponseError = GraphqlResponseError; exports.graphql = graphql$1; exports.withCustomRequest = withCustomRequest; //# sourceMappingURL=index.js.map @@ -5950,7 +5986,7 @@ var isPlainObject = __nccwpck_require__(3287); var nodeFetch = _interopDefault(__nccwpck_require__(467)); var requestError = __nccwpck_require__(537); -const VERSION = "5.6.0"; +const VERSION = "5.6.3"; function getBufferResponse(response) { return response.arrayBuffer(); @@ -6991,7 +7027,7 @@ function setup(env) { namespaces = split[i].replace(/\*/g, '.*?'); if (namespaces[0] === '-') { - createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$')); } else { createDebug.names.push(new RegExp('^' + namespaces + '$')); } diff --git a/src/utils.ts b/src/utils.ts index a491d91556..464695063b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -47,7 +47,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail { } const httpsUrlPattern = new RegExp( - '^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', + '^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$', 'i' ) const sshUrlPattern = new RegExp(