-
Notifications
You must be signed in to change notification settings - Fork 510
69 lines (62 loc) · 2.4 KB
/
art-pr.yml
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
name: Art PR Comment
run-name: Art PR Comment
on:
pull_request_target:
types: [opened,synchronize,reopened]
paths: 'art/**'
jobs:
comment-pr:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
const owner = context.payload.repository.owner.login;
const repo = context.payload.repository.name;
const number = context.payload.number;
const changedFiles = await github.request(`GET /repos/${owner}/${repo}/pulls/${number}/files`, {
owner: owner,
repo: repo,
pull_number: number,
});
let commentbody = "<!-- SUPER-COOL-BLOT-BOT-THING -->\n";
let also = false;
for (const file of changedFiles.data) {
if (!file.filename.endsWith('index.js')) continue;
const rawUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${pr.head.sha}/${file.filename}`
const blotUrl = `https://blot.hackclub.com/editor?src=${encodeURI(rawUrl)}`;
if (!also) {
commentbody += `\`${file.filename}\` looks like art! [preview it in the editor](${blotUrl})\n`
also = true
} else {
commentbody += `\`${file.filename}\` *also* looks like art! [preview it in the editor](${blotUrl})\n`
}
}
if (!also) return;
console.log(commentbody)
const comments = await github.rest.issues.listComments({
issue_number: number,
owner: owner,
repo: repo,
});
const ecomment = comments.data.find((c) => c.body.includes("SUPER-COOL-BLOT-BOT-THING"));
if (ecomment) {
github.rest.issues.updateComment({
comment_id: ecomment.id,
owner: owner,
repo: repo,
body: commentbody,
});
} else {
github.rest.issues.createComment({
issue_number: number,
owner: owner,
repo: repo,
body: commentbody,
});
}