Skip to content

Instantly share code, notes, and snippets.

@KoheiKanagu
Created May 31, 2023 04:49
Show Gist options
  • Save KoheiKanagu/27aab28b27d408a1057452fe3ff93b54 to your computer and use it in GitHub Desktop.
Save KoheiKanagu/27aab28b27d408a1057452fe3ff93b54 to your computer and use it in GitHub Desktop.
PRのワークフローが完了した際に`auto_merge`というタグがあればマージする
name: Auto Merge
on:
workflow_run:
workflows:
- Pull Requests
types:
- completed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
merge:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: GitHub App token
uses: tibdex/[email protected]
id: generate_token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Get PR number and labels
id: labels
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
pr_number=${{ github.event.workflow_run.pull_requests[0].number }}
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
pr_labels=$(gh pr view $pr_number --json labels)
echo "pr_labels=$pr_labels" >> "$GITHUB_OUTPUT"
- name: Auto merge
if: contains(fromJson(steps.labels.outputs.pr_labels).labels.*.name, 'auto_merge')
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
gh pr merge ${{ steps.labels.outputs.pr_number }} --squash --delete-branch
@KoheiKanagu
Copy link
Author

もしプルリクに "fixed #123" のように連動してクローズしてほしいissueを書いていた場合、このauto_mergeではクローズしないので注意。
おそらくbotがマージしている場合はクローズしない仕様だと思われる。

であればPersonal access tokenを利用すればクローズするかも?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment