-
-
Save Link-/f817f7523a3ac5de6861efd7be6bc3fb to your computer and use it in GitHub Desktop.
name: Create a comment on new issues | |
on: | |
issues: | |
types: [opened] | |
permissions: write-all | |
jobs: | |
comment-with-action: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "dump github context" | |
run: echo '${{ toJSON(github.event) }}' | jq | |
shell: bash | |
- name: Create comment | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
issue-number: ${{ github.event.issue.number }} | |
body: | | |
This is a multi-line test comment | |
- With GitHub **Markdown** :sparkles: | |
- Created by [create-or-update-comment][1] | |
[1]: https://github.com/peter-evans/create-or-update-comment | |
reactions: '+1' | |
comment-with-api: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create comment with API | |
run: | | |
gh api -X POST \ | |
https://api.github.com/repos/${ORGANIZATION}/${REPOSITORY}/issues/${ISSUE_NUMBER}/comments \ | |
-f body=' | |
Comment but from the API call not action | |
' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
ORGANIZATION: ${{ github.event.organization.login }} | |
REPOSITORY: ${{ github.event.repository.name }} | |
ISSUE_NUMBER: ${{ github.event.issue.number }} |
The action version has been upgraded. Please use peter-evans/create-or-update-comment@v2
The action version has been upgraded. Please use peter-evans/create-or-update-comment@v2
It's on v3
now! :)
this worked. env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ORGANIZATION: ${{ github.event.repository.owner.login }} #JSON structure changed REPOSITORY: ${{ github.event.repository.name }} ISSUE_NUMBER: ${{ github.event.issue.number }}
This changes the API call from a repository belonging to an organisation to one belonging to a specific user. I know many are facing this difficulty but it's not really hard and I encourage everyone to create a free organisation and experiment with it (as opposed to just repositories).
Sometimes it is required to add permission to the Github actions, so you can use :
permissions: write-all
The action version has been upgraded. Please use peter-evans/create-or-update-comment@v2
thx worked with permission: write-all flag
I added the permissions: write-all
- this was created before GITHUB_TOKEN permissions were introduced :)
Nice @Link- thank you for adding it. I was coming from working with Gitlab CICD and your course was a great resource. Also the official docs so thank you
I am currently facing this issue and I will appreciate any help I can get
Run gh api -X POST
gh api -X POST
https://api.github.com/repo/${ORGANIZATION}/${REPOSITORY}/issues/${ISSUE_NUMBER/comments}
-f body=" Comment from Github API Bot"
shell: /usr/bin/bash -e {0}
env:
GITHUB_TOKEN: ***
ORGANIZATION: Gerald-Izuchukwu
REPOSITORY: Meal-Microservice-App
ISSUE_NUMBER: 10
gh: Not Found (HTTP 404)
{"message":"Not Found","documentation_url":"https://docs.github.com/rest"}
Error: Process completed with exit code 1.
You have typos inside of your workflow file. The link should look like this:
https://api.github.com/repos/${ORGANIZATION}/${REPOSITORY}/issues/${ISSUE_NUMBER}/comments
Also, make sure you set up the correct environment variables if you're using a repo inside your account instead of a repo inside an organization(check out Mawulijo's comment).
this worked.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORGANIZATION: ${{ github.event.repository.owner.login }} #JSON structure changed
REPOSITORY: ${{ github.event.repository.name }}
ISSUE_NUMBER: ${{ github.event.issue.number }}