Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use gh issue comment instead of peter-evans/create-or-update-comment #29420

Merged
merged 10 commits into from
Oct 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ shortTitle: Add label to comment on issue

## Introduction

This tutorial demonstrates how to use the [`peter-evans/create-or-update-comment` action](https://github.com/marketplace/actions/create-or-update-comment) 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.
This tutorial demonstrates how to use the [GitHub CLI](https://cli.github.com/manual/) 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.
skedwards88 marked this conversation as resolved.
Show resolved Hide resolved

In the tutorial, you will first make a workflow file that uses the [`peter-evans/create-or-update-comment` action](https://github.com/marketplace/actions/create-or-update-comment). Then, you will customize the workflow to suit your needs.
In the tutorial, you will first make a workflow file that uses the [`gh issue comment`](https://cli.github.com/manual/gh_issue_comment) command. Then, you will customize the workflow to suit your needs.
skedwards88 marked this conversation as resolved.
Show resolved Hide resolved

## Creating the workflow

Expand All @@ -30,38 +30,38 @@ In the tutorial, you will first make a workflow file that uses the [`peter-evans
1. Copy the following YAML contents into your workflow file.

```yaml copy
{% data reusables.actions.actions-not-certified-by-github-comment %}

{% data reusables.actions.actions-use-sha-pinning-comment %}

jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
name: Add comment
on:
issues:
types:
- labeled
jobs:
add-comment:
if: github.event.label.name == 'help-wanted'
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:
run: gh issue comment "$NUMBER" --repo "$REPO" --body "$BODY"
skedwards88 marked this conversation as resolved.
Show resolved Hide resolved
env:
GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
skedwards88 marked this conversation as resolved.
Show resolved Hide resolved
NUMBER: {% raw %}${{ github.event.issue.number }}{% endraw %}
REPO: {% raw %}${{ github.repository }}{% endraw %}
skedwards88 marked this conversation as resolved.
Show resolved Hide resolved
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:
```

1. 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 "[AUTOTITLE](/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)."
- 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 "[AUTOTITLE](/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)."
1. {% 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.
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.

Expand All @@ -72,4 +72,4 @@ Test your workflow by applying your specified label to an issue.

## Next steps

- To learn more about additional things you can do with the `peter-evans/create-or-update-comment` action, like adding reactions, visit the [`peter-evans/create-or-update-comment` action documentation](https://github.com/marketplace/actions/create-or-update-comment).
- To learn more about additional things you can do with the GitHub CLI, like editing existing comments, visit the [GitHub CLI Manual](https://cli.github.com/manual/).
jcbhmr marked this conversation as resolved.
Show resolved Hide resolved
Loading