0

我有这个代码:

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 然后跳过并转到下一个。但是,它仍然需要打印数组中的数字,然后为andnumbers输入一个空白或零,然后移动到数组中的下一项,从而产生如下内容:pull.additionspull.deletions

pull.number pull.additions pull.deletions
642,        12,            3
630,          , 
623,        15,            23
...

如何才能做到这一点?

4

2 回答 2

1

我已经删除了 for 循环,因为它本质上不是 ruby​​ish,下面应该可以工作

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|
     numbers.each do |number|
         begin
          pull = client.pull_request(repo, number)
          csv << [pull.number, pull.additions, pull.deletions]
         rescue
          csv << [0,0,0]
          next
        end
     end    
  end
于 2013-12-21T19:49:32.973 回答
0

您是否尝试过使用开始/救援/确保这样救援/确保代码将适当地设置拉变量?有关示例,请参见https://stackoverflow.com/a/2192010/832648

于 2013-12-21T19:16:16.990 回答