Skip to content

Commit e89eef3

Browse files
authored
Actions: How to run jobs on issue_comment only if PR (#438)
1 parent 9913665 commit e89eef3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

content/actions/reference/events-that-trigger-workflows.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,33 @@ on:
314314
types: [created, deleted]
315315
```
316316

317+
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.
318+
319+
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.
320+
321+
```yaml
322+
on: issue_comment
323+
324+
jobs:
325+
pr_commented:
326+
# This job only runs for pull request comments
327+
name: PR comment
328+
if: ${{ github.event.issue.pull_request }}
329+
runs-on: ubuntu-latest
330+
steps:
331+
- run: |
332+
echo "Comment on PR #${{ github.event.issue.number }}"
333+
334+
issue-commented:
335+
# This job only runs for issue comments
336+
name: Issue comment
337+
if: ${{ !github.event.issue.pull_request }}
338+
runs-on: ubuntu-latest
339+
steps:
340+
- run: |
341+
echo "Comment on issue #${{ github.event.issue.number }}"
342+
```
343+
317344
#### `issues`
318345

319346
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)."

0 commit comments

Comments
 (0)