Skip to content

Instantly share code, notes, and snippets.

@Link-
Last active August 19, 2024 15:24
Show Gist options
  • Save Link-/f817f7523a3ac5de6861efd7be6bc3fb to your computer and use it in GitHub Desktop.
Save Link-/f817f7523a3ac5de6861efd7be6bc3fb to your computer and use it in GitHub Desktop.
Write your first workflow with GitHub Actions and GitHub APIs - beginner friendly tutorial!
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 }}
@djole-kuzma
Copy link

@Gerald-Izuchukwu

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment