From 1c466bedd538f4d6872cb4a8a9ef3b66056dc429 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Wed, 19 Aug 2020 12:06:41 +0900 Subject: [PATCH] Fix branch naming check for push-to-fork --- dist/index.js | 12 +++++++----- src/create-pull-request.ts | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 729ad11..f528857 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7656,11 +7656,13 @@ function createPullRequest(inputs) { throw new Error('The checked out ref is not a valid base for a pull request. Unable to continue.'); } const workingBase = symbolicRefResult.stdout.trim(); - // Exit if the working base is a PR branch created by this action. - // This may occur when using a PAT instead of GITHUB_TOKEN because - // a PAT allows workflow actions to trigger further events. - if (workingBase.startsWith(inputs.branch)) { - throw new Error(`Working base branch '${workingBase}' was created by this action. Unable to continue.`); + // If the base is not specified it is assumed to be the working base. + const base = inputs.base ? inputs.base : workingBase; + // Throw an error if the base and branch are not different branches + // of the 'origin' remote. An identically named branch in the `fork` + // remote is perfectly fine. + if (branchRemoteName == 'origin' && base == inputs.branch) { + throw new Error(`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`); } core.endGroup(); // Apply the branch suffix if set diff --git a/src/create-pull-request.ts b/src/create-pull-request.ts index 23e00c6..e554293 100644 --- a/src/create-pull-request.ts +++ b/src/create-pull-request.ts @@ -99,12 +99,14 @@ export async function createPullRequest(inputs: Inputs): Promise { ) } const workingBase = symbolicRefResult.stdout.trim() - // Exit if the working base is a PR branch created by this action. - // This may occur when using a PAT instead of GITHUB_TOKEN because - // a PAT allows workflow actions to trigger further events. - if (workingBase.startsWith(inputs.branch)) { + // If the base is not specified it is assumed to be the working base. + const base = inputs.base ? inputs.base : workingBase + // Throw an error if the base and branch are not different branches + // of the 'origin' remote. An identically named branch in the `fork` + // remote is perfectly fine. + if (branchRemoteName == 'origin' && base == inputs.branch) { throw new Error( - `Working base branch '${workingBase}' was created by this action. Unable to continue.` + `The 'base' and 'branch' for a pull request must be different branches. Unable to continue.` ) } core.endGroup()