有没有办法以编程方式获取私有 github 存储库的压缩包? [英] Is there anyway to programmatically fetch a zipball of private github repo?
问题描述
我们需要获取一个私有仓库的压缩包.对于公共的,通过 GitHub API 或手动 (https://github.com/user/repo/zipball/master) 非常容易.但是私人回购呢?即使有 oAuth 令牌,也不完全清楚如何做到这一点.
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.
推荐答案
New Alternative
因为给定的已接受答案不再有效,我想我会解释如何使用 github API 中的新更改来做到这一点.
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.
新的下载 Api 链接
首先,我在这里找到了有关下载档案的信息:https://developer.github.com/v3/repos/contents/#get-archive-link
First, I found information about downloading the archive here: https://developer.github.com/v3/repos/contents/#get-archive-link
公共仓库
如果它是一个公共回购,那么它很容易......你可以这样做:
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
私人仓库
如果它是私有仓库,您需要通过转到您的设置然后选择开发人员设置"/个人访问令牌".我创建了一个个人令牌.
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.
然后使用下一页上的说明,我发现了如何获取您有权访问的私有仓库:https://developer.github.com/v3/#authentication
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
完整代码
curl -H "Authorization: token ab499f3b..."
-L https://api.github.com/repos/godzilla/my_priv_repo/tarball > wut.tar.gz
务必将 ab499f3b...
替换为您的实际令牌.
Be sure to replace ab499f3b...
with your actual token.
这篇关于有没有办法以编程方式获取私有 github 存储库的压缩包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!