1
0
mirror of synced 2025-12-25 02:17:36 -05:00
Files
docs/content/actions/guides/commenting-on-an-issue-when-a-label-is-added.md
hubwriter de28b750d1 Configure GITHUB_TOKEN permissions (#18348)
* Add 'permissions' to reference page

* Final set of pre-review changes

* Update content/actions/learn-github-actions/security-hardening-for-github-actions.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/reference/authentication-in-a-workflow.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/reference/authentication-in-a-workflow.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/reference/authentication-in-a-workflow.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/reference/authentication-in-a-workflow.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update data/reusables/github-actions/workflow-permissions-intro.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/reference/authentication-in-a-workflow.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/reference/authentication-in-a-workflow.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update data/reusables/github-actions/publish-to-packages-workflow-step.md

Co-authored-by: Sarah Edwards <skedwards88@github.com>

* Update content/actions/guides/publishing-nodejs-packages.md

* Update content/actions/guides/publishing-java-packages-with-gradle.md

* Update content/actions/guides/publishing-java-packages-with-maven.md

* Update content/actions/guides/publishing-nodejs-packages.md

* Update content/actions/reference/authentication-in-a-workflow.md

* Update content/actions/reference/authentication-in-a-workflow.md

* Update content/actions/reference/authentication-in-a-workflow.md

* Update content/actions/reference/authentication-in-a-workflow.md

* Update content/actions/learn-github-actions/security-hardening-for-github-actions.md

* Update content/actions/reference/authentication-in-a-workflow.md

* Update content/actions/reference/workflow-syntax-for-github-actions.md

* Update content/actions/reference/workflow-syntax-for-github-actions.md

* Update content/actions/reference/workflow-syntax-for-github-actions.md

* Update content/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository.md

* Update content/github/setting-up-and-managing-organizations-and-teams/disabling-or-limiting-github-actions-for-your-organization.md

* Update content/github/setting-up-and-managing-your-enterprise/enforcing-github-actions-policies-in-your-enterprise-account.md

* Update content/packages/guides/using-github-packages-with-github-actions.md

* Make review comment changes (locally)

* Resolve conflicts caused by remotely made review changes

* Remove translation file changes from PR.

* Remove rogue indentation in Important box

* Remove sentence about default being set to restricted.

This *will* be the case for new repos in future,
but that isn't being shipped at the moment.

* Add permissions to workflow examples (#18393)

Co-authored-by: Sarah Edwards <skedwards88@github.com>
2021-04-20 15:49:38 +00:00

4.1 KiB

title, intro, product, versions, type, topics
title intro product versions type topics
Commenting on an issue when a label is added You can use {% data variables.product.prodname_actions %} to automatically comment on issues when a specific label is applied. {% data reusables.gated-features.actions %}
free-pro-team enterprise-server github-ae
* >=2.22 *
tutorial
Workflows
Project management

{% data reusables.actions.enterprise-beta %} {% data reusables.actions.enterprise-github-hosted-runners %} {% data reusables.actions.ae-beta %} {% data reusables.actions.ae-self-hosted-runners-notice %}

Introduction

This tutorial demonstrates how to use the peter-evans/create-or-update-comment action to comment on an issue when a specific label is applied. For example, when the help-wanted label is added to an issue, you can add a comment to encourage contributors to work on the issue.

In the tutorial, you will first make a workflow file that uses the peter-evans/create-or-update-comment action. Then, you will customize the workflow to suit your needs.

Creating the workflow

  1. {% data reusables.actions.choose-repo %}

  2. {% data reusables.actions.make-workflow-file %}

  3. Copy the following YAML contents into your workflow file.

    name: Add comment
    on:
      issues:
        types:
          - labeled
    jobs:
      add-comment:
        if: github.event.label.name == 'help-wanted'
        runs-on: ubuntu-latest{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@3.1" or currentVersion == "github-ae@next" %}
        permissions:
          issues: write{% endif %}
        steps:
          - name: Add comment
            uses: peter-evans/create-or-update-comment@v1
            with:
              issue-number: {% raw %}${{ github.event.issue.number }}{% endraw %}
              body: |
                This issue is available for anyone to work on. **Make sure to reference this issue in your pull request.** :sparkles: Thank you for your contribution! :sparkles:
    
  4. Customize the parameters in your workflow file:

    • Replace help-wanted in if: github.event.label.name == 'help-wanted' with the label that you want to act on. If you want to act on more than one label, separate the conditions with ||. For example, if: github.event.label.name == 'bug' || github.event.label.name == 'fix me' will comment whenever the bug or fix me labels are added to an issue.
    • Change the value for body to the comment that you want to add. GitHub flavored markdown is supported. For more information about markdown, see "Basic writing and formatting syntax."
  5. {% data reusables.actions.commit-workflow %}

Testing the workflow

Every time an issue in your repository is labeled, this workflow will run. If the label that was added is one of the labels that you specified in your workflow file, the peter-evans/create-or-update-comment action will add the comment that you specified to the issue.

Test your workflow by applying your specified label to an issue.

  1. Open an issue in your repository. For more information, see "Creating an issue."
  2. Label the issue with the specified label in your workflow file. For more information, see "Managing labels."
  3. To see the workflow run triggered by labeling the issue, view the history of your workflow runs. For more information, see "Viewing workflow run history."
  4. When the workflow completes, the issue that you labeled should have a comment added.

Next steps