You can use GitHub Actions to automatically comment on issues when a specific label is applied.
IntroductionThis tutorial demonstrates how to use the GitHub CLI 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. For more information about GitHub CLI, see Using GitHub CLI in workflows.
In the tutorial, you will first make a workflow file that uses the gh issue comment
command to comment on an issue. Then, you will customize the workflow to suit your needs.
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.
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.
Copy the following YAML contents into your workflow file.
YAMLname: 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 run: gh issue comment "$NUMBER" --body "$BODY" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_REPO: ${{ github.repository }} 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:
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
run: gh issue comment "$NUMBER" --body "$BODY"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
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:
Customize the parameters in your workflow file:
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.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.Commit your workflow file to the default branch of your repository. For more information, see Creating new files.
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 gh issue comment
command will add the comment that you specified to the issue.
Test your workflow by applying your specified label to an issue.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4