2017-10-06 157 views
0

我經常遇到Octokit::AbuseDetected錯誤,因爲我的應用觸發了太多的API請求。Octokit:add_contents無法推送回購

我使用add_contents方法對每個文件的特定目錄內添加到遠程倉庫:(一一)

Dir.glob(wrapper + '/**/*') do |path| 
    octokit_client.create_contents(repo, path.sub("#{wrapper}/", ''), 'adding content', File.read(path), branch: 'master') unless File.directory?(path) 
end 

有沒有辦法要麼推所有文件的目錄裏面一次遠程回購或首先在本地添加內容,然後推回購?

+0

您是否需要使用oktokit庫?或者它可以切換到其他庫,例如[ruby-git](https://github.com/schacon/ruby-git) – Hirurg103

+0

@ Hirurg103那麼,如果它不會使事情太複雜:-) – jonhue

回答

0

不確定oktokit庫是否有可能。與ruby-git你可以做以下實現這一點:

Dir.glob(wrapper + '/**/*') do |path| 
    next if File.directory?(path) 
    File.write path.sub("#{wrapper}/", ''), File.read(path) 
end 

g = Git.open('.') # initialize ruby git 
g.add 
g.commit('adding content') 
g.push 

你不需要在源代碼ruby-git進行身份驗證。您需要設置ssh-keys - 讀取Generating a new SSH key and adding it to the ssh-agent

+0

'Git.open('。')'是什麼意思?我如何進行身份驗證才能推送? – jonhue