Class: Michael::Models::Github::PRWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/michael/models/github/pr_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#reviewsObject

Returns the value of attribute reviews.



10
11
12
# File 'lib/michael/models/github/pr_wrapper.rb', line 10

def reviews
  @reviews
end

#statusesObject

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

#authorObject



26
27
28
# File 'lib/michael/models/github/pr_wrapper.rb', line 26

def author
  pr[:user][:login]
end

#commented_on_prObject



54
55
56
57
58
# File 'lib/michael/models/github/pr_wrapper.rb', line 54

def commented_on_pr
  reviews
    .reject { |review| author == review.author }
    .select(&:commented?).map(&:author)
end

#head_shaObject



30
31
32
# File 'lib/michael/models/github/pr_wrapper.rb', line 30

def head_sha
  pr[:head][:sha]
end

#labelsObject



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

Returns:

  • (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_atObject



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

#numberObject



22
23
24
# File 'lib/michael/models/github/pr_wrapper.rb', line 22

def number
  pr[:number]
end

#requested_changesObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/michael/models/github/pr_wrapper.rb', line 34

def reviewed?
  reviewers.any? || teams.any?
end

#reviewersObject



38
39
40
# File 'lib/michael/models/github/pr_wrapper.rb', line 38

def reviewers
  pr[:requested_reviewers].map { |reviewer| Reviewer.new(reviewer) }
end

#teamsObject



42
43
44
# File 'lib/michael/models/github/pr_wrapper.rb', line 42

def teams
  pr[:requested_teams].map { |team| Team.new(team) }
end

#titleObject



18
19
20
# File 'lib/michael/models/github/pr_wrapper.rb', line 18

def title
  pr[:title]
end