-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 979 Bytes
/
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
const core = require('@actions/core');
const github = require('@actions/github');
try {
// skip if not PR
if (github.context.eventName !== "pull_request") {
console.log("not a PR")
return
}
// skip if PR is not freshly opened
if (github.context.payload.action !== "opened") {
console.log("PR is not new")
return
}
const pr_payload = github.context.payload.pull_request;
const token = core.getInput('github-token');
let added = parseInt(pr_payload.additions);
let deleted = parseInt(pr_payload.deletions);
if (token == "") {
throw new Error("no gh token");
}
const octokit = github.getOctokit(token)
if (added < deleted) {
octokit.rest.issues.createComment({
issue_number: pr_payload.number,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
body: "🎉 🏆 This PR deletes more code than it adds! 🏆 🎉"
})
}
} catch (error) {
core.setFailed(error.message);
}