class PullRequest

Attributes

ci[RW]
cl[RW]
code_reviewed[RW]
created[RW]
issue[RW]
issue_current_sprint[RW]
issue_status[RW]
jira[RW]
needs_testing[RW]
pr_number[RW]
pr_raw[RW]
project[RW]
requester[RW]
title[RW]

Public Class Methods

client() click to toggle source
# File lib/pull_request.rb, line 26
def self.client
  @@client
end
connect(token = nil) click to toggle source
# File lib/pull_request.rb, line 31
def self.connect(token = nil)
  return @@client if @@client
  client = nil
  if token
    client = Octokit::Client.new(access_token: token)
  else
    print "Github Login: "
    login = gets.chomp
    print "Github Password: "
    passwd = STDIN.noecho(&:gets).chomp
    puts "\nBuilding report..."
    client = Octokit::Client.new(login: login, password: passwd)
  end
  client.auto_paginate = true
  @@client = client
end
get_prs(project, options = {}) click to toggle source
# File lib/pull_request.rb, line 48
def self.get_prs(project, options = {})

  pulls = client.pulls("optoro/#{project}", options)

  prs = []

  pulls.each do |pull|
    pr = PullRequest.new(
      pr_number: pull.number,
      title: pull.title,
      created: pull.created_at,
      requester: pull.user.login,
      ci: pull.rels[:statuses].get.data.first.andand.state,
      pr_raw: pull,
    )

    if pr.title =~ /([A-Z]{2,}-[0-9]+)/
      pr.jira = $1
    end

    labels = pr.labels
    if labels.member? "CL - Low"
      pr.cl = "Low"
    end
    if labels.member? "CL - Medium"
      pr.cl = "Medium"
    end
    if labels.member? "CL - High"
      pr.cl = "High"
    end
    if labels.member? "CL - System Impacting"
      pr.cl = "System"
    end
    pr.needs_testing = labels.member?("Needs External Testing") ? "Yes" : "No"
    pr.code_reviewed = labels.member?("Review Passed")          ? "Yes" : "No"
    pr.project       = labels.member?("Part of Project")        ? "Yes" : "No"

    if pr.jira
      issue = JiraIssue.find("issueKey = #{pr.jira}").first
      if issue
        pr.issue = issue
        pr.issue_current_sprint = !!issue.sprints.detect{|s|s["state"] == "ACTIVE"}
        pr.issue_status = issue.status
      end
    end

    prs << pr
  end
  prs
end
new(params) click to toggle source
# File lib/pull_request.rb, line 14
def initialize(params)
  params.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Public Instance Methods

labels() click to toggle source
# File lib/pull_request.rb, line 99
def labels
  pr_raw.rels[:issue].get.data.labels.map(&:name).to_set
end
to_csv() click to toggle source
# File lib/pull_request.rb, line 20
def to_csv
  [:pr_number, :jira, :title, :created, :requester, :cl, :ci, :code_reviewed, :needs_testing, :projec, :issue_current_sprint, :issue_status]
    .map{|col| instance_variable_get("@#{col}")}
    .to_csv
end