Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com> Co-authored-by: Melanie Yarbrough <11952755+myarb@users.noreply.github.com>
4.2 KiB
title, intro, redirect_from, versions, type, topics, shortTitle
| title | intro | redirect_from | versions | type | topics | shortTitle | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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. |
|
|
tutorial |
|
Add label to comment on issue |
{% data reusables.actions.enterprise-beta %} {% data reusables.actions.enterprise-github-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
-
{% data reusables.actions.choose-repo %}
-
{% data reusables.actions.make-workflow-file %}
-
Copy the following YAML contents into your workflow file.
{% indented_data_reference reusables.actions.actions-not-certified-by-github-comment spaces=4 %}
{% indented_data_reference reusables.actions.actions-use-sha-pinning-comment spaces=4 %}
name: Add comment
on:
issues:
types:
- labeled
jobs:
add-comment:
if: github.event.label.name == 'help-wanted'
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Add comment
uses: peter-evans/create-or-update-comment@5f728c3dae25f329afbe34ee4d08eef25569d79f
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:
```
- Customize the parameters in your workflow file:
- Replace
help-wantedinif: 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 thebugorfix melabels are added to an issue. - Change the value for
bodyto the comment that you want to add. GitHub flavored markdown is supported. For more information about markdown, see "AUTOTITLE."
- Replace
- {% 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.
- Open an issue in your repository. For more information, see "AUTOTITLE."
- Label the issue with the specified label in your workflow file. For more information, see "AUTOTITLE."
- To see the workflow run triggered by labeling the issue, view the history of your workflow runs. For more information, see "AUTOTITLE."
- When the workflow completes, the issue that you labeled should have a comment added.
Next steps
- To learn more about additional things you can do with the
peter-evans/create-or-update-commentaction, like adding reactions, visit thepeter-evans/create-or-update-commentaction documentation.