← github actions
Views:
Creating comments on issues opened
We can create a workflow to automate and comment on issues opened. The prerequisite for this is a PAT (Personal Access Token), which you have to create and store in github secrets and pass it in the workflow to make it authorized to create a comment.
Creating a PAT (Personal Access Token)
- Go to settings > tokens
- Click Generate new token and create a classic token with repo access
- Once token is generated, copy it and keep it somewhere safe.
You can also go through the official documentation for creating a personal access token.
Adding PAT to Github Actions Secret
- Open your repository and go to Settings tab
- Go to Security > Secrets and variables > Actions
- Click on New repository secret
- Enter desired key in name and PAT in secret
You can also go through the official documentation for adding github action secret
Once you're done with adding your Personal Access Token in your github action secret, you can proceed with writing the workflow for creating comments when an issue is opened.
name: Issue Comment
on:
issues:
types: [opened]
jobs:
issue-comment:
runs-on: ubuntu-latest
steps:
- name: Adding Comment to Issues Openend
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_ACTION_EXAMPLES_PAT }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thanks for reporting an issue.'
})
Result
Following is the output for the above workflow-
