Skip to content

Commit bc4ea13

Browse files
alehechkapeterjgrainger
authored andcommitted
compare resp ref to generated ref
1 parent d1356e0 commit bc4ea13

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

dist/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5749,14 +5749,15 @@ function createBranch(getOctokit, context, branch, sha) {
57495749
const toolkit = getOctokit(githubToken());
57505750
// Sometimes branch might come in with refs/heads already
57515751
branch = branch.replace('refs/heads/', '');
5752+
const ref = `refs/heads/${branch}`;
57525753
// throws HttpError if branch already exists.
57535754
try {
57545755
yield toolkit.rest.repos.getBranch(Object.assign(Object.assign({}, context.repo), { branch }));
57555756
}
57565757
catch (error) {
57575758
if (error.name === 'HttpError' && error.status === 404) {
5758-
const resp = yield toolkit.rest.git.createRef(Object.assign({ ref: `refs/heads/${branch}`, sha: sha || context.sha }, context.repo));
5759-
return ((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.ref) === branch;
5759+
const resp = yield toolkit.rest.git.createRef(Object.assign({ ref, sha: sha || context.sha }, context.repo));
5760+
return ((_a = resp === null || resp === void 0 ? void 0 : resp.data) === null || _a === void 0 ? void 0 : _a.ref) === ref;
57605761
}
57615762
else {
57625763
throw Error(error);

src/create-branch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export async function createBranch(getOctokit: any, context: Context, branch: st
44
const toolkit = getOctokit(githubToken());
55
// Sometimes branch might come in with refs/heads already
66
branch = branch.replace('refs/heads/', '');
7+
const ref = `refs/heads/${branch}`;
78

89
// throws HttpError if branch already exists.
910
try {
@@ -14,12 +15,12 @@ export async function createBranch(getOctokit: any, context: Context, branch: st
1415
} catch (error: any) {
1516
if (error.name === 'HttpError' && error.status === 404) {
1617
const resp = await toolkit.rest.git.createRef({
17-
ref: `refs/heads/${branch}`,
18+
ref,
1819
sha: sha || context.sha,
1920
...context.repo,
2021
});
2122

22-
return resp?.data?.ref === branch;
23+
return resp?.data?.ref === ref;
2324
} else {
2425
throw Error(error);
2526
}

0 commit comments

Comments
 (0)