Class: OpenPull::PullRequestDecorator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/openpull/pull_request_decorator.rb

Instance Method Summary collapse

Instance Method Details

#as_row(username) ⇒ Object



5
6
7
8
# File 'lib/openpull/pull_request_decorator.rb', line 5

def as_row(username)
  [title, user(username), labels, status, commits, comments, mergeable,
   html_url.underline, updated_at]
end

#commentsObject



47
48
49
50
51
# File 'lib/openpull/pull_request_decorator.rb', line 47

def comments
  num = rels[:comments].get.data.size
  num += rels[:review_comments].get.data.size
  num.zero? ? '' : num
end

#commitsObject



42
43
44
45
# File 'lib/openpull/pull_request_decorator.rb', line 42

def commits
  num = rels[:commits].get.data.size
  num.zero? ? '' : num
end

#labelsObject



22
23
24
25
26
27
# File 'lib/openpull/pull_request_decorator.rb', line 22

def labels
  issue  = rels[:issue].get.data
  labels = issue.rels[:labels].get.data

  labels.map { |l| l.name.yellow }.join(', ')
end

#mergeableObject



53
54
55
# File 'lib/openpull/pull_request_decorator.rb', line 53

def mergeable
  super ? 'Yes'.green : 'No'.red
end

#statusObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openpull/pull_request_decorator.rb', line 29

def status
  state = rels[:statuses].get.data.map(&:state).first

  case state
  when 'success'
    state.green
  when 'pending'
    state.yellow
  else
    (state || '--').red
  end
end

#titleObject



10
11
12
13
14
15
# File 'lib/openpull/pull_request_decorator.rb', line 10

def title
  title = super
  return title if title.size <= 80

  title[0, 80] + '...'
end

#user(other) ⇒ Object



17
18
19
20
# File 'lib/openpull/pull_request_decorator.rb', line 17

def user(other)
  user = super().
  user == other ? user.blue : user
end