Class: Michael::Models::Github::PRWrapper
- Inherits:
-
Object
- Object
- Michael::Models::Github::PRWrapper
- Defined in:
- lib/michael/models/github/pr_wrapper.rb
Instance Attribute Summary collapse
-
#reviews ⇒ Object
Returns the value of attribute reviews.
-
#statuses ⇒ Object
Returns the value of attribute statuses.
Instance Method Summary collapse
- #author ⇒ Object
- #commented_on_pr ⇒ Object
- #head_sha ⇒ Object
-
#initialize(pull_request) ⇒ PRWrapper
constructor
A new instance of PRWrapper.
- #labels ⇒ Object
- #last_update_head? ⇒ Boolean
- #last_updated_at ⇒ Object
- #number ⇒ Object
- #requested_changes ⇒ Object
- #reviewed? ⇒ Boolean
- #reviewers ⇒ Object
- #teams ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(pull_request) ⇒ PRWrapper
Returns a new instance of PRWrapper.
12 13 14 15 16 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 12 def initialize(pull_request) @pr = pull_request @statuses = [] @reviews = [] end |
Instance Attribute Details
#reviews ⇒ Object
Returns the value of attribute reviews.
10 11 12 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 10 def reviews @reviews end |
#statuses ⇒ Object
Returns the value of attribute statuses.
10 11 12 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 10 def statuses @statuses end |
Instance Method Details
#author ⇒ Object
26 27 28 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 26 def pr[:user][:login] end |
#commented_on_pr ⇒ Object
54 55 56 57 58 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 54 def commented_on_pr reviews .reject { |review| == review. } .select(&:commented?).map(&:author) end |
#head_sha ⇒ Object
30 31 32 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 30 def head_sha pr[:head][:sha] end |
#labels ⇒ Object
46 47 48 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 46 def labels pr[:labels].map { |label| label[:name] } end |
#last_update_head? ⇒ Boolean
60 61 62 63 64 65 66 67 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 60 def last_update_head? pr_last_update = pr[:updated_at] review_last_update = pr.reviews&.map(&:submitted_at)&.sort&.pop return false unless review_last_update pr_last_update > review_last_update end |
#last_updated_at ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 69 def last_updated_at updates = [pr[:updated_at]] updates.concat pr.statuses.map(&:updated_at) unless pr.statuses.nil? || pr.statuses.any? updates.concat pr.reviews.map(&:submitted_at) unless pr.reviews.nil? || pr.reviews.any? updates.sort.pop end |
#number ⇒ Object
22 23 24 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 22 def number pr[:number] end |
#requested_changes ⇒ Object
50 51 52 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 50 def requested_changes reviews.select(&:changes_requested?).map(&:author) end |
#reviewed? ⇒ Boolean
34 35 36 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 34 def reviewed? reviewers.any? || teams.any? end |
#reviewers ⇒ Object
38 39 40 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 38 def reviewers pr[:requested_reviewers].map { |reviewer| Reviewer.new(reviewer) } end |
#teams ⇒ Object
42 43 44 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 42 def teams pr[:requested_teams].map { |team| Team.new(team) } end |
#title ⇒ Object
18 19 20 |
# File 'lib/michael/models/github/pr_wrapper.rb', line 18 def title pr[:title] end |