Last active
December 4, 2024 15:52
-
-
Save yankeyhotel/4248ac0eee8067e85ac8164d4865b187 to your computer and use it in GitHub Desktop.
GitHub: Count all org repos and return repo's names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.