gergich 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +5 -5
  2. data/{bin → exe}/gergich +0 -0
  3. data/{bin → exe}/master_bouncer +0 -0
  4. data/lib/gergich/capture/androidlint_capture.rb +10 -5
  5. data/lib/gergich/capture/brakeman_capture.rb +3 -2
  6. data/lib/gergich/capture/eslint_capture.rb +2 -1
  7. data/lib/gergich/capture/flake8_capture.rb +1 -1
  8. data/lib/gergich/capture/i18nliner_capture.rb +1 -1
  9. data/lib/gergich/capture/rubocop_capture.rb +38 -3
  10. data/lib/gergich/capture/shellcheck_capture.rb +2 -1
  11. data/lib/gergich/capture/stylelint_capture.rb +2 -5
  12. data/lib/gergich/capture/swiftlint_capture.rb +3 -3
  13. data/lib/gergich/capture/yamllint_capture.rb +31 -0
  14. data/lib/gergich/capture.rb +12 -5
  15. data/lib/gergich/cli/gergich.rb +6 -4
  16. data/lib/gergich/cli/master_bouncer.rb +6 -6
  17. data/lib/gergich/cli.rb +1 -1
  18. data/lib/gergich.rb +27 -28
  19. metadata +65 -41
  20. data/LICENSE +0 -20
  21. data/README.md +0 -178
  22. data/bin/check_coverage +0 -8
  23. data/bin/run_tests.sh +0 -52
  24. data/spec/gergich/capture/androidlint_capture_spec.rb +0 -61
  25. data/spec/gergich/capture/brakeman_capture_spec.rb +0 -91
  26. data/spec/gergich/capture/custom_capture_spec.rb +0 -41
  27. data/spec/gergich/capture/eslint_capture_spec.rb +0 -31
  28. data/spec/gergich/capture/flake8_capture_spec.rb +0 -23
  29. data/spec/gergich/capture/i18nliner_capture_spec.rb +0 -25
  30. data/spec/gergich/capture/rubocop_capture_spec.rb +0 -66
  31. data/spec/gergich/capture/shellcheck_capture_spec.rb +0 -83
  32. data/spec/gergich/capture/stylelint_capture_spec.rb +0 -54
  33. data/spec/gergich/capture/swiftlint_capture_spec.rb +0 -42
  34. data/spec/gergich/capture_spec.rb +0 -75
  35. data/spec/gergich_spec.rb +0 -379
  36. data/spec/spec_helper.rb +0 -92
  37. data/spec/support/capture_shared_examples.rb +0 -19
data/spec/gergich_spec.rb DELETED
@@ -1,379 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Gergich::API do
4
- context "bad change-id" do
5
- let(:result) { double(:result, body: "Not Found: 1234") }
6
-
7
- before :each do
8
- allow(HTTParty).to receive(:send).and_return(result)
9
- allow(described_class).to receive(:prepare_options).and_return({})
10
- end
11
-
12
- it "provides helpful error when Change-Id not found" do
13
- # Get ride of CI_TEST_RUN environment variable so the api preforms normally
14
- ENV["CI_TEST_RUN"] = nil
15
- expect { described_class.get("/a/changes/1234") }
16
- .to raise_error(/Cannot find Change-Id: 1234/)
17
- end
18
- end
19
-
20
- context "GERGICH_DIGEST_AUTH exists" do
21
- it "uses digest auth" do
22
- original_basic_auth = ENV["GERGICH_DIGEST_AUTH"]
23
- ENV["GERGICH_DIGEST_AUTH"] = "1"
24
- original_gergich_key = ENV["GERGICH_KEY"]
25
- ENV["GERGICH_KEY"] = "foo"
26
- allow(described_class).to receive(:base_uri).and_return("https://gerrit.foobar.com")
27
-
28
- expect(described_class.send(:prepare_options, {}))
29
- .to match(
30
- hash_including(
31
- digest_auth: { username: "gergich", password: ENV["GERGICH_KEY"] }
32
- )
33
- )
34
-
35
- ENV["GERGICH_DIGEST_AUTH"] = original_basic_auth
36
- ENV["GERGICH_KEY"] = original_gergich_key
37
- end
38
- end
39
-
40
- context "GERGICH_DIGEST_AUTH does not exist" do
41
- it "uses basic auth" do
42
- original_basic_auth = ENV["GERGICH_DIGEST_AUTH"]
43
- ENV["GERGICH_DIGEST_AUTH"] = nil
44
- original_gergich_key = ENV["GERGICH_KEY"]
45
- ENV["GERGICH_KEY"] = "foo"
46
- allow(described_class).to receive(:base_uri).and_return("https://gerrit.foobar.com")
47
-
48
- expect(described_class.send(:prepare_options, {}))
49
- .to match(hash_including(basic_auth: { username: "gergich", password: ENV["GERGICH_KEY"] }))
50
-
51
- ENV["GERGICH_DIGEST_AUTH"] = original_basic_auth
52
- ENV["GERGICH_KEY"] = original_gergich_key
53
- end
54
- end
55
- end
56
-
57
- RSpec.describe Gergich::Commit do
58
- before :each do
59
- allow(Gergich).to receive(:use_git?).and_return(false)
60
- end
61
-
62
- context "change_id works" do
63
- it "supports branches with slashes" do
64
- allow(ENV).to receive(:[]).with("GERRIT_PATCHSET_REVISION").and_return("commit-ish")
65
- allow(ENV).to receive(:[]).with("GERRIT_PROJECT").and_return("spec-project")
66
- allow(ENV).to receive(:[]).with("GERRIT_BRANCH").and_return("releases/2017.11.17")
67
- allow(ENV).to receive(:[]).with("GERRIT_CHANGE_ID").and_return("dummychangeset")
68
-
69
- expect(described_class.new.change_id) # %2F = / and %7E = ~
70
- .to match("spec-project~releases%2F2017.11.17~dummychangeset")
71
- end
72
- end
73
- end
74
-
75
- RSpec.describe Gergich::Draft do
76
- let!(:draft) do
77
- commit = double(
78
- :commit,
79
- files: [
80
- "foo.rb",
81
- "bar/baz.lol"
82
- ],
83
- revision_id: "test",
84
- change_id: "test"
85
- )
86
- described_class.new commit
87
- end
88
-
89
- after do
90
- draft.reset!
91
- end
92
-
93
- describe "#info" do
94
- subject { draft.info }
95
-
96
- describe "[:comments]" do
97
- subject { super()[:comments] }
98
-
99
- it "includes file comments" do
100
- draft.add_comment "foo.rb", 1, "fix foo", "info"
101
- expect(subject).to eq("foo.rb" => [{ line: 1, message: "[INFO] fix foo" }])
102
- end
103
-
104
- it "strips whitespace from filename" do
105
- draft.add_comment " foo.rb\n", 1, "fix foo", "info"
106
- expect(subject).to eq("foo.rb" => [{ line: 1, message: "[INFO] fix foo" }])
107
- end
108
-
109
- it "includes COMMIT_MSG comments" do
110
- draft.add_comment "/COMMIT_MSG", 1, "fix commit", "info"
111
- expect(subject).to eq("/COMMIT_MSG" => [{ line: 1, message: "[INFO] fix commit" }])
112
- end
113
-
114
- it "doesn't include orphaned file comments" do
115
- draft.add_comment "invalid.rb", 1, "fix invalid", "info"
116
- expect(subject).to eq({})
117
- end
118
- end
119
-
120
- describe "[:cover_message_parts]" do
121
- subject { super()[:cover_message_parts] }
122
- let(:message_1) { "this is good" }
123
- let(:message_2) { "loljk it's terrible" }
124
-
125
- it "includes explicitly added messages" do
126
- draft.add_message message_1
127
- draft.add_message message_2
128
-
129
- expect(subject).to include(message_1)
130
- expect(subject).to include(message_2)
131
- end
132
-
133
- context "orphaned file comments exist" do
134
- let(:orphaned_comment) { "fix invalid" }
135
-
136
- before :each do
137
- draft.add_comment "invalid.rb", 1, orphaned_comment, "info"
138
- end
139
-
140
- it "includes orphan file message" do
141
- expect(subject.first).to match(/#{orphaned_comment}/)
142
- end
143
- end
144
- end
145
-
146
- describe "[:total_comments]" do
147
- subject { super()[:total_comments] }
148
-
149
- it "includes inline and orphaned comments" do
150
- draft.add_comment "foo.rb", 1, "fix foo", "info"
151
- draft.add_comment "invalid.rb", 1, "fix invalid", "info"
152
- expect(subject).to eq 2
153
- end
154
- end
155
-
156
- describe "[:labels]" do
157
- subject { super()[:labels] }
158
-
159
- it "uses the lowest score for each label" do
160
- draft.add_label "QA-Review", 1
161
- draft.add_label "QA-Review", -1
162
- draft.add_label "Code-Review", -2
163
- draft.add_label "Code-Review", 1
164
-
165
- expect(subject).to eq(
166
- "QA-Review" => -1,
167
- "Code-Review" => -2
168
- )
169
- end
170
-
171
- it "disallows \"Verified\"" do
172
- expect { draft.add_label "Verified", 1 }.to raise_error(/can't set Verified/)
173
- end
174
-
175
- it "disallows scores > 1" do
176
- expect { draft.add_label "Foo", 2 }.to raise_error(/invalid score/)
177
- end
178
-
179
- describe "[\"Code-Review\"]" do
180
- subject { super()["Code-Review"] }
181
-
182
- it "defaults to zero" do
183
- expect(subject).to eq(0)
184
- end
185
-
186
- it "is the lowest comment severity if not set" do
187
- draft.add_comment "foo.rb", 1, "fix foo", "info"
188
- draft.add_comment "foo.rb", 2, "fix foo", "error"
189
- draft.add_comment "foo.rb", 3, "fix foo", "warn"
190
-
191
- expect(subject).to eq(-2)
192
- end
193
-
194
- it "is trumped by a lower comment severity if negative" do
195
- draft.add_label "Code-Review", 1
196
- draft.add_comment "foo.rb", 1, "fix foo", "warn"
197
-
198
- expect(subject).to eq(-1)
199
- end
200
-
201
- it "is not trumped by a lower comment severity if zero" do
202
- draft.add_label "Code-Review", 1
203
- draft.add_comment "foo.rb", 1, "this is ok", "info"
204
-
205
- expect(subject).to eq(1)
206
- end
207
-
208
- it "is not trumped by a higher comment severity" do
209
- draft.add_label "Code-Review", -1
210
- draft.add_comment "foo.rb", 1, "this is ok", "info"
211
-
212
- expect(subject).to eq(-1)
213
- end
214
- end
215
- end
216
- end
217
- end
218
-
219
- RSpec.describe Gergich::Review do
220
- let(:change_id) { "test" }
221
- let!(:commit) do
222
- double(
223
- :commit,
224
- change_id: change_id,
225
- files: [
226
- "foo.rb",
227
- "bar/baz.lol"
228
- ],
229
- info: {},
230
- revision_id: change_id,
231
- revision_number: 1
232
- )
233
- end
234
- let!(:draft) do
235
- Gergich::Draft.new commit
236
- end
237
- let!(:review) { described_class.new(commit, draft) }
238
-
239
- after do
240
- draft.reset!
241
- end
242
-
243
- describe "#status" do
244
- subject { review.status }
245
-
246
- context "nothing to publish" do
247
- before :each do
248
- allow(review).to receive(:anything_to_publish?).and_return(false)
249
- end
250
- it { expect { subject }.to output(include("Nothing to publish")).to_stdout }
251
- end
252
-
253
- context "something to publish" do
254
- before :each do
255
- allow(review).to receive(:anything_to_publish?).and_return(true)
256
- allow(review).to receive(:already_commented?).and_return(false)
257
- allow(review).to receive(:generate_payload).and_return({})
258
- allow(review).to receive(:my_messages).and_return([])
259
- end
260
- it {
261
- expected_outputs = [
262
- "Project:",
263
- "Branch:",
264
- "Revision:",
265
- "ChangeId: #{change_id}",
266
- "Files:"
267
- # There's more... but this is good
268
- ]
269
- expect { subject }.to output(include(*expected_outputs)).to_stdout
270
- }
271
- end
272
- end
273
-
274
- describe "#publish!" do
275
- context "nothing to publish" do
276
- before :each do
277
- allow(review).to receive(:anything_to_publish?).and_return(false)
278
- end
279
-
280
- it "does nothing" do
281
- expect(Gergich::API).not_to receive(:post)
282
-
283
- review.publish!
284
- end
285
- end
286
-
287
- context "something to publish" do
288
- before :each do
289
- allow(review).to receive(:anything_to_publish?).and_return(true)
290
- allow(review).to receive(:already_commented?).and_return(false)
291
- allow(review).to receive(:generate_payload).and_return({})
292
- end
293
-
294
- it "publishes via the api" do
295
- expect(Gergich::API).to receive(:post)
296
- review.publish!
297
- end
298
- end
299
- end
300
-
301
- describe "#anything_to_publish?" do
302
- before :each do
303
- allow(review).to receive(:current_label).and_return("BAHA")
304
- allow(review).to receive(:current_label_revision).and_return("Revision trash stuff")
305
- end
306
-
307
- context "no comments exist" do
308
- it "returns false" do
309
- allow(review).to receive(:new_score?).and_return(false)
310
- expect(review.anything_to_publish?).to eq false
311
- end
312
- end
313
-
314
- context "comments exist" do
315
- it "returns true" do
316
- draft.info[:comments] = "Hello there this is a comment"
317
- expect(review.anything_to_publish?).to eq true
318
- end
319
- end
320
- end
321
-
322
- describe "#new_score?" do
323
- before :each do
324
- allow(review).to receive(:current_label_is_for_current_revision?).and_return(true)
325
- allow(review).to receive(:current_score).and_return(0)
326
- end
327
-
328
- context "score is the same" do
329
- it "returns false" do
330
- draft.info[:score] = 0
331
- expect(review.new_score?).to eq false
332
- end
333
- end
334
-
335
- context "score is different" do
336
- it "returns true" do
337
- draft.info[:score] = -1
338
- expect(review.new_score?).to eq true
339
- end
340
- end
341
- end
342
-
343
- describe "#upcoming_score" do
344
- context "current_label_is_for_current_revision? is true" do
345
- it "Should return the min value of draft.info[:score] and current_score" do
346
- allow(review).to receive(:current_label_is_for_current_revision?).and_return(true)
347
- allow(review).to receive(:current_score).and_return(0)
348
- review.draft.info[:score] = 1
349
- expect(review.upcoming_score).to eq 0
350
- end
351
- end
352
-
353
- context "current_label_is_for_current_revision? is false" do
354
- it "Should return the value of draft.info[:score]" do
355
- allow(review).to receive(:current_label_is_for_current_revision?).and_return(false)
356
- review.draft.info[:score] = 1
357
- expect(review.upcoming_score).to eq 1
358
- end
359
- end
360
- end
361
-
362
- describe "#cover_message" do
363
- context "score is negative" do
364
- it "includes the Code-Review score if negative" do
365
- allow(review).to receive(:upcoming_score).and_return(-1)
366
- review.draft.add_label "Code-Review", -1
367
- expect(review.cover_message).to match(/^-1/)
368
- end
369
- end
370
-
371
- context "score is non-negative" do
372
- it "doesn't include the score if not negative" do
373
- allow(review).to receive(:upcoming_score).and_return(0)
374
- draft.add_label "Code-Review", 0
375
- expect(subject).to_not match(/^0/)
376
- end
377
- end
378
- end
379
- end
data/spec/spec_helper.rb DELETED
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "simplecov" if ENV["COVERAGE"]
4
- require_relative "../lib/gergich"
5
-
6
- # This file was generated by the `rspec --init` command. Conventionally, all
7
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
- # The generated `.rspec` file contains `--require spec_helper` which will cause
9
- # this file to always be loaded, without a need to explicitly require it in any
10
- # files.
11
- #
12
- # Given that it is always loaded, you are encouraged to keep this file as
13
- # light-weight as possible. Requiring heavyweight dependencies from this file
14
- # will add to the boot time of your test suite on EVERY test run, even for an
15
- # individual file that may not need all of that loaded. Instead, consider making
16
- # a separate helper file that requires the additional dependencies and performs
17
- # the additional setup, and require it from the spec files that actually need
18
- # it.
19
- #
20
- # The `.rspec` file also contains a few flags that are not defaults but that
21
- # users commonly want.
22
- #
23
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
- RSpec.configure do |config|
25
- # rspec-expectations config goes here. You can use an alternate
26
- # assertion/expectation library such as wrong or the stdlib/minitest
27
- # assertions if you prefer.
28
- config.expect_with :rspec do |expectations|
29
- # This option will default to `true` in RSpec 4. It makes the `description`
30
- # and `failure_message` of custom matchers include text for helper methods
31
- # defined using `chain`, e.g.:
32
- # be_bigger_than(2).and_smaller_than(4).description
33
- # # => "be bigger than 2 and smaller than 4"
34
- # ...rather than:
35
- # # => "be bigger than 2"
36
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
- end
38
-
39
- # rspec-mocks config goes here. You can use an alternate test double
40
- # library (such as bogus or mocha) by changing the `mock_with` option here.
41
- config.mock_with :rspec do |mocks|
42
- # Prevents you from mocking or stubbing a method that does not exist on
43
- # a real object. This is generally recommended, and will default to
44
- # `true` in RSpec 4.
45
- mocks.verify_partial_doubles = true
46
- end
47
-
48
- # These two settings work together to allow you to limit a spec run
49
- # to individual examples or groups you care about by tagging them with
50
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
- # get run.
52
- config.filter_run :focus
53
- config.run_all_when_everything_filtered = true
54
-
55
- # Limits the available syntax to the non-monkey patched syntax that is
56
- # recommended. For more details, see:
57
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
- config.disable_monkey_patching!
61
-
62
- # This setting enables warnings. It's recommended, but in some cases may
63
- # be too noisy due to issues in dependencies.
64
- config.warnings = true
65
-
66
- # Many RSpec users commonly either run the entire suite or an individual
67
- # file, and it's useful to allow more verbose output when running an
68
- # individual spec file.
69
- if config.files_to_run.one?
70
- # Use the documentation formatter for detailed output,
71
- # unless a formatter has already been configured
72
- # (e.g. via a command-line flag).
73
- config.default_formatter = "doc"
74
- end
75
-
76
- # Print the 10 slowest examples and example groups at the
77
- # end of the spec run, to help surface which specs are running
78
- # particularly slow.
79
- config.profile_examples = 10
80
-
81
- # Run specs in random order to surface order dependencies. If you find an
82
- # order dependency and want to debug it, you can fix the order by providing
83
- # the seed, which is printed after each run.
84
- # --seed 1234
85
- config.order = :random
86
-
87
- # Seed global randomization in this process using the `--seed` CLI option.
88
- # Setting this allows you to use `--seed` to deterministically reproduce
89
- # test failures related to randomization by passing the same `--seed` value
90
- # as the one that triggered the failure.
91
- Kernel.srand config.seed
92
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../../lib/gergich/capture"
4
-
5
- RSpec.shared_examples_for "a captor" do
6
- let(:capture_format) do
7
- Gergich::Capture::BaseCapture.normalize_captor_class_name(described_class)
8
- end
9
-
10
- it "loads" do
11
- captor = Gergich::Capture.load_captor(capture_format)
12
- expect(captor).to eq(described_class)
13
- end
14
-
15
- it "catches errors" do
16
- parsed_comments = subject.run(output)
17
- expect(parsed_comments).to match_array(comments)
18
- end
19
- end