-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
105 lines (86 loc) · 3.09 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
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* This is the main entrypoint to your Probot app
* @param {import('probot').Probot} app
*/
const data = require('./functions/data.js');
const steps = require('./functions/steps.js');
var start;
module.exports = (app) => {
app.log.info("Yay, the app was loaded!");
app.on("push", async (context) => {
console.log("Push event")
if (context.payload.commits[context.payload.commits.length - 1].added.includes(".bit/course-details.md")) {
start = true
} else {
start = false
} // comment lol
if (start && context.payload.commits[0].added[0] != ".bit/.progress") {
let configData = await data.yamlFile(context);
console.log("Deleting file...")
await steps.deleteFile(context);
await steps.startLab(context, configData);
console.log("Committing workflow files")
await steps.workFlow(context);
}
});
app.on('pull_request.closed', async (context) => {
console.log("Pull request")
main(context, 'pull_request.closed');
});
app.on('issue_comment.created', async (context) => {
console.log("Issue comment created")
if (context.payload.sender.login != "counselorbot[bot]") {
main(context, 'issue_comment.created');
}
});
app.on('workflow_run.completed', async (context) => {
console.log("Workflow run")
console.log(context.payload.workflow_run.name)
if (context.payload.workflow_run.name != "Syncing Your Cabin" && context.payload.workflow_run.head_commit.message != "Start workflows" && context.payload.workflow_run.head_commit.message != "Track progress" && context.payload.workflow_run.head_commit.message != "Update progress") {
main(context, 'workflow_run.completed');
}
});
app.on('create', async (context) => {
console.log("Branch created")
main(context, 'create')
});
};
async function main(context, event) {
let currentStep = ""
let configData = await data.yamlFile(context);
if (configData == null) {
return
}
console.log("Got configyml!")
try {
currentStep = await data.findStep(context);
console.log("Getting current step!")
} catch (e) {
return
}
if (event == 'create') {
let condition = await steps.newBranch(context, context.payload.ref, currentStep)
if (condition == null) {
return
}
} else {
console.log(currentStep, configData, event)
let typeOfStep = await data.typeStep(currentStep, configData, event);
if (typeOfStep == null) {
return
}
console.log("The type: " + typeOfStep)
let moveOn = await steps.workEvaluation(typeOfStep, context, configData);
console.log("moveOn: " + moveOn)
console.log("Successfully evaluated")
console.log("Next Step function executing")
let issueNo = await data.issueNo(context)
if (issueNo == null) {
return
}
if (moveOn[0] == true) {
let branchName = await steps.nextStep(currentStep, context, configData, issueNo);
await steps.updateFiles(typeOfStep, moveOn, count, configyml, branchName, context)
}
}
}