GitHub action workflow can be setup to set a lable to any newly created issue, using below code. If we want to add a lable "triage" to a new issue once opened we can create below workflow.
on:
issues:
types:
- opened
jobs:
label_issue:
runs-on: ubuntu-latest
steps:
- env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_URL: ${{ github.event.issue.html_url }}
run: |
gh issue edit $ISSUE_URL --add-label "triage"
HHowever, you may see error "GraphQL: Resource not accessible by integration (addLabelsToLabelable)", when the workflow is executed. Let's see how we can resolve the issue in this post.
The permisson issue occurs here, because GITHUB_TOKEN is not having sufficient permision to edit issue and add a lablel to it. To fix the issue we have to go to settings of the repo, expand Actions --> General. For workflow permisions, selcet the option Read and write permisions and save.
Once the permisions is updated, we can create a new issue and that will trigger a new workflow run, which will set the label "triage" to the new issue.
No comments:
Post a Comment