Class: PullRequest
- Inherits:
-
Object
- Object
- PullRequest
- Defined in:
- lib/pull_request.rb
Constant Summary collapse
- @@client =
nil
Instance Attribute Summary collapse
-
#ci ⇒ Object
Returns the value of attribute ci.
-
#cl ⇒ Object
Returns the value of attribute cl.
-
#code_reviewed ⇒ Object
Returns the value of attribute code_reviewed.
-
#created ⇒ Object
Returns the value of attribute created.
-
#issue ⇒ Object
Returns the value of attribute issue.
-
#issue_current_sprint ⇒ Object
Returns the value of attribute issue_current_sprint.
-
#issue_status ⇒ Object
Returns the value of attribute issue_status.
-
#jira ⇒ Object
Returns the value of attribute jira.
-
#needs_testing ⇒ Object
Returns the value of attribute needs_testing.
-
#pr_number ⇒ Object
Returns the value of attribute pr_number.
-
#pr_raw ⇒ Object
Returns the value of attribute pr_raw.
-
#project ⇒ Object
Returns the value of attribute project.
-
#requester ⇒ Object
Returns the value of attribute requester.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ PullRequest
constructor
A new instance of PullRequest.
- #labels ⇒ Object
- #to_csv ⇒ Object
Constructor Details
#initialize(params) ⇒ PullRequest
Returns a new instance of PullRequest.
14 15 16 17 18 |
# File 'lib/pull_request.rb', line 14 def initialize(params) params.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#ci ⇒ Object
Returns the value of attribute ci.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def ci @ci end |
#cl ⇒ Object
Returns the value of attribute cl.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def cl @cl end |
#code_reviewed ⇒ Object
Returns the value of attribute code_reviewed.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def code_reviewed @code_reviewed end |
#created ⇒ Object
Returns the value of attribute created.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def created @created end |
#issue ⇒ Object
Returns the value of attribute issue.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def issue @issue end |
#issue_current_sprint ⇒ Object
Returns the value of attribute issue_current_sprint.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def issue_current_sprint @issue_current_sprint end |
#issue_status ⇒ Object
Returns the value of attribute issue_status.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def issue_status @issue_status end |
#jira ⇒ Object
Returns the value of attribute jira.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def jira @jira end |
#needs_testing ⇒ Object
Returns the value of attribute needs_testing.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def needs_testing @needs_testing end |
#pr_number ⇒ Object
Returns the value of attribute pr_number.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def pr_number @pr_number end |
#pr_raw ⇒ Object
Returns the value of attribute pr_raw.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def pr_raw @pr_raw end |
#project ⇒ Object
Returns the value of attribute project.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def project @project end |
#requester ⇒ Object
Returns the value of attribute requester.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def requester @requester end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/pull_request.rb', line 10 def title @title end |
Class Method Details
.client ⇒ Object
26 27 28 |
# File 'lib/pull_request.rb', line 26 def self.client @@client end |
.connect(token = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/pull_request.rb', line 48 def self.get_prs(project, = {}) pulls = client.pulls("optoro/#{project}", ) 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 |
Instance Method Details
#labels ⇒ Object
99 100 101 |
# File 'lib/pull_request.rb', line 99 def labels pr_raw.rels[:issue].get.data.labels.map(&:name).to_set end |
#to_csv ⇒ Object
20 21 22 23 24 |
# 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 |