generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (65 loc) · 1.75 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
const core = require('@actions/core');
const github = require('@actions/github')
async function run() {
try {
const owner = core.getInput('owner', { required: true })
const repo = core.getInput('repo', { required: true })
const pr_number = core.getInput('pr_number', { required: true })
const token = core.getInput('token', { required: true })
const octokit = new github.getOctokit(token)
const { data: changedFiles } = await octokit.rest.pulls.listFiles({
owner,
repo,
pull_number: pr_number
})
let diffData = {
addition: 0,
deletions: 0,
changes: 0
}
diffData = changedFiles.reduce((acc, file) => {
acc.additions += file.additions;
acc.deletions += file.deletions;
acc.changes += file.changes;
return acc;
}, diffData);
await octokit.rest.issues.createComment({
owner,
repo,
issue_number: pr_number,
body: `
Pull request ${pr_number} has been updated with: \n
- ${diffData.changes} changes\n
- ${diffData.addition} additions\n
- ${diffData.deletions} deletions\n
`
})
for (const file of changedFiles) {
const fileExtension = file.filename.split('.').pop();
let label = '';
switch (fileExtension) {
case 'md':
label = 'markdown';
break;
case 'js':
label = 'javascript'
break;
case 'yml':
label = 'yaml'
break;
default:
label = 'noextension'
break;
}
await octokit.rest.issues.addLabel({
owner,
repo,
issue_number: pr_number,
labels: [label]
})
}
} catch (error) {
core.setFailed(error.message);
}
}
run();