Is there anyway to programmatically fetch a zipball of private github repo?

后端 未结 5 389
伪装坚强ぢ
伪装坚强ぢ 2020-12-24 06:10

We got a necessity to fetch a zipball of a private repo. For public ones it\'s pretty easy either through GitHub API or manually (https://github.com/user/repo/zipball/ma

相关标签:
5条回答
  • 2020-12-24 06:32

    Edit: This no longer works.


    with CURL:

    curl -L -F "login=$USER" -F "token=$TOKEN" https://github.com/$USER/$REPO/$PKGTYPE/$BRANCHorTAG
    

    where $TOKEN is the API token on your github profile, not an oAuth2 token used for communicating with the APIv3.

    $USER is the user account the token is connected with, not necessarily the organization/other user the repo belongs to. Second Instance of $USER is the user/account the repo is.

    $REPO is the name of the private repository

    $PKGTYPE is tarball or zipball and $BRANCHorTAG is a branch, like master, or a tag name for a commit.

    The first instance of $USER must have access to the repo belonging to the second instance of $USER.

    I could not find this documented ANYWHERE, so I also have a little write up about it if you want anything more detailed.

    0 讨论(0)
  • 2020-12-24 06:49

    You can use Basic Authentication or Token based method. See https://help.github.com/articles/downloading-files-from-the-command-line for more details.

    0 讨论(0)
  • 2020-12-24 06:50

    I don't seem to have a problem getting a zipball from the private repos for download. I use the same format you have specified and it works perfectly.

    I use OAuth2 to get the repositories but I build the link for the zip ball using the format you have given. Here is the application I do this in.

    If you are looking to get an OAuth2 token, just use the GitHubt API v3 format, it is pretty simple. Although this doesn't fit your problem exactly :

    This is how I get an OAuth2 token from GitHub for this chrome extension

    UPDATE

    @jayarjo I build the URL here on line 202. I just build the URL like the one you specified, the OAuth2 token isn't even used for it. All my token allows me to do is fetch all the users private data before I create the markup. But it works with no problem...

    I think the reason I am actually able to download the zipball is because the URL is actually to https://github.com/* and because I am currently signed in because of the OAuth2 I have permission to get to that URL - where as it sounds like you don't so you get a 404 error.

    You may try sending a request to the page and if you get an error response prompt the user to login first, then when you request the zipball you should get it no problem.

    0 讨论(0)
  • 2020-12-24 06:51

    New Alternative

    Because the given accepted answer does not work anymore, I thought I would explain how I was able to do it with the new changes in the github API.

    The new Download Api Link

    First, I found information about downloading the archive here: https://developer.github.com/v3/repos/contents/#get-archive-link

    Public Repo

    If it's a public repo then it is very easy... you can do:

    curl -L https://api.github.com/repos/pengwynn/octokit/tarball > octokit.tar.gz
    

    Private Repo

    If it's it is a private repo, you need to create an oAuth token by going to your settings and then selecting "Developer settings" / "Personal access tokens". I created a personal token.

    Then using the instructions on the following page I found out how to get private repo that you have permission to: https://developer.github.com/v3/#authentication

    Full Code

    curl -H "Authorization: token ab499f3b..." \
    -L https://api.github.com/repos/godzilla/my_priv_repo/tarball > wut.tar.gz
    

    Be sure to replace ab499f3b... with your actual token.

    0 讨论(0)
  • 2020-12-24 06:58

    I came across the same problem and this worked for me (as of Feb 2015):

    curl -O -J -L -u $YOUROAUTHKEY:x-oauth-basic https://github.com/$USER/$REPO/archive/master.zip
    

    The oAuth as a header solutions didn't work for me but what worked was stuffing the key into the username and specifying type. It then gave a 302 to redirect with the proper link.

    Verbose command really helped me troubleshoot whether the credentials I was using were being accepted or not (404 vs 401)

    0 讨论(0)
提交回复
热议问题