-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (38 loc) · 1.47 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import * as core from '@actions/core';
import {GitHubService} from "./github.service.js";
try {
const headUserBranch = core.getInput('headBranch') || "main";
const token = core.getInput('token');
const org = core.getInput('org');
const userRepoName = core.getInput('userRepoName');
const branch = core.getInput('branch');
const githubService = new GitHubService(token, org, userRepoName)
let isBranchExists;
githubService.isBranchExists(branch).then(res => {
isBranchExists = res;
if (!isBranchExists) {
console.log(`Branch ${branch} does not exist`);
core.setOutput('branchExists', 'false');
githubService.createBranch(branch, headUserBranch).then(res => {
console.log(`Branch ${branch} created`);
core.setOutput('branchCreated', 'true');
}).catch(e => {
console.log(`Branch ${branch} creation failed : ${e}`);
core.setOutput('branchExists', 'false');
throw e;
});
} else {
console.log(`Branch ${branch} exists`);
core.setOutput('branchExists', 'true');
}
}).catch(e => {
console.log(`Branch ${branch} check failed : ${e}`);
core.setOutput('branchCheck', 'false');
throw e;
});
} catch (e) {
core.setOutput("choreo-status", "failed");
core.setFailed(e.message);
console.log("choreo-status", "failed");
console.log(e.message);
}