From bc4ea1382f474cbbc88c6065e96b6bd137b2cd13 Mon Sep 17 00:00:00 2001 From: Adam Lehechka <42357034+alehechka@users.noreply.github.com> Date: Sun, 20 Feb 2022 11:28:34 -0600 Subject: [PATCH] compare resp ref to generated ref --- dist/index.js | 5 +++-- src/create-branch.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 28a67b4..6bfac2d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5749,14 +5749,15 @@ function createBranch(getOctokit, context, branch, sha) { const toolkit = getOctokit(githubToken()); // Sometimes branch might come in with refs/heads already branch = branch.replace('refs/heads/', ''); + const ref = `refs/heads/${branch}`; // throws HttpError if branch already exists. try { yield toolkit.rest.repos.getBranch(Object.assign(Object.assign({}, context.repo), { branch })); } catch (error) { if (error.name === 'HttpError' && error.status === 404) { - const resp = yield toolkit.rest.git.createRef(Object.assign({ ref: `refs/heads/${branch}`, sha: sha || context.sha }, context.repo)); - return ((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.ref) === branch; + const resp = yield toolkit.rest.git.createRef(Object.assign({ ref, sha: sha || context.sha }, context.repo)); + return ((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.ref) === ref; } else { throw Error(error); diff --git a/src/create-branch.ts b/src/create-branch.ts index 1fb42b9..cf65981 100644 --- a/src/create-branch.ts +++ b/src/create-branch.ts @@ -4,6 +4,7 @@ export async function createBranch(getOctokit: any, context: Context, branch: st const toolkit = getOctokit(githubToken()); // Sometimes branch might come in with refs/heads already branch = branch.replace('refs/heads/', ''); + const ref = `refs/heads/${branch}`; // throws HttpError if branch already exists. try { @@ -14,12 +15,12 @@ export async function createBranch(getOctokit: any, context: Context, branch: st } catch (error: any) { if (error.name === 'HttpError' && error.status === 404) { const resp = await toolkit.rest.git.createRef({ - ref: `refs/heads/${branch}`, + ref, sha: sha || context.sha, ...context.repo, }); - return resp?.data?.ref === branch; + return resp?.data?.ref === ref; } else { throw Error(error); }