Search code examples
githubdownloadrepositorygithub-api

How do I download source code of all the versions of a repository on Github using some automated script?


I have details of few public repositories on GitHub. Is there a way to write a script which downloads the source code of all those repositories on to my local machine? While downloading the source code I want all the previous versions of project to be downloaded.

Ex: Project RxJava has about 124 releases as shown here. I want to know if there is a way to write a program which downloads source code of all these 124 releases on to my machine. I don't want to click on download source code button on each of these releases.


Solution

  • This is how I figured the solution:

    1. Using the Repository Search API get the details of required the projects.
    2. This gives you a JSON object which has the below property

      "releases_url": "https://api.github.com/repos/ReactiveX/RxJava/releases",

    3. Use the above url to get a JSON object which describes release details of project

    4. The JSON obtained in step 3 has a property as given below for each version of project

      "zipball_url": "https://api.github.com/repos/ReactiveX/RxJava/zipball/v1.0.8",

    5. Now copy the content from above URL in to an output stream to fetch the required source code.

    6. Sample source code is available here