I want to streamline the following GitHub workflow by removing the if
statements and removing the redundant code.
As you can see, it's largely the same, I need to create a environment variable which is set to either issue
or pull_request
based on the value of ${{ github.event_name }}
name: my-workflow
run-name: my-workflow
on:
issues:
types: [opened, edited, closed]
pull_request:
types: [opened, edited, closed]
jobs:
issue-push:
if: github.event_name == 'issues'
runs-on: "ubuntu-latest"
steps:
- run: |
# Do something here with ${{ github.event.issue.html_url }}
pull-request-push:
if: github.event_name == 'pull_request'
runs-on: "ubuntu-latest"
steps:
- run: |
# Do something here with ${{ github.event.pull_request.html_url }}
In other words, I'm trying to achieve this:
name: my-workflow
run-name: my-workflow
on:
issues:
types: [opened, edited, closed]
pull_request:
types: [opened, edited, closed]
jobs:
issue-push:
runs-on: "ubuntu-latest"
steps:
- env:
# Pseudocode
TRIGGER_TYPE: "(if github.event_name == "issues" then 'issue') else 'pull_request'"
- run: |
# Do something here with ${{ github.event.$TRIGGER_TYPE.html_url }}