gitarro 0.1.78 → 0.1.79
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/gitarro +2 -0
- data/lib/gitarro/backend.rb +53 -25
- data/lib/gitarro/git_op.rb +2 -0
- data/lib/gitarro/opt_parser.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 14bb2f5adfdd8fdc345c010ab3282f7c5cf19e5bd7fd81155fac8fcb3b298b70
|
4
|
+
data.tar.gz: 05ff77cd63c57b95541c5db21b9684c06981a202e5f49ac657f8ff5b4b43e01b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eb6fb49628ce67ad61f7b60e1e0da8cc5c560e3e0a8845be5556a3265e5bddc4b4d4774fb7204700f855442d3f6b536e5a2d2467e6970553976a34bb1f5862a
|
7
|
+
data.tar.gz: 69c6dc98ba868abad274eb1587662735f258368b0a97ebd22f69d187c871e105b2c1d8565047b272dd053a761d20f2b31f495c06daf0a967aba20cce2cb62286
|
data/bin/gitarro
CHANGED
@@ -15,10 +15,12 @@ prs.each do |pr|
|
|
15
15
|
puts '=' * 30 + "\n" + "TITLE_PR: #{pr.title}, NR: #{pr.number}\n" + '=' * 30
|
16
16
|
# check if prs contains the branch given otherwise just break
|
17
17
|
next unless b.pr_equal_spefic_branch?(pr)
|
18
|
+
|
18
19
|
# this check the last commit state, catch for review or not reviewd status.
|
19
20
|
comm_st = b.client.status(b.repo, pr.head.sha)
|
20
21
|
# pr number trigger.
|
21
22
|
break if b.triggered_by_pr_number?
|
23
|
+
|
22
24
|
# retrigger if magic word found
|
23
25
|
b.retrigger_check(pr)
|
24
26
|
# 0) do test for unreviewed pr
|
data/lib/gitarro/backend.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
2
|
|
3
|
+
require 'json'
|
3
4
|
require 'octokit'
|
4
5
|
require 'optparse'
|
5
6
|
require 'time'
|
@@ -80,14 +81,13 @@ class TestExecutor
|
|
80
81
|
instance_variable_set("@#{key}", value)
|
81
82
|
self.class.send(:attr_accessor, key)
|
82
83
|
end
|
84
|
+
Octokit.auto_paginate = true
|
85
|
+
@client = Octokit::Client.new(netrc: true)
|
83
86
|
end
|
84
87
|
|
85
88
|
# this will clone the repo and execute the tests
|
86
89
|
def pr_test(pr)
|
87
|
-
export_pr_data_to_hidden_file(pr)
|
88
90
|
clone_repo(@noshallow, pr)
|
89
|
-
# export variables
|
90
|
-
export_pr_variables(pr)
|
91
91
|
# do valid tests and store the result
|
92
92
|
test_status = run_script
|
93
93
|
test_status
|
@@ -99,8 +99,42 @@ class TestExecutor
|
|
99
99
|
$CHILD_STATUS.exitstatus.nonzero? ? 'failure' : 'success'
|
100
100
|
end
|
101
101
|
|
102
|
+
def export_pr_data(pr)
|
103
|
+
export_pr_data_to_simple_file(pr)
|
104
|
+
export_pr_data_to_file(pr)
|
105
|
+
end
|
106
|
+
|
102
107
|
private
|
103
108
|
|
109
|
+
def export_pr_data_to_simple_file(pr)
|
110
|
+
# save this file in local dir where gitarro is executed.
|
111
|
+
# This part is kept for compatibility purposes
|
112
|
+
File.open('.gitarro_vars', 'w') do |file|
|
113
|
+
file.write("GITARRO_PR_AUTHOR: #{pr.head.user.login}\n" \
|
114
|
+
"GITARRO_PR_TITLE: #{pr.title}\n" \
|
115
|
+
"GITARRO_PR_NUMBER: #{pr.number}\n" \
|
116
|
+
"GITARRO_PR_TARGET_REPO: #{@repo}\n")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def export_pr_data_to_file(pr)
|
121
|
+
pr = pr.to_hash
|
122
|
+
pr[:files] = []
|
123
|
+
@client.pull_request_files(@repo, pr[:number]).each do |github_file|
|
124
|
+
pr[:files].push(github_file.to_hash)
|
125
|
+
end
|
126
|
+
File.open('.gitarro_pr.json', 'w') do |file|
|
127
|
+
file.write(JSON.generate(pr))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def export_pr_variables(pr)
|
132
|
+
ENV['GITARRO_PR_AUTHOR'] = pr.head.user.login.to_s
|
133
|
+
ENV['GITARRO_PR_TITLE'] = pr.title.to_s
|
134
|
+
ENV['GITARRO_PR_NUMBER'] = pr.number.to_s
|
135
|
+
ENV['GITARRO_PR_TARGET_REPO'] = @repo
|
136
|
+
end
|
137
|
+
|
104
138
|
def clone_repo(noshallow, pr)
|
105
139
|
shallow = GitShallowClone.new(@git_dir, pr, @options)
|
106
140
|
# by default we use always shallow clone
|
@@ -117,24 +151,6 @@ class TestExecutor
|
|
117
151
|
git.merge_pr_totarget(pr.base.ref, pr.head.ref)
|
118
152
|
git.del_pr_branch(pr.base.ref, pr.head.ref)
|
119
153
|
end
|
120
|
-
|
121
|
-
def export_pr_data_to_hidden_file(pr)
|
122
|
-
# save this file in local dir where gitarro is executed.
|
123
|
-
File.open('.gitarro_vars', 'w') do |file|
|
124
|
-
file.write("GITARRO_PR_AUTHOR: #{pr.head.user.login}\n" \
|
125
|
-
"GITARRO_PR_TITLE: #{pr.title}\n" \
|
126
|
-
"GITARRO_PR_NUMBER: #{pr.number}\n" \
|
127
|
-
"GITARRO_PR_BRANCH: #{pr.head.ref}\n" \
|
128
|
-
"GITARRO_PR_TARGET_REPO: #{@repo}\n")
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def export_pr_variables(pr)
|
133
|
-
ENV['GITARRO_PR_AUTHOR'] = pr.head.user.login.to_s
|
134
|
-
ENV['GITARRO_PR_TITLE'] = pr.title.to_s
|
135
|
-
ENV['GITARRO_PR_NUMBER'] = pr.number.to_s
|
136
|
-
ENV['GITARRO_PR_TARGET_REPO'] = @repo
|
137
|
-
end
|
138
154
|
end
|
139
155
|
|
140
156
|
# this the main public class is the backend of gitarro,
|
@@ -163,6 +179,7 @@ class Backend
|
|
163
179
|
def pr_equal_spefic_branch?(pr)
|
164
180
|
return true if @branch.nil?
|
165
181
|
return true if @branch == pr.base.ref
|
182
|
+
|
166
183
|
puts "branch \"#{pr.base.ref}\" should match github-branch \"#{@branch}\" (given) !!!"
|
167
184
|
puts "skipping tests !!!"
|
168
185
|
false
|
@@ -181,30 +198,38 @@ class Backend
|
|
181
198
|
# public for retrigger the test
|
182
199
|
def retrigger_check(pr)
|
183
200
|
return unless retrigger_needed?(pr)
|
201
|
+
|
184
202
|
create_status(pr, 'pending')
|
185
203
|
print_test_required
|
204
|
+
gbexec.export_pr_data(pr)
|
186
205
|
exit 0 if @check
|
187
206
|
launch_test_and_setup_status(pr) == 'success' ? exit(0) : exit(1)
|
188
207
|
end
|
189
208
|
|
190
209
|
# public always rerun tests against the pr number if this exists
|
191
210
|
def triggered_by_pr_number?
|
192
|
-
return false if @pr_number.nil?
|
211
|
+
return false if @pr_number.nil?
|
212
|
+
|
193
213
|
pr_on_number = @client.pull_request(@repo, @pr_number)
|
194
214
|
puts "Got triggered by PR_NUMBER OPTION, rerunning on #{@pr_number}"
|
195
215
|
print_test_required
|
196
|
-
|
216
|
+
gbexec.export_pr_data(pr)
|
217
|
+
launch_test_and_setup_status(pr_on_number) == 'success' ? exit(0) : exit(1)
|
197
218
|
end
|
198
219
|
|
199
220
|
def unreviewed_new_pr?(pr, comm_st)
|
200
221
|
return unless commit_is_unreviewed?(comm_st)
|
222
|
+
|
201
223
|
pr_all_files_type(pr.number, @file_type)
|
202
224
|
return if empty_files_changed_by_pr?(pr)
|
225
|
+
|
203
226
|
# gb.check is true when there is a job running as scheduler
|
204
227
|
# which doesn't execute the test but trigger another job
|
205
228
|
print_test_required
|
229
|
+
gbexec.export_pr_data(pr)
|
206
230
|
return false if @check
|
207
|
-
|
231
|
+
|
232
|
+
launch_test_and_setup_status(pr) == 'success' ? exit(0) : exit(1)
|
208
233
|
end
|
209
234
|
|
210
235
|
def reviewed_pr?(comm_st, pr)
|
@@ -213,9 +238,11 @@ class Backend
|
|
213
238
|
return false unless context_present?(comm_st) == false ||
|
214
239
|
pending_pr?(comm_st)
|
215
240
|
return false unless pr_all_files_type(pr.number, @file_type).any?
|
241
|
+
|
216
242
|
print_test_required
|
243
|
+
gbexec.export_pr_data(pr)
|
217
244
|
exit(0) if @check
|
218
|
-
launch_test_and_setup_status(pr)
|
245
|
+
launch_test_and_setup_status(pr) == 'success' ? exit(0) : exit(1)
|
219
246
|
end
|
220
247
|
|
221
248
|
# this function will check if the PR contains in comment the magic word
|
@@ -298,6 +325,7 @@ class Backend
|
|
298
325
|
def retrigger_needed?(pr)
|
299
326
|
# we want redo sometimes tests
|
300
327
|
return false unless retriggered_by_comment?(pr.number, @context)
|
328
|
+
|
301
329
|
# if check is set, the comment in the trigger job will be del.
|
302
330
|
# so setting it to pending, it will be remembered
|
303
331
|
pr_all_files_type(pr.number, @file_type).any?
|
data/lib/gitarro/git_op.rb
CHANGED
@@ -67,6 +67,7 @@ class GitOp
|
|
67
67
|
`git pull origin #{upstream}`
|
68
68
|
`git checkout -b #{pr_fix}#{pr_branch} origin/#{pr_branch}`
|
69
69
|
return if $CHILD_STATUS.exitstatus.zero?
|
70
|
+
|
70
71
|
# if it fails the PR contain a forked external repo
|
71
72
|
repo_external.checkout_into
|
72
73
|
end
|
@@ -82,6 +83,7 @@ class GitOp
|
|
82
83
|
def ck_or_clone_git
|
83
84
|
git_repo_dir = git_dir + '/' + @options[:repo].split('/')[1]
|
84
85
|
return if File.directory?(git_repo_dir)
|
86
|
+
|
85
87
|
FileUtils.mkdir_p(git_dir) unless File.directory?(git_dir)
|
86
88
|
Dir.chdir git_dir
|
87
89
|
clone_repo
|
data/lib/gitarro/opt_parser.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitarro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.79
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dario Maiocchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: english
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
version: '0'
|
169
169
|
requirements: []
|
170
170
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.7.3
|
172
172
|
signing_key:
|
173
173
|
specification_version: 4
|
174
174
|
summary: gitarro gem
|