Introduction
This 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.
Creating the workflow
-
Escolha um repositório onde você deseja aplicar este fluxo de trabalho de gerenciamento de projetos. Você pode usar um repositório existente ao qual você tem acesso de gravação ou criar um novo repositório. Para saber mais sobre como criar um repositório, confira Criar um repositório.
-
No repositório, crie um arquivo chamado
.github/workflows/YOUR_WORKFLOW.yml
, substituindoYOUR_WORKFLOW
por um nome de sua escolha. Este é um arquivo do fluxo de trabaho. Para saber mais sobre como criar arquivos no GitHub, confira Criar arquivos. -
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 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:
- Replace
help wanted
inif: 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 thebug
orfix 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 Sintaxe básica de gravação e formatação no GitHub.
- Replace
-
Faça o commit do arquivo de fluxo de trabalho para o branch padrão do seu repositório. Para saber mais, confira Criar arquivos.
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 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.
- Open an issue in your repository. For more information, see Criar um problema.
- Label the issue with the specified label in your workflow file. For more information, see Gerenciar etiquetas.
- To see the workflow run triggered by labeling the issue, view the history of your workflow runs. For more information, see Visualizar o histórico de execução do fluxo de trabalho.
- 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 GitHub CLI, like editing existing comments, visit the GitHub CLI Manual.