Skip to content

Commit 2d7815f

Browse files
author
Tristan payne
committed
fix: move replace logic up further
1 parent 05a8934 commit 2d7815f

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

dist/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8383,17 +8383,15 @@ function createBranch(github, context, branch) {
83838383
return __awaiter(this, void 0, void 0, function* () {
83848384
const toolkit = new github(githubToken());
83858385
let branchExists;
8386+
// Sometimes branch might come in with refs/heads already
8387+
branch = branch.replace('refs/heads/', '');
83868388
// throws HttpError if branch already exists.
83878389
try {
83888390
yield toolkit.repos.getBranch(Object.assign({}, context.repo, { branch }));
83898391
branchExists = true;
83908392
}
83918393
catch (error) {
83928394
if (error.name === 'HttpError' && error.status === 404) {
8393-
// Sometimes branch might come in with refs/heads already
8394-
console.log(`Incoming Branch: ${branch}`);
8395-
branch = branch.replace('refs/heads/', '');
8396-
console.log(`Replaced branch: ${branch}`);
83978395
yield toolkit.git.createRef(Object.assign({ ref: `refs/heads/${branch}`, sha: context.sha }, context.repo));
83988396
}
83998397
else {

src/create-branch.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { GitHub } from "@actions/github";
44
export async function createBranch(github: any, context: Context, branch: string) {
55
const toolkit : GitHub = new github(githubToken());
66
let branchExists;
7+
// Sometimes branch might come in with refs/heads already
8+
branch = branch.replace('refs/heads/', '');
9+
710
// throws HttpError if branch already exists.
811
try {
912
await toolkit.repos.getBranch({
@@ -14,10 +17,6 @@ export async function createBranch(github: any, context: Context, branch: string
1417
branchExists = true;
1518
} catch(error) {
1619
if(error.name === 'HttpError' && error.status === 404) {
17-
// Sometimes branch might come in with refs/heads already
18-
console.log(`Incoming Branch: ${branch}`);
19-
branch = branch.replace('refs/heads/', '');
20-
console.log(`Replaced branch: ${branch}`);
2120
await toolkit.git.createRef({
2221
ref: `refs/heads/${branch}`,
2322
sha: context.sha,

0 commit comments

Comments
 (0)