Skip to content

Commit

Permalink
compare resp ref to generated ref
Browse files Browse the repository at this point in the history
  • Loading branch information
alehechka authored and peterjgrainger committed Mar 16, 2022
1 parent d1356e0 commit bc4ea13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/create-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down

0 comments on commit bc4ea13

Please sign in to comment.