-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from mrhappyma/pr-link-in-one-commit-so-it-lo…
…oks-like-it-worked-first-try add preview link gh action
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||