Class: Michael::Models::PullRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pull_request) ⇒ PullRequest

Returns a new instance of PullRequest.



12
13
14
# File 'lib/michael/models/pull_request.rb', line 12

def initialize(pull_request)
  @pull_request = pull_request
end

Instance Attribute Details

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#pull_requestObject (readonly)

Returns the value of attribute pull_request.



9
10
11
# File 'lib/michael/models/pull_request.rb', line 9

def pull_request
  @pull_request
end

#reviewsObject

Returns the value of attribute reviews.



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

def reviews
  @reviews
end

#statusesObject

Returns the value of attribute statuses.



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

def statuses
  @statuses
end

Instance Method Details

#actionable?(name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/michael/models/pull_request.rb', line 36

def approved?
  return false if reviews.nil?

  reviews.any? && reviews.all?(&:approved?)
end

#authorObject



24
25
26
# File 'lib/michael/models/pull_request.rb', line 24

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

#author?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/michael/models/pull_request.rb', line 46

def author?(name)
  author == name
end

#head_shaObject



28
29
30
# File 'lib/michael/models/pull_request.rb', line 28

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

#labelsObject



32
33
34
# File 'lib/michael/models/pull_request.rb', line 32

def labels
  pull_request[:labels].map(&:name)
end

#needs_review?Boolean

Returns:

  • (Boolean)


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

def needs_review?
  pull_request[:requested_reviewers].any? || pull_request[:requested_teams].any?
end

#numberObject



16
17
18
# File 'lib/michael/models/pull_request.rb', line 16

def number
  pull_request[:number]
end

#pretty_printObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# 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

#titleObject



20
21
22
# File 'lib/michael/models/pull_request.rb', line 20

def title
  pull_request[:title]
end