diff --git a/.github/workflows/merger.yml b/.github/workflows/merger.yml new file mode 100644 index 0000000..0e14d5f --- /dev/null +++ b/.github/workflows/merger.yml @@ -0,0 +1,36 @@ +name: Pull-request Merger + +on: + workflow_call: + issue_comment: + types: [created, edited] + +jobs: + merge: + if: | + (github.event.issue.pull_request) && + (github.event.comment.author_association == 'OWNER') && + (github.event.comment.body == '/merge') + runs-on: ubuntu-20.04 + timeout-minutes: 1 + permissions: + contents: write + pull-requests: write + steps: + - name: Merge + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUM: ${{ github.event.issue.number }} + run: | + PR_JSON=$(gh pr view "${PR_NUM}" --json "title,body,labels" --repo "${GITHUB_REPOSITORY}") + PR_TITLE=$(echo "${PR_JSON}" | jq -r '.title') + PR_BODY=$(echo "${PR_JSON}" | jq -r '.body') + PR_LABELS=$(echo "${PR_JSON}" | jq -r '.labels[].name' | sed "s/^/- /g") + PR_MERGE_TITLE="${PR_TITLE} (#${PR_NUM})" + gh pr merge "${PR_NUM}" --squash \ + --subject "${PR_MERGE_TITLE}" \ + --repo "${GITHUB_REPOSITORY}" \ + --body "${PR_BODY} + + Labels: + ${PR_LABELS}" diff --git a/README.md b/README.md index a267b12..197b4c2 100644 --- a/README.md +++ b/README.md @@ -273,3 +273,19 @@ jobs: hadolint: uses: peaceiris/workflows/.github/workflows/hadolint.yml@v0.14.0 ``` + + + +## Reusable pull-request merger workflow + +```yaml +name: pull-request + +on: + issue_comment: + types: [created, edited] + +jobs: + merger: + uses: peaceiris/workflows/.github/workflows/merger.yml@v0.16.0 +```