Skip to content

Art PR Comment

Art PR Comment #826

Workflow file for this run

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,
});
}