Skip to content

Commit 1e7a168

Browse files
alehechkapeterjgrainger
authored andcommitted
change tabs back to spaces
1 parent bc4ea13 commit 1e7a168

File tree

3 files changed

+34
-50
lines changed

3 files changed

+34
-50
lines changed

.github/workflows/test-run.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/create-branch.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
import { Context } from '@actions/github/lib/context';
22

33
export async function createBranch(getOctokit: any, context: Context, branch: string, sha?: string) {
4-
const toolkit = getOctokit(githubToken());
5-
// Sometimes branch might come in with refs/heads already
6-
branch = branch.replace('refs/heads/', '');
7-
const ref = `refs/heads/${branch}`;
4+
const toolkit = getOctokit(githubToken());
5+
// Sometimes branch might come in with refs/heads already
6+
branch = branch.replace('refs/heads/', '');
7+
const ref = `refs/heads/${branch}`;
88

9-
// throws HttpError if branch already exists.
10-
try {
11-
await toolkit.rest.repos.getBranch({
12-
...context.repo,
13-
branch,
14-
});
15-
} catch (error: any) {
16-
if (error.name === 'HttpError' && error.status === 404) {
17-
const resp = await toolkit.rest.git.createRef({
18-
ref,
19-
sha: sha || context.sha,
20-
...context.repo,
21-
});
9+
// throws HttpError if branch already exists.
10+
try {
11+
await toolkit.rest.repos.getBranch({
12+
...context.repo,
13+
branch,
14+
});
15+
} catch (error: any) {
16+
if (error.name === 'HttpError' && error.status === 404) {
17+
const resp = await toolkit.rest.git.createRef({
18+
ref,
19+
sha: sha || context.sha,
20+
...context.repo,
21+
});
2222

23-
return resp?.data?.ref === ref;
24-
} else {
25-
throw Error(error);
26-
}
27-
}
23+
return resp?.data?.ref === ref;
24+
} else {
25+
throw Error(error);
26+
}
27+
}
2828
}
2929

3030
function githubToken(): string {
31-
const token = process.env.GITHUB_TOKEN;
32-
if (!token) throw ReferenceError('No token defined in the environment variables');
33-
return token;
31+
const token = process.env.GITHUB_TOKEN;
32+
if (!token) throw ReferenceError('No token defined in the environment variables');
33+
return token;
3434
}

src/main.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { getOctokit, context } from '@actions/github';
33
import { createBranch } from './create-branch';
44

55
async function run() {
6-
try {
7-
const branch = core.getInput('branch');
8-
const sha = core.getInput('sha');
9-
core.debug(`Creating branch ${branch}`);
10-
const isCreated = await createBranch(getOctokit, context, branch, sha);
11-
core.setOutput('created', Boolean(isCreated));
12-
} catch (error: any) {
13-
core.setFailed(error.message);
14-
}
6+
try {
7+
const branch = core.getInput('branch');
8+
const sha = core.getInput('sha');
9+
core.debug(`Creating branch ${branch}`);
10+
const isCreated = await createBranch(getOctokit, context, branch, sha);
11+
core.setOutput('created', Boolean(isCreated));
12+
} catch (error: any) {
13+
core.setFailed(error.message);
14+
}
1515
}
1616
run();

0 commit comments

Comments
 (0)