| title | GitHub API for PR and Issue Management | |||||
|---|---|---|---|---|---|---|
| domain | devops | |||||
| tags |
|
|||||
| status | published | |||||
| source | agent_experience | |||||
| created | 2026-07-02 |
Need to manage PRs and issues programmatically via GitHub API when gh CLI is not authenticated or unavailable.
GitHub REST API v3 allows full CRUD operations on PRs, issues, and comments using personal access tokens (PAT). The API endpoints follow predictable patterns:
- Issues:
GET/POST/PATCH /repos/{owner}/{repo}/issues/{number} - PRs:
GET/POST/PATCH /repos/{owner}/{repo}/pulls/{number} - Comments:
GET/POST /repos/{owner}/{repo}/issues/{number}/comments - Merge:
PUT /repos/{owner}/{repo}/pulls/{number}/merge
# Extract token from git credentials
TOKEN=$(cat ~/.git-credentials | grep -i "github.com" | head -1 | sed 's/.*:\/\/[^:]*:\([^@]*\)@.*/\1/')
# Or set directly
TOKEN="ghp_xxxxxxxxxxxx"curl -s -X POST \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/issues \
-d '{"title":"Issue title","body":"Issue body","labels":["bug"]}'curl -s -X PATCH \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/issues/{number} \
-d '{"state":"closed","state_reason":"completed"}'curl -s -X POST \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/issues/{number}/comments \
-d '{"body":"Comment text"}'curl -s -X PUT \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/pulls/{number}/merge \
-d '{"merge_method":"squash","commit_title":"Title","commit_message":"Message"}'curl -s -X PATCH \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/{owner}/{repo}/pulls/{number} \
-d '{"state":"closed"}'- Test API connectivity:
curl -s -H "Authorization: token $TOKEN" https://api.github.com/user - Verify issue creation: check
html_urlin response - Verify PR merge: check
"merged": truein response
- Use
jqfor JSON parsing:curl ... | jq '.html_url' - Rate limit: 5000 requests/hour for authenticated users
- For large bodies, use JSON file:
-d @/tmp/issue.json