-
Notifications
You must be signed in to change notification settings - Fork 2
/
print.rb
52 lines (41 loc) · 1.38 KB
/
print.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'pry'
require 'colorize'
require_relative 'helpers/gitlab_service'
require_relative 'helpers/time_helper'
module Terminal
extend TimeHelper
SEPARATOR = ('-' * 100).yellow
def mergeable(merge_request)
merge_request &&
!merge_request.has_conflicts &&
!merge_request.work_in_progress &&
merge_request.merge_status == 'can_be_merged' &&
merge_request.blocking_discussions_resolved
end
def label_format(labels)
labels.map do |label|
"[#{label}]".light_magenta
end.join
end
def run
previous_author = nil
merge_requests = GitlabService.fetch_merge_requests
merge_requests.each do |merge_request|
if previous_author != merge_request.author.username
previous_author = merge_request.author.username
puts SEPARATOR
end
upvotes = merge_request.upvotes > 0 ? "#{merge_request.upvotes}★".cyan : ''
mergeable = mergeable(merge_request) ? '✓'.green : '✗'.red
labels = merge_request.labels
time_ago = calculate_time_ago(merge_request.created_at)
puts """ #{merge_request.web_url.cyan}
#{merge_request.author.username.blue} - #{merge_request.title}
#{mergeable} #{merge_request.user_notes_count}C #{time_ago} #{upvotes} #{label_format(labels)}
"""
end
puts SEPARATOR
end
module_function :run, :mergeable, :label_format
end
Terminal.run