From d8246958b986a62aeaea4abade36ad8c18043df1 Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Mon, 11 Jul 2022 22:44:29 +0900 Subject: [PATCH] ci: add reusable merger workflow (#7) --- .github/workflows/merger.yml | 36 ++++++++++++++++++++++++++++++++++++ README.md | 16 ++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/merger.yml 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 +```