我有這樣的代碼:在for循環中展望未來,儘管錯誤
require 'octokit'
require 'csv'
client = Octokit::Client.new :login => 'github_username', :password => 'github_password'
repo = 'rubinius/rubinius'
numbers = CSV.read('/Users/Name/Downloads/numbers.csv').flatten
# at this point, essentially numbers = [642, 630, 623, 643, 626]
CSV.open('results.csv', 'w') do |csv|
for number in numbers
begin
pull = client.pull_request(repo, number)
csv << [pull.number, pull.additions, pull.deletions]
rescue
next
end
end
end
然而,在次client.pull_request遇到404,然後躍過並進入下一個。但是,它仍然需要打印的數量numbers
數組中,然後把一張空白或零pull.additions
和pull.deletions
,然後在陣列中移動到下一個項目,從而產生類似:
pull.number pull.additions pull.deletions
642, 12, 3
630, ,
623, 15, 23
...
如何這可以做到嗎?
是的,但它仍然是有問題的 - 見上面編輯的代碼 – histelheim