From a75f34b1e446da4fc2a47bf751806165f2689ffa Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Fri, 8 Apr 2022 17:46:12 +0900 Subject: [PATCH] fix: use full name for head branch to allow for repo renaming --- dist/index.js | 11 ++++++----- src/github-helper.ts | 17 +++++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index 67a12f654..818bfdb94 100644 --- a/dist/index.js +++ b/dist/index.js @@ -950,8 +950,11 @@ class GitHubHelper { repo: repo }; } - createOrUpdate(inputs, baseRepository, headBranch) { + createOrUpdate(inputs, baseRepository, headRepository) { return __awaiter(this, void 0, void 0, function* () { + const [headOwner] = headRepository.split('/'); + const headBranch = `${headOwner}:${inputs.branch}`; + const headBranchFull = `${headRepository}:${inputs.branch}`; // Try to create the pull request try { core.info(`Attempting creation of pull request`); @@ -974,7 +977,7 @@ class GitHubHelper { } // Update the pull request that exists for this branch and base core.info(`Fetching existing pull request`); - const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base })); + const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranchFull, base: inputs.base })); core.info(`Attempting update of pull request`); const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number, title: inputs.title, body: inputs.body })); core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`); @@ -996,10 +999,8 @@ class GitHubHelper { } createOrUpdatePullRequest(inputs, baseRepository, headRepository) { return __awaiter(this, void 0, void 0, function* () { - const [headOwner] = headRepository.split('/'); - const headBranch = `${headOwner}:${inputs.branch}`; // Create or update the pull request - const pull = yield this.createOrUpdate(inputs, baseRepository, headBranch); + const pull = yield this.createOrUpdate(inputs, baseRepository, headRepository); // Apply milestone if (inputs.milestone) { core.info(`Applying milestone '${inputs.milestone}'`); diff --git a/src/github-helper.ts b/src/github-helper.ts index 35db3e879..2d451c963 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -39,8 +39,12 @@ export class GitHubHelper { private async createOrUpdate( inputs: Inputs, baseRepository: string, - headBranch: string + headRepository: string ): Promise { + const [headOwner] = headRepository.split('/') + const headBranch = `${headOwner}:${inputs.branch}` + const headBranchFull = `${headRepository}:${inputs.branch}` + // Try to create the pull request try { core.info(`Attempting creation of pull request`) @@ -76,7 +80,7 @@ export class GitHubHelper { const {data: pulls} = await this.octokit.rest.pulls.list({ ...this.parseRepository(baseRepository), state: 'open', - head: headBranch, + head: headBranchFull, base: inputs.base }) core.info(`Attempting update of pull request`) @@ -113,11 +117,12 @@ export class GitHubHelper { baseRepository: string, headRepository: string ): Promise { - const [headOwner] = headRepository.split('/') - const headBranch = `${headOwner}:${inputs.branch}` - // Create or update the pull request - const pull = await this.createOrUpdate(inputs, baseRepository, headBranch) + const pull = await this.createOrUpdate( + inputs, + baseRepository, + headRepository + ) // Apply milestone if (inputs.milestone) {