{"id":19138146,"url":"https://github.com/locus313/github-api-scripts","last_synced_at":"2026-05-13T13:46:01.755Z","repository":{"id":48443246,"uuid":"382846115","full_name":"locus313/github-api-scripts","owner":"locus313","description":"Bash scripts to work with the Github API","archived":false,"fork":false,"pushed_at":"2024-09-02T23:43:47.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-03T14:17:21.607Z","etag":null,"topics":["github","github-api"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/locus313.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["locus313"]}},"created_at":"2021-07-04T12:26:25.000Z","updated_at":"2024-09-02T23:43:50.000Z","dependencies_parsed_at":"2022-09-12T20:50:47.253Z","dependency_job_id":null,"html_url":"https://github.com/locus313/github-api-scripts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locus313%2Fgithub-api-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locus313%2Fgithub-api-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locus313%2Fgithub-api-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/locus313%2Fgithub-api-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/locus313","download_url":"https://codeload.github.com/locus313/github-api-scripts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240221236,"owners_count":19767442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","github-api"],"created_at":"2024-11-09T06:41:54.023Z","updated_at":"2026-05-13T13:46:01.747Z","avatar_url":"https://github.com/locus313.png","language":"Shell","funding_links":["https://github.com/sponsors/locus313"],"categories":[],"sub_categories":[],"readme":"# GitHub API Scripts\r\n\r\n[![License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](LICENSE)\r\n![Shell](https://img.shields.io/badge/Shell-Bash-89e051?style=flat-square\u0026logo=gnu-bash\u0026logoColor=white)\r\n[![GitHub API](https://img.shields.io/badge/GitHub_API-v3-blue?style=flat-square\u0026logo=github)](https://docs.github.com/en/rest)\r\n\r\n⭐ If you like this project, star it on GitHub — it helps a lot!\r\n\r\n[Overview](#overview) • [Getting started](#getting-started) • [Scripts](#scripts) • [Resources](#resources)\r\n\r\nA collection of standalone bash scripts for GitHub organization administration. Automate common tasks like bulk permission management, repository creation, migration, and reporting using simple, self-contained utilities powered by the GitHub REST API.\r\n\r\n## Overview\r\n\r\nThis toolkit provides ready-to-use automation scripts for GitHub organization administrators. Each script is a complete, independent utility—no shared libraries or frameworks. Just drop in your token and organization name, and you're ready to go.\r\n\r\n**What you can do:**\r\n- Grant team permissions across all repositories in bulk\r\n- Create repositories from templates with pre-configured access\r\n- Mirror repositories with full git history\r\n- Generate monthly issue reports with contributor statistics\r\n- Track license consumption for enterprise accounts\r\n\r\n**What you can do:**\r\n- Grant team permissions across all repositories in bulk\r\n- Create repositories from templates with pre-configured access\r\n- Mirror repositories with full git history\r\n- Generate monthly issue reports with contributor statistics\r\n- Track license consumption for enterprise accounts\r\n\r\n**Built with simplicity:** Each script uses only `curl` for API requests and `jq` for JSON processing—no complex dependencies, no installation required beyond standard Unix tools.\r\n\r\n\u003e [!NOTE]\r\n\u003e These scripts follow a convention-over-configuration approach. Each lives in its own directory as a single `.sh` file with built-in validation and error handling.\r\n\r\n## Getting started\r\n\r\n### Prerequisites\r\n\r\n- **bash** 4+\r\n- **[curl](https://curl.se)** - HTTP client for API requests\r\n- **[jq](https://stedolan.github.io/jq)** - Command-line JSON processor\r\n- **[git](https://git-scm.com)** - For repository operations (required by some scripts)\r\n- **[gh](https://cli.github.com)** - GitHub CLI (required by `github-organize-stars`)\r\n- **GitHub Personal Access Token** with appropriate scopes\r\n\r\n### Installation\r\n\r\nClone the repository:\r\n\r\n```bash\r\ngit clone https://github.com/locus313/github-api-scripts.git\r\ncd github-api-scripts\r\n```\r\n\r\nAlternatively, download individual scripts as needed—each script is standalone and can be used independently.\r\n\r\n### Authentication\r\n\r\nCreate a GitHub Personal Access Token at [github.com/settings/tokens](https://github.com/settings/tokens) with these scopes:\r\n\r\n- `repo` - Full control of repositories\r\n- `admin:org` - Organization administration\r\n- `read:enterprise` - Read enterprise data (for license scripts)\r\n\r\nExport your token as an environment variable:\r\n\r\n```bash\r\nexport GITHUB_TOKEN=\"ghp_your_token_here\"\r\n```\r\n\r\n\u003e [!TIP]\r\n\u003e Add this export to your `~/.bashrc` or `~/.zshrc` to persist the token across terminal sessions.\r\n\r\n### Configuration\r\n\r\nScripts use environment variables for configuration. Common variables include:\r\n\r\n| Variable | Description | Required |\r\n|----------|-------------|----------|\r\n| `GITHUB_TOKEN` | GitHub personal access token | Yes |\r\n| `ORG` | Organization name | Yes (most scripts) |\r\n| `API_URL_PREFIX` | GitHub API base URL (default: `https://api.github.com`) | No |\r\n| `GIT_URL_PREFIX` | GitHub base URL (default: `https://github.com`) | No |\r\n\r\n\u003e [!NOTE]\r\n\u003e The `*_PREFIX` variables support GitHub Enterprise Server. Set them to your enterprise domain to use these scripts with GHES.\r\n\r\n## Scripts\r\n\r\nEach script is a self-contained utility designed for a specific task. Navigate to the script's directory, set the required environment variables, and execute.\r\n\r\n### Add Repository Permissions\r\n\r\n**Script:** `github-add-repo-permissions/github-add-repo-permissions.sh`\r\n\r\nGrants team permissions across all repositories in an organization. Supports multiple permission levels (admin, maintain, push, triage, pull) and multiple teams per permission level.\r\n\r\n**Required variables:**\r\n```bash\r\nexport GITHUB_TOKEN=\"your_token\"\r\nexport ORG=\"your-org\"\r\n\r\n# Set one or more permission levels (space-separated team slugs)\r\nexport REPO_ADMIN=\"platform-team ops-team\"      # Admin permissions\r\nexport REPO_MAINTAIN=\"maintainers\"              # Maintain permissions\r\nexport REPO_PUSH=\"developers contributors\"      # Write/push permissions\r\nexport REPO_TRIAGE=\"support-team\"               # Triage permissions\r\nexport REPO_PULL=\"external-auditors\"            # Read/pull permissions\r\n```\r\n\r\n**Usage:**\r\n```bash\r\ncd github-add-repo-permissions\r\n./github-add-repo-permissions.sh\r\n```\r\n\r\n**What it does:**\r\n- Retrieves all repositories in the organization (paginated)\r\n- Grants permissions to specified teams based on permission level\r\n- Supports multiple teams per permission level (space-separated)\r\n- Processes all five GitHub permission levels: admin, maintain, push, triage, pull\r\n- Includes 5-second delays between repos to avoid rate limits\r\n\r\n**Permission levels:**\r\n- `admin` - Full repository access including settings and team management\r\n- `maintain` - Repository management without admin privileges\r\n- `push` - Read and write access to code\r\n- `triage` - Read access plus ability to manage issues and pull requests\r\n- `pull` - Read-only access to code\r\n\r\n\u003e [!NOTE]\r\n\u003e At least one permission level must be set. Team slugs should be lowercase and hyphenated (e.g., \"Platform Team\" → `platform-team`).\r\n\r\n---\r\n\r\n### Create Repository from Template\r\n\r\n**Script:** `github-repo-from-template/github-repo-from-template.sh`\r\n\r\nCreates a new repository from a template with pre-configured team permissions and collaborator access.\r\n\r\n**Required variables:**\r\n```bash\r\nexport GITHUB_TOKEN=\"your_token\"\r\nexport ORG=\"your-org\"\r\nexport TEMPLATE_REPO=\"template-repo\"\r\nexport REPO_ADMIN=\"admins platform-team\"     # Space-separated team slugs\r\nexport REPO_WRITE=\"developers contributors\"  # Space-separated team slugs\r\nexport CD_USERNAME=\"ci-bot\"\r\nexport CD_GITHUB_TOKEN=\"bot_token\"\r\n```\r\n\r\n**Usage:**\r\n```bash\r\ncd github-repo-from-template\r\n./github-repo-from-template.sh new-project-name\r\n```\r\n\r\n**What it does:**\r\n- Creates a private repository from the specified template\r\n- Includes all branches from the template\r\n- Assigns admin permissions to teams in `REPO_ADMIN`\r\n- Assigns write permissions to teams in `REPO_WRITE`\r\n- Invites CD user as collaborator and auto-accepts the invitation\r\n\r\n---\r\n\r\n### Import Repository\r\n\r\n**Script:** `github-import-repo/github-import-repo.sh`\r\n\r\nPerforms a full repository mirror—clones source repo and pushes all branches, tags, and history to a new destination repo.\r\n\r\n**Required variables:**\r\n```bash\r\nexport GITHUB_TOKEN=\"your_token\"\r\nexport ORG=\"your-org\"\r\nexport OWNER_USERNAME=\"admin-user\"\r\n```\r\n\r\n**Usage:**\r\n```bash\r\ncd github-import-repo\r\n./github-import-repo.sh source-repo destination-repo\r\n```\r\n\r\n**What it does:**\r\n- Creates a new internal repository\r\n- Performs bare clone of source repository\r\n- Mirrors all git objects to destination\r\n- Grants admin permissions to specified owner\r\n- Cleans up local temporary clone\r\n\r\n\u003e [!WARNING]\r\n\u003e This creates a complete copy with full git history. Ensure you have sufficient disk space and network bandwidth for large repositories.\r\n\r\n---\r\n\r\n### Monthly Issues Report\r\n\r\n**Script:** `github-monthly-issues-report/github-monthly-issues-report.sh`\r\n\r\nGenerates HTML-formatted statistics about issues created within a date range, filtered by labels.\r\n\r\n**Required variables:**\r\n```bash\r\nexport GITHUB_TOKEN=\"your_token\"\r\nexport ORG=\"your-org\"\r\nexport REPO=\"your-repo\"\r\nexport MONTH_START=\"2025-10-01\"\r\nexport MONTH_END=\"2025-10-31\"\r\n```\r\n\r\n**Usage:**\r\n```bash\r\ncd github-monthly-issues-report\r\n./github-monthly-issues-report.sh\r\n```\r\n\r\n**What it does:**\r\n- Filters issues by creation date range\r\n- Filters by label (currently hardcoded to `Linked [AC]`)\r\n- Uses timeline API to track who applied labels\r\n- Generates author and contributor statistics\r\n- Outputs HTML report to `output.txt`\r\n\r\n\u003e [!NOTE]\r\n\u003e This script includes a hardcoded label filter. Edit the script to modify the filter criteria.\r\n\r\n---\r\n\r\n### Get Consumed Licenses\r\n\r\n**Script:** `github-get-consumed-licenses/github-get-consumed-licenses.sh`\r\n\r\nRetrieves license consumption metrics for a GitHub Enterprise account.\r\n\r\n**Required variables:**\r\n```bash\r\nexport GITHUB_TOKEN=\"your_enterprise_token\"  # Must have read:enterprise scope\r\nexport ENTERPRISE=\"your-enterprise\"\r\n```\r\n\r\n**Usage:**\r\n```bash\r\ncd github-get-consumed-licenses\r\n./github-get-consumed-licenses.sh\r\n```\r\n\r\n**Output:**\r\n```\r\nTotal seats consumed: 150\r\nTotal seats purchased: 200\r\n```\r\n\r\n**What it does:**\r\n- Calls the enterprise consumed-licenses endpoint\r\n- Uses Bearer token authentication (unlike other scripts)\r\n- Returns seat consumption and purchase counts\r\n\r\n\u003e [!IMPORTANT]\r\n\u003e This script requires an enterprise-level token with `read:enterprise` scope. Organization tokens will not work.\r\n\r\n---\r\n\r\n### Organize Starred Repositories\r\n\r\n**Script:** `github-organize-stars/github-organize-stars.sh`\r\n\r\nFetches all your starred repositories and organizes them into GitHub Lists using customizable categorization rules.\r\n\r\n**Prerequisites:**\r\n- **[gh](https://cli.github.com)** - GitHub CLI (authenticated via `gh auth login`)\r\n- **[jq](https://stedolan.github.io/jq)** - Command-line JSON processor\r\n\r\n**Usage:**\r\n```bash\r\ncd github-organize-stars\r\n./github-organize-stars.sh              # Interactive (shows plan, asks to confirm)\r\n./github-organize-stars.sh --dry-run    # Preview only, no changes made\r\n./github-organize-stars.sh -y           # Skip confirmation prompt\r\n./github-organize-stars.sh --show-repos # Also list repo names in each category\r\n./github-organize-stars.sh --no-cache   # Force re-fetch stars from GitHub\r\n```\r\n\r\n**What it does:**\r\n- Fetches all starred repositories via the GraphQL API (paginated)\r\n- Categorizes each repo by primary language, GitHub topics, and repo name keywords\r\n- Creates new GitHub Lists and adds repos in batches of 25\r\n- Caches fetched stars locally at `~/.cache/gh-star-organizer/stars.json` to speed up re-runs\r\n- Shows a categorization plan and prompts for confirmation before making changes\r\n\r\n**Customizing categories:**\r\n\r\nEdit the `RULES` array in the script. Each rule is a `|`-delimited string:\r\n```\r\n\"List Name|LANGUAGES|TOPICS|NAME_KEYWORDS\"\r\n```\r\n- `LANGUAGES` — comma-separated primary language names (case-insensitive)\r\n- `TOPICS` — comma-separated GitHub topic slugs\r\n- `NAME_KEYWORDS` — comma-separated substrings matched against the repo name\r\n\r\nThe **first matching rule wins**, so order matters. Place more specific rules (e.g., AI) before general ones (e.g., Security).\r\n\r\n\u003e [!NOTE]\r\n\u003e This script uses the `gh` CLI for all API calls (GraphQL) rather than `curl`. Ensure you are authenticated via `gh auth login` before running.\r\n\r\n## Best Practices\r\n\r\n**Test on a test organization first**\r\nThese scripts have no dry-run mode. Always validate on a non-production organization before running against production resources.\r\n\r\n**Rate limiting**\r\nScripts include built-in delays (5 seconds between repository operations) to stay within GitHub's rate limits. For large organizations with hundreds of repos, expect longer execution times.\r\n\r\n**Audit trails**\r\nCapture output for compliance and troubleshooting:\r\n```bash\r\n./script.sh 2\u003e\u00261 | tee execution-$(date +%Y%m%d).log\r\n```\r\n\r\n**Team slugs vs display names**\r\nGitHub API uses team slugs (lowercase, hyphenated). Example: \"Platform Team\" → `platform-team`. Find team slugs in your organization settings or via the API.\r\n\r\n**GitHub Enterprise Server**\r\nThese scripts support GHES. Set custom endpoints:\r\n```bash\r\nexport API_URL_PREFIX=\"https://github.company.com/api/v3\"\r\nexport GIT_URL_PREFIX=\"https://github.company.com\"\r\n```\r\n\r\n## Resources\r\n\r\n- [GitHub REST API Documentation](https://docs.github.com/en/rest)\r\n- [Creating a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)\r\n- [jq Manual](https://stedolan.github.io/jq/manual/)\r\n- [GitHub API Rate Limits](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocus313%2Fgithub-api-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocus313%2Fgithub-api-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocus313%2Fgithub-api-scripts/lists"}