GitHub AE is currently under limited release. Please contact our Sales Team to find out more.

Commenting on an issue when a label is added

You can use GitHub Actions to automatically comment on issues when a specific label is applied.

GitHub Actions is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, GitHub Enterprise Server, and GitHub AE. GitHub Actions is not available for private repositories owned by accounts using legacy per-repository plans.

In this article

Note: GitHub Actions is currently in beta for GitHub AE.

Warning: Self-hosted runners are currently disabled for GitHub AE. This is because GitHub AE offers guarantees for security boundaries which are incompatible with how self-hosted runners work. However, if you do need to use self-hosted runners with GitHub AE and understand the security implications, you can contact GitHub support for a security exception that will enable self-hosted runners.

If you don't need self-hosted runners, then you can use AE hosted runners to run your workflows. For more information, see "About AE hosted runners."

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. Choose a repository where you want to apply this project management workflow. You can use an existing repository that you have write access to, or you can create a new repository. For more information about creating a repository, see "Creating a new repository."

  2. In your repository, create a file called .github/workflows/YOUR_WORKFLOW.yml, replacing YOUR_WORKFLOW with a name of your choice. This is a workflow file. For more information about creating new files on GitHub, see "Creating new files."

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

    YAML
    name: Add comment
    on:
      issues:
        types:
          - labeled
    jobs:
      add-comment:
        if: github.event.label.name == 'help-wanted'
        runs-on: ubuntu-latest
        steps:
          - name: Add comment
            uses: peter-evans/create-or-update-comment@v1
            with:
              issue-number: ${{ github.event.issue.number }}
              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. Commit your workflow file to the default branch of your repository. For more information, see "Creating new files."

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

Did this doc help you?

Privacy policy

Help us make these docs great!

All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

Or, learn how to contribute.