forked from hiimbex/testing-things
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (30 loc) · 1.08 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
const standard = require('standard')
;
module.exports = {
async push(event, context) {
const push = event.payload
const compare = await context.github.repos.compareCommits(context.repo({
base: push.before,
head: push.after
}));
const branch = push.ref.replace('refs/heads/', '');
return Promise.all(compare.data.files.map(async file => {
const content = await context.github.repos.getContent(context.repo({
path: file.filename,
ref: branch
}));
const text = Buffer.from(content.data.content, 'base64').toString();
standard.lintText(text, {cwd: '', fix: true, filename: file.filename}, (err, results) => {
console.log(results);
return Promise.all(results.results.map(result => {
context.github.repos.updateFile(context.repo({
path: file.filename,
message: `Fix lint errors for ${file.filename}`,
content: Buffer.from(result.output).toString('base64'),
sha: content.data.sha,
branch: branch,
}));
}));
});
}));
}