I’m trying to set up a GitHub action for when pull requests are opened or closed and I’d like to get the type of the trigger to add it to the message. The YAML is as follows:
on:
pull_request:
types: [opened, closed, reopened] #I’d like to get which one has been triggered
For instance:
User X has opened a pull request
Someone suggested ${{env.GITHUB_EVENT_NAME}}
but it’s empty. ${{github.event}}
seems to be a good place but it returns an object with the webhook payload and I don’t know if "types" is in it or how to get it.
This action triggers another GitHub Actions workflow, using the workflow_dispatch event. The workflow must be configured for this event type e.g. on: [workflow_dispatch] This allows you to chain workflows, the classic use case is have a CI build workflow, trigger a CD release/deploy workflow when it completes.
pull_request_target runs in the context of the target repository of the PR, rather than in the merge commit. This means the standard checkout action uses the target repository to prevent accidental usage of the user supplied code.
${{github.event.action}}
should give you the action for the pull request.
Example:
on:
pull_request:
types: [opened, closed, reopened]
jobs:
prJob:
name: Print info
runs-on: ubuntu-latest
steps:
- name: Print GitHub event action
run: |
echo "${{ github.event.action }}"
The github
context is documented at https://docs.github.com/en/actions/learn-github-actions/contexts#github-context.
And the complete documentation for the event can be found here: https://developer.github.com/webhooks/event-payloads/#pull_request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With