bin/pull_req_data_extraction.rb
# Return a hash of file names and commits on those files in the
# period between pull request open and months_back. The returned
# results do not include the commits coming from the PR.
Return a hash of file names and commits on those files in the
period between pull request open and months_back. The returned
results do not include the commits coming from the PR.
Return a hash of file names and commits on those files in the period between pull request open and months_back . The returned results do not include the commits coming from the PR .
def commits_on_pr_files(pr, months_back)
    oldest = Time.at(Time.at(pr[:created_at]).to_i - 3600 * 24 * 30 * months_back)
    pr_against = pull_req_entry(pr)['base']['sha']
    commits = commit_entries(pr[:id], at_open = true)
    commits_per_file = commits.flat_map { |c|
      unless c['files'].nil?
        c['files'].map { |f|
          [c['sha'], f['filename']]
        }
      else
        []
      end
    }.select{|x| x.size > 1}.group_by {|c|
      c[1]
    }
    commits_per_file.keys.reduce({}) do |acc, filename|
      commits_in_pr = commits_per_file[filename].map{|x| x[0]}
      walker = Rugged::Walker.new(git)
      walker.sorting(Rugged::SORT_DATE)
      walker.push(pr_against)
      commit_list = walker.take_while do |c|
        c.time > oldest
      end.reduce([]) do |acc1, c|
        if c.diff(paths: [filename.to_s]).size > 0 and
            not commits_in_pr.include? c.oid
          acc1 << c.oid
        end
        acc1
      end
      acc.merge({filename => commit_list})
    end
  end
def commits_on_pr_files ( pr , months_back ) oldest = Time . at ( Time . at ( pr [ :created_at ] ) . to_i - 3600 * 24 * 30 * months_back ) pr_against = pull_req_entry ( pr ) [ 'base' ] [ 'sha' ] commits = commit_entries ( pr [ :id ] , at_open = true ) commits_per_file = commits . flat_map { | c | unless c [ 'files' ] . nil? c [ 'files' ] . map { | f | [ c [ 'sha' ] , f [ 'filename' ] ] } else [ ] end } . select { | x | x . size > 1 } . group_by { | c | c [ 1 ] } commits_per_file . keys . reduce ( { } ) do | acc , filename | commits_in_pr = commits_per_file [ filename ] . map { | x | x [ 0 ] } walker = Rugged :: Walker . new ( git ) walker . sorting ( Rugged :: SORT_DATE ) walker . push ( pr_against ) commit_list = walker . take_while do | c | c . time > oldest end . reduce ( [ ] ) do | acc1 , c | if c . diff ( paths : [ filename . to_s ] ) . size > 0 and not commits_in_pr . include? c . oid acc1 << c . oid end acc1 end acc . merge ( { filename => commit_list } ) end end
Return a hash of file names and commits on those files in the
period between pull request open and months_back.
Return a hash of file names and commits on those files in the period between pull request open and months_back .
pr
months_back