Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Aug 27, 2023
1 parent bc21306 commit 819ed49
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ on:
issue_comment:
types: [created] # only trigger on new issue comments
env:
GH_TOKEN: ${{ secrets.GH_PAT }} # authorize bot
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # authorize bot
GH_PAT: ${{ secrets.GH_PAT }} # authorize bot to write to PRs
jobs:
process:
name: Process Comment
Expand Down
14 changes: 10 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ const main = async () => {
}

const githubToken = process.env.GH_TOKEN
const PAT = process.env.GH_PAT || githubToken
if (!githubToken) {
throw new Error('GH_TOKEN is not set')
}
if (!PAT) {
throw new Error('this is unreachable')
}
const octokit = github.getOctokit(githubToken)

const result = await processCmd(octokit, rawcmd, {
Expand All @@ -28,6 +32,9 @@ const main = async () => {

console.log('Result', result)

// use a PAT to merge the PR
const patOctokit = github.getOctokit(PAT)

if (result.createComment) {
await octokit.rest.issues.createComment({
...github.context.repo,
Expand All @@ -38,21 +45,21 @@ const main = async () => {

if (result.merge) {
// approve the pr
await octokit.rest.pulls.createReview({
await patOctokit.rest.pulls.createReview({
...github.context.repo,
pull_number: github.context.issue.number,
event: 'APPROVE'
})

await octokit.rest.pulls.merge({
await patOctokit.rest.pulls.merge({
...github.context.repo,
pull_number: github.context.issue.number,
sha: result.merge
})
}

if (result.close) {
await octokit.rest.issues.update({
await patOctokit.rest.issues.update({
...github.context.repo,
issue_number: github.context.issue.number,
state: 'closed'
Expand Down
2 changes: 1 addition & 1 deletion src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const processCmd = async (octokit: ReturnType<typeof github.getOctokit>, rawcmd:
}
}
return {
createComment: `Unable to find fellowshipReferenda.confirmed event at ${blockHash}`
createComment: `Unable to find fellowshipReferenda.confirmed event at \`${blockHash}\` for proposal with preimage \`${remarkBodyHash}\``
}
}

Expand Down

0 comments on commit 819ed49

Please sign in to comment.