68

zip/tarball 文字列の作成方法に関する適切なリンクがここにありました

github から zip をダウンロードするとき、ファイル名の末尾にある 16 進文字列は何を表していますか?

しかし、私は GitHub APIv3 を見ているのですが、何か不足していないか気になりました。

  1. API 呼び出しを介して zip/tarball リンクを取得する方法はありますか?

  2. そうでない場合、git バイナリまたはライブラリを使用せずにその文字列を作成する方法はありますか? つまり、さまざまな API 呼び出しを使用して必要なデータを引き出し、必要な URL に組み立てることはできますか?

2 番目の質問は、stackoverflow にとって少し不合理であり、これは私にとって少し楽しいプロジェクトであることを知っています。そのため、コード スニペットをスローするのではなく、正しい方向に私を少し押し付けてくれれば、2 番目の質問を好むでしょう。 . または、それが可能かどうかを教えてください。

4

2 に答える 2

115

You can wget your way out of the GitHub repo to get a tar file (archive):

wget --no-check-certificate https://github.com/User/repo/archive/master.tar.gz

# better, if the certificate authorities are present:
wget https://github.com/User/repo/archive/master.tar.gz

will get you a file named 'master' from the user 'User''s repo 'repo'.

The updated V3 API url is:

https://api.github.com/repos/User/repo/:archive_format/:ref
#
# two possibilities for fomat:
https://api.github.com/repos/User/repo/tarball/master
https://api.github.com/repos/User/repo/zipball/master

# from github example:
$curl -L https://api.github.com/repos/octokit/octokit.rb/tarball > octokit.tar.gz

You can then tar xpvf master, getting the full archive. It will create a directory following the naming convention described in the question you mentioned.

No git binary is needed to get an archive from GitHub, thanks to their download service "Nodeload".


ligemer proposed in an edit the following example:

Edit 2016-08-25 - Shell Example With Wget, Variables, and Untar:

#!/bin/bash -ex

# arguments:
# token = $1
# organization = $2
# repo name = $3
# branch = $4

wget --header="Authorization: token ${1}" --header="Accept:application/vnd.github.v3.raw" -O - https://api.github.com/repos/${2}/${3}/tarball/${4} | tar xz

Call via:

$ scriptName.sh token my-organization site.com master

The command above will download and extract the Github folder to the same directory as the script.


Diogo Quintela suggests in the comments:

The following example allow the download, extract and cut the top level directory

curl -L https://api.github.com/repos/octokit/octokit.rb/tarball | tar xz --strip=1 
于 2011-12-04T20:44:25.277 に答える
28

構文はドキュメントで説明されています:

GET /repos/:owner/:repo/:archive_format/:ref

次の URL の例は、( 302 リダイレクトを介して) hadley/devtoolsリポジトリmaster内のzip アーカイブを指します。

https://api.github.com/repos/hadley/devtools/zipball/master

( のもう 1 つのオプションはarchive_formatですtarball。)

この API がいつから利用できるようになったのかはわかりません。

于 2014-05-07T22:53:32.170 に答える