From 02a8f71e34146f88dd40b7a4a664a895ee1bbfe8 Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:20:05 +0000 Subject: [PATCH] fix: remove the remote for the fork on completion --- dist/index.js | 7 +++++-- src/create-pull-request.ts | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7efc7df..d9ec1c9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -320,7 +320,7 @@ const git_auth_helper_1 = __nccwpck_require__(2565); const utils = __importStar(__nccwpck_require__(918)); function createPullRequest(inputs) { return __awaiter(this, void 0, void 0, function* () { - let gitAuthHelper; + let gitAuthHelper, git; try { if (!inputs.token) { throw new Error(`Input 'token' not supplied. Unable to continue.`); @@ -343,7 +343,7 @@ function createPullRequest(inputs) { // Get the repository path const repoPath = utils.getRepoPath(inputs.path); // Create a git command manager - const git = yield git_command_manager_1.GitCommandManager.create(repoPath); + git = yield git_command_manager_1.GitCommandManager.create(repoPath); // Save and unset the extraheader auth config if it exists core.startGroup('Prepare git configuration'); gitAuthHelper = new git_auth_helper_1.GitAuthHelper(git); @@ -511,6 +511,9 @@ function createPullRequest(inputs) { finally { // Remove auth and restore persisted auth config if it existed core.startGroup('Restore git configuration'); + if (inputs.pushToFork) { + yield git.exec(['remote', 'rm', 'fork']); + } yield gitAuthHelper.removeAuth(); yield gitAuthHelper.restorePersistedAuth(); yield gitAuthHelper.removeSafeDirectory(); diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 1e7b8ba..43e45c2 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -35,7 +35,7 @@ export interface Inputs { } export async function createPullRequest(inputs: Inputs): Promise { - let gitAuthHelper + let gitAuthHelper, git try { if (!inputs.token) { throw new Error(`Input 'token' not supplied. Unable to continue.`) @@ -61,7 +61,7 @@ export async function createPullRequest(inputs: Inputs): Promise { // Get the repository path const repoPath = utils.getRepoPath(inputs.path) // Create a git command manager - const git = await GitCommandManager.create(repoPath) + git = await GitCommandManager.create(repoPath) // Save and unset the extraheader auth config if it exists core.startGroup('Prepare git configuration') @@ -283,6 +283,9 @@ export async function createPullRequest(inputs: Inputs): Promise { } finally { // Remove auth and restore persisted auth config if it existed core.startGroup('Restore git configuration') + if (inputs.pushToFork) { + await git.exec(['remote', 'rm', 'fork']) + } await gitAuthHelper.removeAuth() await gitAuthHelper.restorePersistedAuth() await gitAuthHelper.removeSafeDirectory()