-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
92 lines (77 loc) · 3.89 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const core = require("@actions/core");
const github = require("@actions/github");
const fetch = require("node-fetch");
const prHandler = require("./handlers/prHandler");
const branchHandler = require("./handlers/branchHandler");
const staticFunctions = require("./staticFunctions");
const version = "2.0.5";
global.Headers = fetch.Headers;
main();
async function main(){
try {
console.log("VERSION " + version);
staticFunctions.getValuesFromPayload(github.context.payload);
// HANDLING PULL REQUESTS
if (process.env.GITHUB_EVENT_NAME.includes("pull_request")){
console.log ("PR event detected");
var [prName, prBody] = await prHandler.getPrInfo();
if (prName === undefined) {
console.log("Couldn't read PR name properly, ending checks");
return;
}
if (prName.toLowerCase().includes("Code cleanup".toLowerCase()) ||
prName.toLowerCase().includes("Swagger update".toLowerCase()) ||
prName.toLowerCase().includes("Master to Dev".toLowerCase()) ||
prName.toLowerCase().includes("Dev to Master".toLowerCase())) {
console.log ("No checkups for the code cleanup or swagger update branches or master to dev sync");
return;
}
var workItemId = prHandler.getWorkItemIdFromPrBody(prBody);
try {
if ((await prHandler.isPrOpen()) === true) {
console.log("PR was opened, so moving AB#"+workItemId+" to "+process.env.propenstate+" state");
await prHandler.handleOpenedPr(workItemId);
}
else if ((await prHandler.isPrMerged()) === true) {
console.log("PR was merged, so moving AB#"+workItemId+" to "+process.env.closedstate+" state");
await prHandler.handleMergedPr(workItemId);
}
else if ((await prHandler.isPrClosed()) === true) {
console.log("PR was closed without merging, so moving AB#"+workItemId+" to "+process.env.inprogressstate+ " state");
await prHandler.handleClosedPr(workItemId);
}
} catch (err) {
console.log("Couldn't update the work item");
core.setFailed(err.toString());
}
}
// HANDLING BRANCHES
else
{
console.log ("Branch event detected");
var branchName = branchHandler.getBranchTitle();
console.log ("Branch name: " + branchName);
if (branchName.toLowerCase().includes("code-cleanup".toLowerCase()) ||
branchName.toLowerCase().includes("code cleanup".toLowerCase()) ||
branchName.toLowerCase().includes("swagger-update".toLowerCase()) ||
branchName.toLowerCase().includes("swagger update".toLowerCase()) ||
(branchName.toLowerCase().includes("feature".toLowerCase()) === false && branchName.toLowerCase().includes("master".toLowerCase())) ||
(branchName.toLowerCase().includes("feature".toLowerCase()) === false && branchName.toLowerCase().includes("dev".toLowerCase()))) {
console.log ("No checkups for the code cleanup or swagger update or master/dev branches");
return;
}
var workItemId = branchHandler.getWorkItemIdFromPrBody(branchName);
try {
var updated = await branchHandler.handleOpenedBranch(workItemId);
if (updated !== true) {
console.log("Couldn't update the work item");
}
} catch (err) {
console.log("Couldn't update the work item");
core.setFailed(err.toString());
}
}
} catch (err) {
core.setFailed(err.toString());
}
}