-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (41 loc) · 1.23 KB
/
index.js
File metadata and controls
47 lines (41 loc) · 1.23 KB
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
44
45
46
47
const core = require("@actions/core");
const github = require("@actions/github");
try {
const apiToken = core.getInput("api_token");
if (apiToken === "") {
throw "api_token is a required input"
}
if (github.context.payload.pull_request) {
const branchName = github.context.payload.pull_request.head.ref;
const branchMatch = branchName.match(/^([iep])?(\d+)_/);
if (branchMatch) {
const branchModifier = branchMatch[1];
const taskId = branchMatch[2];
let branchType;
let branchIgnored = false;
switch (branchModifier) {
case "e":
branchType = "effort";
break;
case "p":
branchType = "project";
break;
case "x":
branchIgnored = true;
break;
default:
branchType = "task";
}
core.setOutput('branch_name', branchName);
core.setOutput('branch_type', branchType);
core.setOutput("ignored", branchIgnored);
core.setOutput('task_id', taskId);
} else {
core.info(`Skipping, branch name ${branchName} doesn't match.`);
}
} else {
core.info("Skipping, context doesn't appear to be a pull request.");
}
} catch (error) {
core.setFailed(error.message);
}