Heroku拉取私有GitHub存储库

12

我已经尝试了不同的方法,在Rails应用程序的 Gemfile 中使用Github私有存储库的引用。

1) Gemfile:
gem 'my_gem', :git => "https://#{github_user}:#{github_pw}@github.com/me/my_gem.git"

'git push heroku' 的结果:

Fetching https://user:pw@github.com/me/my_gem.git
error: The requested URL returned error: 401 while accessing https://user:pw@github.com/me/my_gem.git/info/refs
Git error: command `git clone 'https://user:pw@github.com/me/my_gem.git' "/tmp/build_2wxmqutch8gy7/vendor/bundle/jruby/1.9/cache/bundler/git/my_gem-929bddeee3dd4a564c2689e189190073df01431e" --bare --no-hardlinks` in directory /tmp/build_2wxmqutch8gy7 has failed.
Dependencies installed

然后我发现了这篇文章https://help.github.com/articles/creating-an-oauth-token-for-command-line-use, 并创建了一个 OAuth token。

2) Gemfile:
gem 'my_gem', :git => "https://#{github_oauth_token}@github.com/me/my_gem.git"

'git push heroku' 的结果:

Fetching https://0123456789abcdef0123456789abcdef01234567@github.com/me/my_gem.git
Password:

Heroku停顿并提示输入密码。

在我的本地机器上,两者:

git clone https://user:pw@github.com/me/my_gem.git

git clone https://0123456789abcdef0123456789abcdef01234567@github.com/me/my_gem.git

运行完美!

本地:

# git --version
git version 1.7.9.5

Heroku:

# heroku run git --version
git version 1.7.0
2个回答

6

Heroku运行较旧版本的Git,不幸的是它并不完全支持URL中的auth部分。

你可以通过添加由GitHub提供的虚拟密码来解决这个问题。因此,你需要使用以下方式:

https://#{github_oauth_token}@github.com/me/my_gem.git

使用:

https://#{github_oauth_token}:x-oauth-basic@github.com/me/my_gem.git

有没有一种方法可以访问由Github组织拥有的私有repo?我正在尝试通过bower.json使私有repo被bower拉取。 - chandlervdw
只要您拥有OAuth令牌所属账户的访问权限,这将适用于个人和组织存储库。 - bergie

2

Heroku的git(版本1.7)不支持在Github仓库中使用电子邮件作为用户名。

您必须使用您的Github用户名。

此外,Heroku的git不支持使用oauth token。

希望Heroku很快升级他们的git,这样他们就可以继续让我的生活更轻松 :-)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接