forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 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,108 @@ | ||
name: /merge handler | ||
|
||
on: | ||
repository_dispatch: | ||
types: [merge-command] | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
concurrency: merge-handler-${{ github.event.client_payload.pull_request.node_id || github.run_id }} | ||
|
||
jobs: | ||
merge: | ||
if: github.event.client_payload.pull_request != null | ||
|
||
name: Trim description and merge | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- id: pr-data | ||
name: Get PR data and trim PR body | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const pull_id = context.payload.client_payload.pull_request.node_id; | ||
core.debug(`Pull request ID: ${pull_id}.`); | ||
const query = `query($id: ID!) { | ||
node(id: $id) { | ||
... on PullRequest { | ||
autoMergeRequest { | ||
mergeMethod | ||
} | ||
closed | ||
body | ||
} | ||
} | ||
}`; | ||
const { node: pr_info } = await github.graphql(query, { id: pull_id }); | ||
core.debug(`PR data: ${pr_info}`); | ||
if (node.autoMergeRequest || node.closed) { | ||
core.notice("PR is already merged or is in queue."); | ||
return; | ||
} | ||
const [ body, body_tail ] = pr_info.body.split(/^---\s*$/, 2) | ||
body = body.trimEnd() | ||
body_tail = body_tail?.trimEnd() || "" | ||
core.setOutput('run', 'true') | ||
core.setOutput('body', body) | ||
core.setOutput('body-tail', body_tail) | ||
core.setOutput('update-body', pr_info.body !== result.body) | ||
- if: steps.pr-data.outputs.run | ||
id: find-comment | ||
uses: peter-evans/find-comment@v2 | ||
with: | ||
issue-number: ${{ github.event.client_payload.pull_request.number }} | ||
comment-author: github-actions[bot] | ||
body-includes: <!-- /merge info comment --> | ||
direction: last | ||
|
||
- if: steps.pr-data.outputs.run && !(steps.find-comment.outputs.comment-id && steps.pr-data.outputs.body_tail == "") | ||
name: Create or update informational comment | ||
uses: peter-evans/create-or-update-comment@v3 | ||
with: | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
issue-number: ${{ github.event.client_payload.pull_request.number }} | ||
body: | | ||
<!-- /merge info comment --> | ||
Merge requested by: @${{ github.event.client_payload.github.payload.comment.user.login }} | ||
Contents after the first section break of this PR's description has been removed and preserved below: | ||
--- | ||
<blockquote> | ||
${{ steps.pr-data.outputs.body-tail }} | ||
</blockquote> | ||
edit-mode: replace | ||
|
||
- if: steps.pr-data.outputs.run && steps.pr-data.outputs.update-body | ||
name: Update PR description | ||
uses: actions/github-script@v6 | ||
env: | ||
NEW_PR_BODY: ${{ steps.pr-data.outputs.body }} | ||
with: | ||
script: | | ||
const pull_id = context.payload.client_payload.pull_request.node_id; | ||
const update = `mutation ($input: UpdatePullRequestInput!) { | ||
updatePullRequest(input: $input) { | ||
clientMutationId | ||
} | ||
}`; | ||
await github.graphql(update, { | ||
pullRequestId: pull_id, | ||
body: process.env.NEW_PR_BODY | ||
}); | ||
- name: Queue for merging | ||
env: | ||
URL: ${{ github.event.client_payload.pull_request.html_url }} | ||
run: gh pr merge "$URL" --auto |
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,23 @@ | ||
name: Dispatch slash commands | ||
|
||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
dispatch: | ||
name: Dispatch command | ||
runs-on: ubuntu-latest | ||
environment: pr-merge | ||
steps: | ||
- uses: peter-evans/slash-command-dispatch@v3 | ||
with: | ||
token: ${{ secrets.PAT }} | ||
commands: | | ||
merge | ||
issue-type: pull-request | ||
permission: write |