Get lines added/deleted for list of pull requests

684 views Asked by At

Assume I have a list of pull request IDs, such as in this gist.

If I simply want to have two variables for each ID: "lines added" and "lines deleted". How can I use octokit to get these variables for each pull request?

I'd imagine I'd start like this in 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

But this seems to simply overwrite the file and just give me one result instead of 3 (or however many are in the list object. How can I make it give me the data for all 3?

2

There are 2 answers

2
jonahb On BEST ANSWER
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
0
histelheim On
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