1

假设我有一个拉取请求 ID 列表,例如在这个gist中。

如果我只想为每个 ID 设置两个变量:“添加的行”和“删除的行”。如何使用 octokit 为每个拉取请求获取这些变量?

我想我会在 ruby​​ 中这样开始:

require 'octokit'
require 'csv'

list = [2825, 2119, 2629]
output = []

for id in list
   output.push(Octokit.pull_request('rubinius/rubinius', id, options = {}))
 end

begin
   file = File.open("/Users/Username/Desktop/pr_mining_output.txt", "w")
   file.write(output) 
 rescue IOError => e
   #some error occur, dir not writable etc.
 ensure
   file.close unless file == nil
 end

但这似乎只是简单地覆盖了文件并只给我一个结果而不是 3(或者无论list对象中有多少个结果。我怎样才能让它给我所有 3 个的数据?

4

2 回答 2

2
require 'octokit'
require 'csv'

client = Octokit::Client.new :login => 'mylogin', :password => 'mypass'
repo = 'rubinius/rubinius'
numbers = [2825, 2119, 2629]

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 Octokit::NotFound
    end
  end    
end
于 2013-12-21T17:41:56.783 回答
0
require 'octokit'
require 'csv'

client = Octokit::Client.new :login => 'username', :password => 'password'
repo = 'rubinius/rubinius'
numbers = CSV.read('/Users/User/Downloads/numbers.csv').flatten

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
        csv << [number, 0, 0]
        next
      end
    end
  end
于 2013-12-21T20:03:38.950 回答