-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (48 loc) · 1.44 KB
/
index.js
File metadata and controls
57 lines (48 loc) · 1.44 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
48
49
50
51
52
53
54
55
56
57
const github=require('./github/index');
const executor=require('./execution/executor');
const comment=require('./comment')
module.exports = (app) => {
app.log.info("Yay, the app was loaded!");
app.on(
["pull_request.opened", "pull_request.synchronize", "pull_request.edited"],
async (context) => {
const {pull_request:data}=context.payload;
const {title,body}=data;
console.log(title)
console.log(body)
let titlePR = title.toLowerCase();
let bodyPR = body.toLowerCase();
if(bodyPR.search("/execute")==null && titlePR.search("/execute")==-1){
app.log.info("Execute command is not present");
return;
}
try {
const res=await github(context);
if(res.status==400){
throw new Error(res.message);
}
console.log(res.code);
const options={
code:res.code,
language:res.language,
input:res.input=='null'?null:res.input,
}
console.log(options)
const output=await executor(options);
console.log("execution worked")
if(output.status==400){
throw new Error(output.message);
}
const body={
output:output,
message:"Success"
}
console.log(body)
await comment(context,body);
console.log("comment ")
} catch (error) {
await comment(context,error.message);
}
}
);
};