From c8a9894b98ff3cac5838d1f4c7c0c6f08a375469 Mon Sep 17 00:00:00 2001 From: Simran Date: Mon, 12 Oct 2020 14:22:26 +0200 Subject: [PATCH 1/7] Actions: How to run jobs on issue_comment only if PR --- .../actions/reference/events-that-trigger-workflows.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index e1373d36d1e4..c112b273d2bd 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -314,6 +314,16 @@ on: types: [created, deleted] ``` +The `issue_comment` event occurs for both, comments on issues as well as pull requests. To run a workflow only if a pull request is commented, you can check the event payload for the `issue.pull_request` attribute and use it as condition to skip all jobs. + +```yaml +on: issue_comment + +jobs: + pr_commented: + if: ${{ github.event.issue.pull_request }} +``` + #### `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)." From 0a9a86ceb984ec1ef070906dc543ad8eac1c0455 Mon Sep 17 00:00:00 2001 From: Simran Date: Mon, 12 Oct 2020 14:44:28 +0200 Subject: [PATCH 2/7] Make sentence a bit clearer --- content/actions/reference/events-that-trigger-workflows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index c112b273d2bd..fdcfe0b99bec 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -314,7 +314,7 @@ on: types: [created, deleted] ``` -The `issue_comment` event occurs for both, comments on issues as well as pull requests. To run a workflow only if a pull request is commented, you can check the event payload for the `issue.pull_request` attribute and use it as condition to skip all jobs. +The `issue_comment` event occurs for both, comments on issues as well as pull requests. To run jobs only in one of the cases, you can check the event payload for the `issue.pull_request` attribute and use it as condition to skip jobs. ```yaml on: issue_comment From 4885d3356568fd1294569c07a2f45d64f473965d Mon Sep 17 00:00:00 2001 From: Simran Date: Wed, 4 Nov 2020 18:01:04 +0100 Subject: [PATCH 3/7] Update content/actions/reference/events-that-trigger-workflows.md --- content/actions/reference/events-that-trigger-workflows.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index fdcfe0b99bec..93b16b3f61b1 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -314,7 +314,9 @@ on: types: [created, deleted] ``` -The `issue_comment` event occurs for both, comments on issues as well as pull requests. To run jobs only in one of the cases, you can check the event payload for the `issue.pull_request` attribute and use it as condition to skip jobs. +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 comments are added to a pull request or the `issue_commented` job when comments are added to an issue. ```yaml on: issue_comment From e7128b561d90be4bd07038f9c2a32672aefafeb0 Mon Sep 17 00:00:00 2001 From: Simran Spiller Date: Wed, 4 Nov 2020 18:07:58 +0100 Subject: [PATCH 4/7] Apply modified review suggestions --- .../reference/events-that-trigger-workflows.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index 93b16b3f61b1..6b016345a96a 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -316,14 +316,27 @@ on: 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 comments are added to a pull request or the `issue_commented` job when comments are added to an issue. +For example, you can choose to run the `pr_commented` job when comments are added to a pull request, and the `issue_commented` job when comments are added to an issue. ```yaml on: issue_comment jobs: pr_commented: + # This job only runs for pull request comments + name: New PR comment if: ${{ github.event.issue.pull_request }} + runs-on: ubuntu-latest + steps: + - run: echo "New PR comment" + + issue-commented: + # This job only runs for issue comments + name: New issue comment + if: ${{ !github.event.issue.pull_request }} + runs-on: ubuntu-latest + steps: + - run: echo "New issue comment" ``` #### `issues` From cb31da65b6325bd31e183cbb5318682411ae92d6 Mon Sep 17 00:00:00 2001 From: Simran Spiller Date: Wed, 4 Nov 2020 18:25:28 +0100 Subject: [PATCH 5/7] Improve example --- .../actions/reference/events-that-trigger-workflows.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index 6b016345a96a..8e9ac903ab14 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -324,19 +324,21 @@ on: issue_comment jobs: pr_commented: # This job only runs for pull request comments - name: New PR comment + name: PR comment if: ${{ github.event.issue.pull_request }} runs-on: ubuntu-latest steps: - - run: echo "New PR comment" + - run: | + echo "Comment on PR #${{ github.event.issue.number }}" issue-commented: # This job only runs for issue comments - name: New issue comment + name: Issue comment if: ${{ !github.event.issue.pull_request }} runs-on: ubuntu-latest steps: - - run: echo "New issue comment" + - run: | + echo "Comment on issue #${{ github.event.issue.number }}" ``` #### `issues` From a795b0f97eeeb25c7daf6efeb648335ff96889a3 Mon Sep 17 00:00:00 2001 From: Simran Date: Wed, 4 Nov 2020 23:33:46 +0100 Subject: [PATCH 6/7] Update content/actions/reference/events-that-trigger-workflows.md --- content/actions/reference/events-that-trigger-workflows.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index 8e9ac903ab14..f1c31b37a037 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -316,7 +316,7 @@ on: 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 comments are added to a pull request, and the `issue_commented` job when comments are added to an issue. +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 From cffd752ada6d0c01069512ae58463f0df41569b2 Mon Sep 17 00:00:00 2001 From: Simran Date: Wed, 4 Nov 2020 23:38:30 +0100 Subject: [PATCH 7/7] Fix whitespace --- content/actions/reference/events-that-trigger-workflows.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/actions/reference/events-that-trigger-workflows.md b/content/actions/reference/events-that-trigger-workflows.md index f1c31b37a037..d45af6625b3e 100644 --- a/content/actions/reference/events-that-trigger-workflows.md +++ b/content/actions/reference/events-that-trigger-workflows.md @@ -337,8 +337,8 @@ jobs: if: ${{ !github.event.issue.pull_request }} runs-on: ubuntu-latest steps: - - run: | - echo "Comment on issue #${{ github.event.issue.number }}" + - run: | + echo "Comment on issue #${{ github.event.issue.number }}" ``` #### `issues`