I am looking for a way to have a GitHub Action run when a PR is merged, the GitHub Action has to grab the PR description and store the data somewhere for later use.
Is there any way to do this through GitHub Actions without an API or webhook?
I am looking for a way to have a GitHub Action run when a PR is merged, the GitHub Action has to grab the PR description and store the data somewhere for later use.
Is there any way to do this through GitHub Actions without an API or webhook?
There are two approaches: Either run the workflow when a PR is closed with merge=true or run a workflow on the target branch if you know all pushes to the target branch go through a PR.
You can trigger an action when a PR is closed like so:
on:
pull_request:
types: [closed]
The above event is triggered whether a PR was merged or closed without merging. Therefore, you still need to check that flag when running a job:
my_job:
build:
if: github.event.pull_request.merged == 'true'
If you know all your PRs are merged into main and users cannot directly push to main, you might as well trigger your workflow on push events on main like so:
on:
push:
branches:
- main
Answer is great but slightly outdated, using true did not work for me.
The following does the trick for me :
my_job:
build:
if: github.event.pull_request.merged == true