I would like to automatically close the issue once it is created. For this I referred to Actions marketplace and this action. Currently my code in YAML file looks like below. GitHub token is saved in Actions >> Secrets sections, and it is Private repository. Every time I run below code I am receiving this error GraphQL: Could not resolve to an issue or pull request with the number of 1. (repository.issue)
. I do not understand why workflow is complaining about Could not resolve an issue? Any setting I need to perform in my GitHub repo for issue to be close automatically?
name: CI
on:
issues:
types:
- opened
jobs:
titlePrefixCheck:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set repo
run: gh repo set-default user/private-repo
- name: Close Issue
run: gh issue close --comment "Auto-closing issue" "1"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2
Answers
For Future Stackoverflow reader- The way I solved my issue that I mention to Azeem in comment section was by updating Workflow permissions under Settings >> Actions >> General >> Workflow permissions from Read repository contents and packages permissions to Read and write permissions
The number "1" is not a valid issue number in that repository.
The
issues
trigger’s webhook payload hasissue.number
that’ll give the issue number of the newly opened issue. So, you can usegithub.event.issue.number
to refer to that.Example:
For your described use case, the checkout step is not needed at all. You can simply specify the repository with
gh issue close
command using-R
/--repo
flag and that should be enough.