If you ever need to get a list of all GitHub Repositories in your Personal account or Organization Account, There is no option to export the list from GitHub.
Tools Needed
- jq Json Parser
- awk
- sed
- curl
- bash
- tr
Script
#!/bin/bash
# Author: Subramanya Chakravarthy
# Email: subramanya@fyndx.io
# Created Date: 19 Nov 2024
#
USERNAME=<YOUR-GITHUB-USER-NAME>
TOKEN=<GITHUB-API-TOKEN>
# No of reposoitories per page - Maximum Limit is 100
PERPAGE=100
# Change the BASEURL to your Org or User based
# Org base URL
BASEURL="https://api.github.com/orgs/<org-name>/repos"
# User base URL
# BASEURL="https://api.github.com/user/<github-username>/repos"
# Calculating the Total Pages after enabling Pagination
TOTALPAGES=`curl -I -i -u $USERNAME:$TOKEN -H "Accept: application/vnd.github.v3+json" -s ${BASEURL}\?per_page\=${PERPAGE} | grep -i link: 2>/dev/null|sed 's/link: //g'|awk -F',' -v ORS='\n' '{ for (i = 1; i <= NF; i++) print $i }'|grep -i last|awk '{print $1}' | tr -d '\<\>' | tr '\?\&' ' '|awk '{print $3}'| tr -d '=;page'`
i=1
until [ $i -gt $TOTALPAGES ]
do
result=`curl -s -u $USERNAME:$TOKEN -H 'Accept: application/vnd.github.v3+json' ${BASEURL}?per_page=${PERPAGE}\&page=${i} 2>&1`
echo $result > tempfile
echo "Repo Name, SSH URL, Clone URL, Language, Updated at, Pushed at, Archived, Disabled, Default Branch"
cat tempfile|jq '.[]| [.name, .ssh_url, .clone_url, .language, .updated_at, .pushed_at, .archived, .disabled, .default_branch]| @csv'|tr -d '\\"'
((i=$i+1))
done- Create the Script
github-repo-list.shand paste the above contents - Make the script executable by running
chmod a+x github-repos-list.sh - Update the script with user name, org name, token and any necessary data
- Run the script to outpust the csv file
./github-repo-list.sh > output.csv
You can add more information of the repo to the csv. Just add the necessary fields like jq '.[]| [.name, .ssh_url, .clone_url, .created_at, .pushed_at, .language] to the array.
Check the tempfile created by running this script to check what all keys can be added.