class MetadataCollector

Constants

NODE_README_URL
REVIEWER_REGEX

Public Instance Methods

collect(github_pr) click to toggle source
# File lib/committer-tools.rb, line 92
def collect(github_pr)
  {
    pr_url: collect_pr_url(github_pr),
    reviewers: collect_reviewers(github_pr),
    ci_statuses: collect_ci_statuses(github_pr)
  }
end

Private Instance Methods

collect_ci_statuses(github_pr) click to toggle source
# File lib/committer-tools.rb, line 102
def collect_ci_statuses(github_pr)
  HTTPHelper.get_json(github_pr['statuses_url']).map do |status|
    { name: status['context'], status: status['state'] }
  end
end
collect_pr_url(github_pr) click to toggle source
# File lib/committer-tools.rb, line 108
def collect_pr_url(github_pr)
  "PR-URL: #{github_pr['html_url']}"
end
collect_reviewers(github_pr) click to toggle source
# File lib/committer-tools.rb, line 112
def collect_reviewers(github_pr)
  # Collect a list of all possible reviewers
  possible_reviewers = {}
  readme = HTTPHelper.get(NODE_README_URL)

  # GitHub being stupid...
  # Treat every two lines as one...
  readme.split("\n").unshift('').each_slice(2).to_a.each do |a, b|
    if (m = REVIEWER_REGEX.match("#{a} #{b}"))
      possible_reviewers[m[1]] = {
        name: m[2],
        email: m[3]
      }
    end
  end

  # Use this list to identify reviewers for the current PR!
  reviewer_usernames = HTTPHelper.get_json("#{github_pr['url']}/reviews").map do |review|
    next unless review['state'] == 'APPROVED'
    review['user']['login']
  end.compact.uniq

  reviewer_usernames.map do |reviewer_username|
    user = possible_reviewers[reviewer_username]
    next unless user

    "Reviewed-By: #{user[:name]} <#{user[:email]}>"
  end.compact
end