class Michael::Models::PullRequest
Attributes
comments[RW]
pull_request[R]
reviews[RW]
statuses[RW]
Public Class Methods
new(pull_request)
click to toggle source
# File lib/michael/models/pull_request.rb, line 12 def initialize(pull_request) @pull_request = pull_request end
Public Instance Methods
actionable?(name)
click to toggle source
# File lib/michael/models/pull_request.rb, line 50 def actionable?(name) return false if author?(name) return true if reviews.map(&:author).none?(name) last_update_head? end
approved?()
click to toggle source
# File lib/michael/models/pull_request.rb, line 36 def approved? return false if reviews.nil? reviews.any? && reviews.all?(&:approved?) end
head_sha()
click to toggle source
# File lib/michael/models/pull_request.rb, line 28 def head_sha pull_request[:head][:sha] end
labels()
click to toggle source
# File lib/michael/models/pull_request.rb, line 32 def labels pull_request[:labels].map(&:name) end
needs_review?()
click to toggle source
# File lib/michael/models/pull_request.rb, line 42 def needs_review? pull_request[:requested_reviewers].any? || pull_request[:requested_teams].any? end
number()
click to toggle source
# File lib/michael/models/pull_request.rb, line 16 def number pull_request[:number] end
pretty_print()
click to toggle source
# File lib/michael/models/pull_request.rb, line 57 def pretty_print [ pastel.bold("\##{number}"), statuses_in_dots, reviews_in_dots, title, labels.empty? ? nil : pastel.bold.yellow("[#{labels.join(', ')}]"), pastel.cyan(author), pretty_last_update(Time.now, last_updated_at), requested_changes, commented ].reject(&:nil?).join(' ') end
title()
click to toggle source
# File lib/michael/models/pull_request.rb, line 20 def title pull_request[:title] end
Private Instance Methods
commented()
click to toggle source
# File lib/michael/models/pull_request.rb, line 103 def commented rc = reviews.select(&:commented?).map(&:author) return nil if rc.empty? '| Commented: ' + rc.join(', ') end
last_update_head?()
click to toggle source
# File lib/michael/models/pull_request.rb, line 128 def last_update_head? updated_at = pull_request[:updated_at] reviewed_at = reviews.map(&:submitted_at).sort.pop updated_at > reviewed_at end
last_updated_at()
click to toggle source
# File lib/michael/models/pull_request.rb, line 73 def last_updated_at updates = [pull_request[:updated_at]] updates.concat(statuses.map(&:updated_at)) if !statuses.nil? && statuses.any? updates.concat(reviews.map(&:submitted_at)) if !reviews.nil? && reviews.any? updates.sort.pop end
pastel()
click to toggle source
# File lib/michael/models/pull_request.rb, line 134 def pastel @pastel ||= Pastel.new end
pretty_last_update(bigger, smaller)
click to toggle source
# File lib/michael/models/pull_request.rb, line 110 def pretty_last_update(bigger, smaller) duration = Duration.new(bigger-smaller) wh = if duration.weeks.positive? pastel.yellow.bold("#{duration.weeks} week(s)") elsif duration.days.positive? pastel.yellow("#{duration.days} day(s)") elsif duration.hours.positive? "#{duration.hours} hour(s)" elsif duration.minutes.positive? "#{duration.minutes} minute(s)" else 'seconds' end "last update #{wh} ago" end
requested_changes()
click to toggle source
# File lib/michael/models/pull_request.rb, line 96 def requested_changes rc = reviews.select(&:changes_requested?).map(&:author) return nil if rc.empty? '| ' + pastel.bold('Requested changes: ') + rc.map { |n| pastel.underscore(n) }.join(', ') end
reviews_in_dots()
click to toggle source
# File lib/michael/models/pull_request.rb, line 88 def reviews_in_dots return nil if reviews.nil? return '-' if !needs_review? && reviews.none? return pastel.yellow('.') if reviews.empty? reviews.map(&:dot).join end
statuses_in_dots()
click to toggle source
# File lib/michael/models/pull_request.rb, line 81 def statuses_in_dots return nil if statuses.nil? return '-' if statuses.empty? statuses.map(&:dot).join end