Search code examples
githubgithub-api

There is a way to batch archive GitHub repositories based off of a search?


From the answer to a related question I know it's possible to batch clone repositories based on a GitHub search result:

# cheating knowing we currently have 9 pages
for i in {1..9}
do
    curl "https://api.github.com/search/repositories?q=blazor+language:C%23&per_page=100&page=$i" \
     | jq -r '.items[].ssh_url' >> urls.txt
done

cat urls.txt | xargs -P8 -L1 git clone

I also know that the Hub client allows me to make API calls.

hub api [-it] [-X METHOD] [-H HEADER] [--cache TTL] ENDPOINT [-F FIELD|--input FILE]

I guess the last step is, how do I archive a repository with Hub?


Solution

  • hub seems to have been superseded by the gh cli for api usage.

    the gh cli does contain a repo archive feature

    Here's an updated script to bulk archive using gh instead:

    read -r -d '' TO_ARCHIVE <<EOF
    org/repo1
    org/repo2
    EOF
    
    echo $TO_ARCHIVE | xargs -n 1 -I {} gh repo archive {} -y