github-ops
GitHub REST API integration for managing repositories, issues, pull requests, and Actions workflows.
Setup
-
Create a Personal Access Token at https://github.com/settings/tokens
-
Required scopes: repo , workflow , read:user (minimum)
-
Store in environment: GH_TOKEN=ghp_xxx
API Basics
All requests need:
curl -H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
-H "X-GitHub-Api-Version: 2022-11-28"
https://api.github.com/...
Common Operations
Get authenticated user
curl -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/user
List user repos
curl -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/user/repos
Get repo
curl -H "Authorization: Bearer $GH_TOKEN" https://api.github.com/repos/{owner}/{repo}
Create issue
curl -X POST
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/issues
-d '{"title":"Bug report","body":"Description"}'
List issues
curl -H "Authorization: Bearer $GH_TOKEN"
https://api.github.com/repos/{owner}/{repo}/issues?state=open
Get issue
curl -H "Authorization: Bearer $GH_TOKEN"
https://api.github.com/repos/{owner}/{repo}/issues/{number}
Update issue
curl -X PATCH
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/issues/{number}
-d '{"state":"closed"}'
Add comment to issue
curl -X POST
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/issues/{number}/comments
-d '{"body":"My comment"}'
Create PR
curl -X POST
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/pulls
-d '{"title":"New feature","head":"feature-branch","base":"main"}'
List PRs
curl -H "Authorization: Bearer $GH_TOKEN"
https://api.github.com/repos/{owner}/{repo}/pulls?state=open
Get workflow runs
curl -H "Authorization: Bearer $GH_TOKEN"
https://api.github.com/repos/{owner}/{repo}/actions/runs?status=in_progress
Trigger workflow
curl -X POST
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
-d '{"ref":"main"}'
Add labels to issue
curl -X POST
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/issues/{number}/labels
-d '{"labels":["bug","critical"]}'
Remove label from issue
curl -X DELETE
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/issues/{number}/labels/{label_name}
Get PR reviews
curl -H "Authorization: Bearer $GH_TOKEN"
https://api.github.com/repos/{owner}/{repo}/pulls/{number}/reviews
Create PR review
curl -X POST
-H "Authorization: Bearer $GH_TOKEN"
-H "Accept: application/vnd.github+json"
https://api.github.com/repos/{owner}/{repo}/pulls/{number}/reviews
-d '{"body":"LGTM","event":"APPROVE"}'
Notes
-
Repository owner/repo format: owner/repo (e.g., octocat/Hello-World )
-
Rate limits: 5000 requests/hour for authenticated users
-
All timestamps are ISO 8601 format