gitlab-mergetrain-checker 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3f0cc6f8a38c160ea6f78ab7d57755f510272fcdae1cf72ab9dfadc9cffdb94
|
4
|
+
data.tar.gz: 6da1e48f6974907b70ada6a5f4ac14c673f88b14e0a8931f22f029d8d27bb058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f070d495c1ab9b7e7795f2795ef131e5b11cc7e4c793cb55b14ba1780cfb433cb454ceadcc2b1a10be511dcbcd44e5e94dd1592c323a47ffe37a2ca2bb702d
|
7
|
+
data.tar.gz: 5ee8e6509fc145d1100d0c0a2c56902b9b09daff1ea10ba054d9ae81431beccd4847c5c3ddef187432720a3dbf71b2eb8860c6b41f5a08dc0413916ce389eb5b
|
data/lib/mergetrain_check.rb
CHANGED
@@ -13,6 +13,9 @@ module MergetrainCheck
|
|
13
13
|
opts.on("-n", "--host GITLAB-HOSTNAME", "Specify the Gitlab installation host (in case it's not gitlab.com)") do |host|
|
14
14
|
options[:host] = host
|
15
15
|
end
|
16
|
+
opts.on("-l", "--limit COUNT", "Limit completed jobs to COUNT entries (default 10)") do |limit|
|
17
|
+
options[:limit] = limit
|
18
|
+
end
|
16
19
|
opts.on("-v", "--verbose", "Verbose output (larger table)") do |verbose|
|
17
20
|
options[:verbose] = verbose
|
18
21
|
end
|
@@ -3,21 +3,44 @@ require 'json'
|
|
3
3
|
|
4
4
|
module MergetrainCheck
|
5
5
|
class Checker
|
6
|
+
def max_count
|
7
|
+
@max_count
|
8
|
+
end
|
9
|
+
|
10
|
+
def max_completed=(value)
|
11
|
+
@max_completed = value
|
12
|
+
end
|
13
|
+
|
6
14
|
def initialize(host, token, id)
|
7
15
|
@host = host
|
8
16
|
@token = token
|
9
17
|
@id = id
|
10
|
-
@
|
18
|
+
@max_count = 10
|
11
19
|
end
|
12
20
|
|
13
21
|
def check
|
14
|
-
Net::HTTP.start(
|
15
|
-
|
22
|
+
Net::HTTP.start(active_uri.host, active_uri.port, :use_ssl => active_uri.scheme == 'https') do |http|
|
23
|
+
get_and_parse(http, active_uri) + get_and_parse(http, completed_uri)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def get_and_parse(http, uri)
|
30
|
+
request = Net::HTTP::Get.new uri
|
16
31
|
request['PRIVATE-TOKEN'] = @token
|
17
32
|
|
18
33
|
response = http.request request
|
19
34
|
JSON.parse response.body
|
20
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
def completed_uri
|
38
|
+
URI("https://#{@host}/api/v4/projects/#{@id}/merge_trains?per_page=#{@max_completed}&scope=complete")
|
39
|
+
end
|
40
|
+
|
41
|
+
def active_uri
|
42
|
+
URI("https://#{@host}/api/v4/projects/#{@id}/merge_trains?per_page=100&scope=active")
|
21
43
|
end
|
22
44
|
end
|
23
45
|
end
|
46
|
+
|
@@ -22,7 +22,12 @@ module MergetrainCheck
|
|
22
22
|
@firstname_only ? carriage['user']['name'].split.first : carriage['user']['name'],
|
23
23
|
truncate_string(carriage['merge_request']['title'], @max_length)]
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
|
+
header = ''
|
27
|
+
if has_train_finished? body
|
28
|
+
header = "\n ✋ 🚉 The train is at the station: There are currently no running merge trains!\n\n"
|
29
|
+
end
|
30
|
+
header + values.to_table
|
26
31
|
end
|
27
32
|
|
28
33
|
private
|
@@ -44,25 +49,30 @@ module MergetrainCheck
|
|
44
49
|
def pretty_date_difference(from, to)
|
45
50
|
(to.to_time - from.to_time).duration
|
46
51
|
end
|
52
|
+
|
53
|
+
def has_train_finished?(data)
|
54
|
+
data.first['status'] != 'fresh'
|
55
|
+
end
|
47
56
|
end
|
48
57
|
end
|
49
58
|
|
50
59
|
class Array
|
51
60
|
def to_table
|
61
|
+
output = ''
|
52
62
|
column_sizes = self.reduce([]) do |lengths, row|
|
53
63
|
row.each_with_index.map{|iterand, index| [lengths[index] || 0, iterand.to_s.length + count_emojis(iterand.to_s)].max}
|
54
64
|
end
|
55
|
-
|
65
|
+
output += head = '-' * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1) + "\n"
|
56
66
|
self.each_with_index do |row, idx|
|
57
67
|
row = row.fill(nil, row.size..(column_sizes.size - 1))
|
58
68
|
row = row.each_with_index.map{|v, i| v = v.to_s + ' ' * (column_sizes[i] - v.to_s.length - count_emojis(v.to_s))}
|
59
|
-
|
69
|
+
output += '| ' + row.join(' | ') + ' |' + "\n"
|
60
70
|
if idx == 0
|
61
71
|
row = row.each_with_index.map{|v, i| v = '-' * v.to_s.length}
|
62
|
-
|
72
|
+
output += '| ' + row.join(' | ') + ' |' + "\n"
|
63
73
|
end
|
64
74
|
end
|
65
|
-
|
75
|
+
output += head
|
66
76
|
end
|
67
77
|
|
68
78
|
private
|