gitarro 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gitarro/backend.rb +70 -64
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e97e8143aeaa4f46f345b4f4b8bdd0f6f96ff678
|
4
|
+
data.tar.gz: cfefb556f4e12c71ed59c0bb4ae5348413aac8c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 900c16bda6d9c65c8bb7098a984546a8cd699747152edab67bb893e94f283c242d257b7248a8094e583d94a4dfe249023fa8f06f0c9ea5abbb692407cf33f03b
|
7
|
+
data.tar.gz: f04932ba29a8c41bc177c6405cc71b6b311deee27306bbb376d6fd0ee8d04d72da5be4d86a127e8aa6299cae8c7122ff9ed7b6f99a4227856d32968265355688
|
data/lib/gitarro/backend.rb
CHANGED
@@ -9,6 +9,70 @@ require_relative 'opt_parser'
|
|
9
9
|
require_relative 'git_op'
|
10
10
|
require 'active_support'
|
11
11
|
|
12
|
+
# this module perform basic operations
|
13
|
+
# on prs and contain helper functions
|
14
|
+
# that use octokit client for retrieving info
|
15
|
+
# about the PR or commit
|
16
|
+
module GitHubPrOperations
|
17
|
+
# check if the commit of a pr is on pending
|
18
|
+
def pending_pr?(comm_st)
|
19
|
+
# 2) pending
|
20
|
+
(0..comm_st.statuses.size - 1).any? do |pr_status|
|
21
|
+
comm_st.statuses[pr_status]['context'] == @context &&
|
22
|
+
comm_st.statuses[pr_status]['state'] == 'pending'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# check it the cm of pr contain the context from gitarro already
|
27
|
+
def context_present?(cm_st)
|
28
|
+
# 1) context_present == false triggers test. >
|
29
|
+
# this means the PR is not with context tagged
|
30
|
+
(0..cm_st.statuses.size - 1).any? do |pr_status|
|
31
|
+
cm_st.statuses[pr_status]['context'] == @context
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# if the pr has travis test and one custom, we will have 2 elements.
|
36
|
+
# in this case, if the 1st element doesn't have the state property
|
37
|
+
# state property is "pending", failure etc.
|
38
|
+
# if we don't have this, so we have 0 status
|
39
|
+
# the PRs is "unreviewed"
|
40
|
+
def commit_is_unreviewed?(comm_st)
|
41
|
+
puts comm_st.statuses[0]['state']
|
42
|
+
return false
|
43
|
+
rescue NoMethodError
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
|
47
|
+
def success_status?(comm_st)
|
48
|
+
(0..comm_st.statuses.size - 1).any? do |pr_status|
|
49
|
+
comm_st.statuses[pr_status]['context'] == @context &&
|
50
|
+
comm_st.statuses[pr_status]['state'] == 'success'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def failed_status?(comm_st)
|
55
|
+
(0..comm_st.statuses.size - 1).any? do |pr_status|
|
56
|
+
comm_st.statuses[pr_status]['context'] == @context &&
|
57
|
+
comm_st.statuses[pr_status]['state'] == 'failure'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create a status for a PR
|
62
|
+
def create_status(pr, status)
|
63
|
+
client.create_status(@repo, pr.head.sha, status, context: @context,
|
64
|
+
description: @description,
|
65
|
+
target_url: @target_url)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Return true if the PR was updated in less than the value of variable sec
|
69
|
+
# or if sec < 0 (the check was disabled)
|
70
|
+
# GitHub considers a PR updated when there is a new commit or a new comment
|
71
|
+
def pr_last_update_less_than(pr, sec)
|
72
|
+
Time.now.utc - pr.updated_at < sec || sec < 0 ? true : false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
12
76
|
# by default enabled (faraday_cache in memory, will be deleted
|
13
77
|
# after gitarro run 2nd time. usefull for -C check option
|
14
78
|
# and performance, since we cache)
|
@@ -100,7 +164,7 @@ class TestExecutor
|
|
100
164
|
end
|
101
165
|
end
|
102
166
|
|
103
|
-
# this the public class is the backend of gitarro,
|
167
|
+
# this the main public class is the backend of gitarro,
|
104
168
|
# were we execute the tests and so on
|
105
169
|
class Backend
|
106
170
|
attr_accessor :options, :client, :gbexec
|
@@ -108,6 +172,8 @@ class Backend
|
|
108
172
|
# tests are gone from backend and run separately
|
109
173
|
include CachingOctokit
|
110
174
|
include ChangelogTests
|
175
|
+
include GitHubPrOperations
|
176
|
+
|
111
177
|
# public method of backend
|
112
178
|
def initialize(option = nil)
|
113
179
|
@options = option.nil? ? OptParser.new.cmdline_options : option
|
@@ -161,7 +227,7 @@ class Backend
|
|
161
227
|
def unreviewed_new_pr?(pr, comm_st)
|
162
228
|
return unless commit_is_unreviewed?(comm_st)
|
163
229
|
pr_all_files_type(pr.number, @file_type)
|
164
|
-
return if empty_files_changed_by_pr(pr)
|
230
|
+
return if empty_files_changed_by_pr?(pr)
|
165
231
|
# gb.check is true when there is a job running as scheduler
|
166
232
|
# which doesn't execute the test but trigger another job
|
167
233
|
print_test_required
|
@@ -216,20 +282,6 @@ class Backend
|
|
216
282
|
puts '[TESTREQUIRED=true] PR requires test'
|
217
283
|
end
|
218
284
|
|
219
|
-
# Create a status for a PR
|
220
|
-
def create_status(pr, status)
|
221
|
-
client.create_status(@repo, pr.head.sha, status, context: @context,
|
222
|
-
description: @description,
|
223
|
-
target_url: @target_url)
|
224
|
-
end
|
225
|
-
|
226
|
-
# Return true if the PR was updated in less than the value of variable sec
|
227
|
-
# or if sec < 0 (the check was disabled)
|
228
|
-
# GitHub considers a PR updated when there is a new commit or a new comment
|
229
|
-
def pr_last_update_less_than(pr, sec)
|
230
|
-
Time.now.utc - pr.updated_at < sec || sec < 0 ? true : false
|
231
|
-
end
|
232
|
-
|
233
285
|
# this function setup first pending to PR, then execute the tests
|
234
286
|
# then set the status according to the results of script executed.
|
235
287
|
# pr_head = is the PR branch
|
@@ -266,56 +318,10 @@ class Backend
|
|
266
318
|
ff
|
267
319
|
end
|
268
320
|
|
269
|
-
# check if the commit of a pr is on pending
|
270
|
-
def pending_pr?(comm_st)
|
271
|
-
# 2) pending
|
272
|
-
(0..comm_st.statuses.size - 1).any? do |pr_status|
|
273
|
-
comm_st.statuses[pr_status]['context'] == @context &&
|
274
|
-
comm_st.statuses[pr_status]['state'] == 'pending'
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
# check it the cm of pr contain the context from gitarro already
|
279
|
-
def context_present?(cm_st)
|
280
|
-
# 1) context_present == false triggers test. >
|
281
|
-
# this means the PR is not with context tagged
|
282
|
-
(0..cm_st.statuses.size - 1).any? do |pr_status|
|
283
|
-
cm_st.statuses[pr_status]['context'] == @context
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
# if the pr has travis test and one custom, we will have 2 elements.
|
288
|
-
# in this case, if the 1st element doesn't have the state property
|
289
|
-
# state property is "pending", failure etc.
|
290
|
-
# if we don't have this, so we have 0 status
|
291
|
-
# the PRs is "unreviewed"
|
292
|
-
def commit_is_unreviewed?(comm_st)
|
293
|
-
puts comm_st.statuses[0]['state']
|
294
|
-
return false
|
295
|
-
rescue NoMethodError
|
296
|
-
return true
|
297
|
-
end
|
298
|
-
|
299
|
-
def success_status?(comm_st)
|
300
|
-
(0..comm_st.statuses.size - 1).any? do |pr_status|
|
301
|
-
comm_st.statuses[pr_status]['context'] == @context &&
|
302
|
-
comm_st.statuses[pr_status]['state'] == 'success'
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
def failed_status?(comm_st)
|
307
|
-
(0..comm_st.statuses.size - 1).any? do |pr_status|
|
308
|
-
comm_st.statuses[pr_status]['context'] == @context &&
|
309
|
-
comm_st.statuses[pr_status]['state'] == 'failure'
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
321
|
# control if the pr change add any files, specified
|
314
322
|
# it can be also a dir
|
315
|
-
def empty_files_changed_by_pr(pr)
|
316
|
-
|
317
|
-
puts "no files of type #{@file_type} found! skipping"
|
318
|
-
true
|
323
|
+
def empty_files_changed_by_pr?(pr)
|
324
|
+
pr_all_files_type(pr.number, @file_type).any?
|
319
325
|
end
|
320
326
|
|
321
327
|
def retrigger_needed?(pr)
|