Skip to content

Instantly share code, notes, and snippets.

@yankeyhotel
Last active December 4, 2024 15:52
Show Gist options
  • Save yankeyhotel/4248ac0eee8067e85ac8164d4865b187 to your computer and use it in GitHub Desktop.
Save yankeyhotel/4248ac0eee8067e85ac8164d4865b187 to your computer and use it in GitHub Desktop.
GitHub: Count all org repos and return repo's names
#!/bin/bash
# Replace with your GitHub Personal Access Token
GITHUB_TOKEN="your_personal_access_token"
# Replace with your organization's name
ORG_NAME="your_org_name"
# Define the API URL and search query
API_URL="https://api.github.com/search/repositories"
QUERY="org:$ORG_NAME created:2024-01-01..2024-12-31"
# Make the API request
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/search/repositories?q=org:$ORG_NAME+created:2024-01-01..2024-12-31")
# echo "$response"
# Extract the total count using jq
total_count=$(echo "$response" | jq '.total_count')
# Print the result
if [ "$total_count" != "null" ]; then
echo "Total repositories created in 2024 for $ORG_NAME: $total_count"
# Extract and print the repository names
echo "Repositories:"
echo "$response" | jq -r '.items[].name'
else
echo "No repositories found for $ORG_NAME in 2024, or an error occurred."
fi
@yankeyhotel
Copy link
Author

To run the file you will need to install jq.
$ brew install jq

Update file permissions
$ chmod +x repo_count.sh

Run file
$ ./repo_count.sh

To get the Github Token, use Classic Token here https://github.com/settings/tokens.

And add the required scopes Required on the token (classic)

  • repo Grants access to both public and private repositories that you own or collaborate on.
  • read:org Grants access to organization-level information, required for querying organization repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment