You can use the pull_request
event and narrow it down to "has been closed" and "was merged" using the types
and branches
properties of pull_request
, then check in the github.event.pull_request
context that the merged
property is true
.
All together, for a project named "Test" and a column "Merged PRs", using the GitHub CLI to make API calls, a workflow might look like this:
name: Add merged PRs to project
# When a PR into main is closed or merged
on:
pull_request:
types:
- closed
branches:
- main
jobs:
addpr:
name: Add PR to project
# PR must must be merged, not closed
if: github.event.pull_request.merged
runs-on: ubuntu-20.04
steps:
- name: Add PR to project board
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
projectid=$(gh api "repos/${{ github.repository }}/projects" \
-H "Accept: application/vnd.github.inertia-preview+json" \
| jq '.[] | select(.name == "Test").id')
columnid=$(gh api "projects/$projectid/columns" \
-H "Accept: application/vnd.github.inertia-preview+json" \
| jq '.[] | select(.name == "Merged PRs").id')
gh api "projects/columns/$columnid/cards" \
-H "Accept: application/vnd.github.inertia-preview+json" \
-F "content_type=PullRequest" \
-F "content_id=${{ github.event.pull_request.id }}"
For reference and to see how "closed with unmerged commits" and "properly merged" are told apart, see the docs for the pull_request
payload object.