git 有没有办法以编程方式获取私有 github 存储库的压缩包?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9504791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:33:05  来源:igfitidea点击:

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

gitoauthgithubrepository

提问by jayarjo

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/master). But what about private repos? Not exactly obvious how to do it even having oAuth token.

我们有必要获取私人回购的 zipball。对于公共的,通过 GitHub API 或手动(https://github.com/user/repo/zipball/master)非常容易。但是私人回购呢?即使有 oAuth 令牌,也不完全清楚如何做到这一点。

回答by roychri

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.

因为给定的接受答案不再有效,我想我会解释我是如何通过 github API 中的新更改来做到这一点的。

The new Download Api Link

新的下载 Api 链接

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

首先,我在这里找到了有关下载存档的信息: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.

如果它是私有存储库,则需要通过转到设置然后选择“开发人员设置”/“个人访问令牌”来创建 oAuth 令牌。我创建了一个个人令牌。

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

然后使用以下页面上的说明,我发现了如何获取您有权访问的私有仓库: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.

请务必ab499f3b...用您的实际令牌替换。

回答by highvolt

Edit:This no longer works.

编辑:这不再有效。



with CURL:

带卷曲:

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

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

$TOKENgithub 配置文件上的 API 令牌在哪里,而不是用于与 APIv3 通信的 oAuth2 令牌。

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

$USER是令牌所连接的用户帐户,不一定是回购所属的组织/其他用户。第二个实例$USER是存储库所在的用户/帐户。

$REPOis the name of the private repository

$REPO是私有存储库的名称

$PKGTYPEis tarball or zipball and $BRANCHorTAGis a branch, like master, or a tag name for a commit.

$PKGTYPE是 tarball 或 zipball 并且$BRANCHorTAG是一个分支,如 master 或提交的标记名称。

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

的第一个实例$USER必须有权访问属于 的第二个实例的存储库$USER

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

我在任何地方都找不到这个文档,所以如果你想要更详细的内容,我也会写一些关于它的文章。

回答by link

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

我遇到了同样的问题,这对我有用(截至 2015 年 2 月):

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.

oAuth 作为标题解决方案对我不起作用,但有效的是将密钥填充到用户名中并指定类型。然后它给出了一个 302 以使用正确的链接重定向。

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

Verbose 命令确实帮助我解决了我使用的凭据是否被接受的问题(404 vs 401)

回答by jjNford

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.

从私人存储库获取 zipball 以供下载似乎没有问题。我使用您指定的相同格式,并且效果很好。

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 applicationI do this in.

我使用 OAuth2 来获取存储库,但我使用您提供的格式构建了 zip 球的链接。 这是我在其中执行此操作的应用程序

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

如果您想获得 OAuth2 令牌,只需使用GitHubt API v3格式,这非常简单。虽然这并不完全符合您的问题:

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

就是我从 GitHub 为这个 chrome 扩展获取 OAuth2 令牌的方式

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...

@jayarjo我在第 202 行建立了 URL。我只是像你指定的那样构建 URL,OAuth2 令牌甚至没有用于它。我的所有令牌允许我在创建标记之前获取所有用户的私人数据。但它的工作没有问题......

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.

我认为我实际上能够下载 zipball 的原因是因为 URL 实际上是https://github.com/*并且因为我目前由于 OAuth2 而登录,我有权访问该 URL - 其中作为听起来你没有,所以你会收到 404 错误。

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.

您可以尝试向页面发送请求,如果您收到错误响应提示用户先登录,那么当您请求 zipball 时,您应该没问题。

回答by jnlin

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

您可以使用基本身份验证或基于令牌的方法。有关更多详细信息,请参阅https://help.github.com/articles/downloading-files-from-the-command-line