diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index 71e291bdd2eb..f9f9a41a9839 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -314,6 +314,33 @@ on: types: [created, deleted] ``` +The `issue_comment` event occurs for comments on both issues and pull requests. To determine whether the `issue_comment` event was triggered from an issue or pull request, you can check the event payload for the `issue.pull_request` property and use it as a condition to skip a job. + +For example, you can choose to run the `pr_commented` job when comment events occur in a pull request, and the `issue_commented` job when comment events occur in an issue. + +```yaml +on: issue_comment + +jobs: + pr_commented: + # This job only runs for pull request comments + name: PR comment + if: ${{ github.event.issue.pull_request }} + runs-on: ubuntu-latest + steps: + - run: | + echo "Comment on PR #${{ github.event.issue.number }}" + + 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 "Comment on issue #${{ github.event.issue.number }}" +``` + #### `issues` Runs your workflow anytime the `issues` event occurs. {% data reusables.developer-site.multiple_activity_types %} For information about the REST API, see "[Issues](/v3/issues)."