在 CI 服务器上,我想获取我们在 Github 上维护的配置文件,以便可以在多个作业之间共享。我试图通过curl获取这个文件,但是这些方法都失败了(我得到了404):
# As advised by the oAuth docs
curl -H 'Authorization: token the_token' -L -o setup.sh https://raw.github.com/org/repo/file
# The url of the raw file after clicking to view it
curl -L https://raw.github.com/org/repo/file?login=username&token=the_token
以前的答案不起作用(或不再起作用)。
您可以使用 V3 API 获取如下原始文件(您需要 OAuth 令牌):
curl -H 'Authorization: token INSERTACCESSTOKENHERE' \
-H 'Accept: application/vnd.github.v3.raw' \
-O \
-L https://api.github.com/repos/owner/repo/contents/path
所有这一切都必须在一条线上进行。这-O
选项将文件保存在当前目录中。您可以使用-o filename
指定不同的文件名。
要获取 OAuth 令牌,请按照此处的说明操作:
- https://help.github.com/articles/creating-an-access-token-for-command-line-use
我也将其写为要点:
- https://gist.github.com/madrobby/9476733
编辑:解决方案的 API 参考如下:
- https://developer.github.com/v3/#authentication
- https://developer.github.com/v3/media/#request-specific-version
- https://developer.github.com/v3/repos/contents/#get-contents
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)