Search code examples
gitcurlgithubclone

How to filter language for cloning multiple GitHub repositories with curl?


I am working in an organization with about 500 repositories in enterprise GitHub. I found some curl to clone all of the repositories at once but I cannot seem to find a way to filter the script by language. This is the curl I am using:

curl -s -H "Authorization: token [token]" https://github.[company].com/api/v3/orgs/[organization]/repos?page=1&per_page=100 | jq '.[].ssh_url' | xargs -n 1 git clone

It works fine to clone every repo but obviously that is not efficient when I just need specific languages. I have tried every variation I have seen suggested in my searches, such as including the /search/repositories/ string, and ?language= and ?q=language: parameters in the URL. It just skips the filter completely and still returns the full list of repos, results in a basic JSON response for the organization, or it comes back with a "Not Found" message.

Does anyone know how to filter by language in this instance, or maybe have a better solution for cloning multiple repos filtered by language? I am trying to automate some processes in Jenkins and/or Docker that need to search and parse across all of the target repos.

Thanks


Solution

  • I don't know whether or not it's possible to filter this as part of the API request, but you can certainly perform the filtering with jq. For example, I can get a list of SSH urls for my Python projects like this:

    curl -s -H "Authorization: token $token" https://api.github.com/user/repos |
      jq  '.[]|select(.language = "Python").ssh_url'