I've developed a GitHub action that currently is triggered when any issue is opened. I was wondering if there was a way to trigger this action only when an issue is created from a specific issue template? (e.g. when an issue is logged from bug.md and not from feature-request.md)
It looks like you can add if statements to jobs, like below from their docs:
issue_commented:
# This job only runs for issue comments
name: Issue comment
if: ${{ !github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- run: |
echo A comment on issue $NUMBER
env:
NUMBER: ${{ github.event.issue.number }}
I was thinking of applying that logic to my case but it doesn't seem like the issue template name is in any of my testing payloads.
Would anyone know if there is a way/place I can capture the issue template name or another way of accomplishing this?
You can look at the webhook event payload for an opened issue, and as far as I can tell, there's nothing in there that directly tells you what template the issue was created from.
As a workaround, you can set a unique label per template, both for the legacy templates and the issue forms, see docs.
Then, in your workflow, you can check if the labels include the one for the template you want to run the workflow for, with something like
if: contains(github.event.issue.labels.*.name, 'some-template')