Skip to content

Commit

Permalink
Merge pull request #718 from mrhappyma/pr-link-in-one-commit-so-it-lo…
Browse files Browse the repository at this point in the history
…oks-like-it-worked-first-try

add preview link gh action
  • Loading branch information
maxwofford authored Jul 19, 2024
2 parents 5ea8da3 + da0d8ec commit d0aae7f
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/art-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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=${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,
});
}

0 comments on commit d0aae7f

Please sign in to comment.