gergich 0.1.7 → 0.1.8

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
  SHA1:
3
- metadata.gz: c38af223553a1be7a59333cfe4ce0a770f9b0c98
4
- data.tar.gz: 423428f965055f10cb76f90b3784c9a49a2b33c5
3
+ metadata.gz: 5e91d3e160dc26c60885d5a592ab9eef51391b70
4
+ data.tar.gz: 40f9cebef25b558687f6d53f4a2e7494184bb006
5
5
  SHA512:
6
- metadata.gz: 6b37e574c51108d6028f291aa401303235ee649156e8d85a3f417ba371d3e0b30e9bc54073aeb691f1c7319d8c57b1916d178a556d473dee5e99dad214e03989
7
- data.tar.gz: e2fa437864953c6097ffb742ff94b29b4de5247f5f64fbf9362b4fe9ededbaa576809cfa0cab20e24f809a447db7b64b942701a3935b07e3f55b2e1a4f815cac
6
+ metadata.gz: c67f46bb7276417ca22c799436a5dc01f009a182d42ec687ad354749dc0ed96c3eb56c480334538efbb2e7124b6096b7b932181888429d0ad92a7ce2be9b07d8
7
+ data.tar.gz: e671d7cfdee7698b2738aa0ff5c4bc4dba82b8dbf405d7852a509e0e4c4d3e5cd6e9c781063ad98d738e6913bb769d31f3e67d5a4a4005fee5931da2fe29619c
data/README.md CHANGED
@@ -99,6 +99,7 @@ do `gergich comment` calls so you don't have to wire it up yourself.
99
99
 
100
100
  `<format>` - One of the following:
101
101
 
102
+ * `brakeman`
102
103
  * `rubocop`
103
104
  * `eslint`
104
105
  * `i18nliner`
@@ -135,15 +135,15 @@ module Gergich
135
135
  puts "Cover Message:"
136
136
  puts review_info[:cover_message]
137
137
 
138
- unless review_info[:comments].empty?
139
- puts
140
- puts "Inline Comments:"
141
- puts
138
+ return if review_info[:comments].empty?
142
139
 
143
- review_info[:comments].each do |file, comments|
144
- comments.each do |comment|
145
- puts "#{file}:#{comment[:line] || comment[:range]['start_line']}\n#{comment[:message]}"
146
- end
140
+ puts
141
+ puts "Inline Comments:"
142
+ puts
143
+
144
+ review_info[:comments].each do |file, comments|
145
+ comments.each do |comment|
146
+ puts "#{file}:#{comment[:line] || comment[:range]['start_line']}\n#{comment[:message]}"
147
147
  end
148
148
  end
149
149
  end
@@ -362,10 +362,10 @@ module Gergich
362
362
  POSITION_KEYS = %w[end_character end_line start_character start_line].freeze
363
363
  def valid_position?(position)
364
364
  (
365
- position.is_a?(Fixnum) && position >= 0
365
+ position.is_a?(Integer) && position >= 0
366
366
  ) || (
367
367
  position.is_a?(Hash) && position.keys.sort == POSITION_KEYS &&
368
- position.values.all? { |v| v.is_a?(Fixnum) && v >= 0 }
368
+ position.values.all? { |v| v.is_a?(Integer) && v >= 0 }
369
369
  )
370
370
  end
371
371
 
@@ -407,7 +407,7 @@ module Gergich
407
407
  end
408
408
 
409
409
  def min_comment_score
410
- all_comments.inject(0) { |a, e| [a, e.min_score].min }
410
+ all_comments.inject(0) { |acc, elem| [acc, elem.min_score].min }
411
411
  end
412
412
 
413
413
  def changed_files
@@ -441,7 +441,7 @@ module Gergich
441
441
  other_comments.each do |file|
442
442
  file.comments.each do |position, comments|
443
443
  comments.each do |comment|
444
- line = position.is_a?(Fixnum) ? position : position["start_line"]
444
+ line = position.is_a?(Integer) ? position : position["start_line"]
445
445
  message << "\n\n#{file.path}:#{line}: #{comment}"
446
446
  end
447
447
  end
@@ -482,8 +482,8 @@ module Gergich
482
482
  def to_a
483
483
  comments.map do |position, position_comments|
484
484
  comment = position_comments.join("\n\n")
485
- position_key = position.is_a?(Fixnum) ? :line : :range
486
- position = JSON.parse(position) unless position.is_a?(Fixnum)
485
+ position_key = position.is_a?(Integer) ? :line : :range
486
+ position = JSON.parse(position) unless position.is_a?(Integer)
487
487
  {
488
488
  :message => comment,
489
489
  position_key => position
@@ -0,0 +1,29 @@
1
+ module Gergich
2
+ module Capture
3
+ class BrakemanCapture < BaseCapture
4
+ # Map Brakeman "confidence level" to severity.
5
+ # http://brakemanscanner.org/docs/confidence/
6
+ SEVERITY_MAP = {
7
+ "Weak" => "warn",
8
+ "Medium" => "warn",
9
+ "High" => "error"
10
+ }.freeze
11
+
12
+ def run(output)
13
+ # See brakeman_example.json for sample output.
14
+ JSON.parse(output)["warnings"].map { |warning|
15
+ message = "[brakeman] #{warning['warning_type']}: #{warning['message']}"
16
+ message += "\n Code: #{warning['code']}" if warning["code"]
17
+ message += "\n User Input: #{warning['user_input']}" if warning["user_input"]
18
+ message += "\n See: #{warning['link']}" if warning["link"]
19
+ {
20
+ path: warning["file"],
21
+ position: warning["line"] || 0,
22
+ message: message,
23
+ severity: SEVERITY_MAP[warning["confidence"]]
24
+ }
25
+ }.compact
26
+ end
27
+ end
28
+ end
29
+ end
@@ -22,8 +22,12 @@ module Gergich
22
22
 
23
23
  output.scan(pattern).map { |file, line, severity, error, context|
24
24
  context = "\n\n" + context.gsub(/^/, " ") if context
25
- { path: file, message: "[rubocop] #{error}#{context}",
26
- position: line.to_i, severity: SEVERITY_MAP[severity] }
25
+ {
26
+ path: file,
27
+ position: line.to_i,
28
+ message: "[rubocop] #{error}#{context}",
29
+ severity: SEVERITY_MAP[severity]
30
+ }
27
31
  }.compact
28
32
  end
29
33
  end
@@ -201,6 +201,7 @@ For common linting formats, `gergich capture` can be used to automatically
201
201
  do `gergich comment` calls so you don't have to wire it up yourself.
202
202
 
203
203
  <format> - One of the following:
204
+ * brakeman
204
205
  * rubocop
205
206
  * eslint
206
207
  * i18nliner
@@ -0,0 +1,89 @@
1
+ require_relative "../../support/capture_shared_examples"
2
+
3
+ RSpec.describe Gergich::Capture::BrakemanCapture do
4
+ let(:output) do
5
+ File.read(
6
+ File.expand_path(File.dirname(__FILE__) + "/brakeman_example.json")
7
+ )
8
+ end
9
+
10
+ let(:comments) do
11
+ [
12
+ {
13
+ path: "app/models/custom_data.rb",
14
+ position: 36,
15
+ message: <<-MESSAGE.strip,
16
+ [brakeman] Attribute Restriction: attr_accessible is recommended over attr_protected
17
+ See: http://brakemanscanner.org/docs/warning_types/attribute_restriction/
18
+ MESSAGE
19
+ severity: "warn"
20
+ },
21
+ {
22
+ path: "app/models/submission_comment.rb",
23
+ position: 0,
24
+ message: <<-MESSAGE.strip,
25
+ [brakeman] Mass Assignment: Potentially dangerous attribute available for mass assignment
26
+ Code: :context_id
27
+ See: http://brakemanscanner.org/docs/warning_types/mass_assignment/
28
+ MESSAGE
29
+ severity: "warn"
30
+ },
31
+ {
32
+ path: "app/controllers/context_controller.rb",
33
+ position: 60,
34
+ message: <<-MESSAGE.strip,
35
+ [brakeman] Redirect: Possible unprotected redirect
36
+ Code: redirect_to(CanvasKaltura::ClientV3.new.assetSwfUrl(params[:id]))
37
+ User Input: params[:id]
38
+ See: http://brakemanscanner.org/docs/warning_types/redirect/
39
+ MESSAGE
40
+ severity: "warn"
41
+ },
42
+ {
43
+ path: "app/views/context/object_snippet.html.erb",
44
+ position: 6,
45
+ message: <<-MESSAGE.strip,
46
+ [brakeman] Cross Site Scripting: Unescaped parameter value
47
+ Code: Base64.decode64((params[:object_data] or ""))
48
+ User Input: params[:object_data]
49
+ See: http://brakemanscanner.org/docs/warning_types/cross_site_scripting
50
+ MESSAGE
51
+ severity: "warn"
52
+ },
53
+ {
54
+ path: "app/models/account.rb",
55
+ position: 795,
56
+ message: <<-MESSAGE.strip,
57
+ [brakeman] SQL Injection: Possible SQL injection
58
+ Code: Account.find_by_sql(Account.sub_account_ids_recursive_sql(parent_account_id))
59
+ User Input: Account.sub_account_ids_recursive_sql(parent_account_id)
60
+ See: http://brakemanscanner.org/docs/warning_types/sql_injection/
61
+ MESSAGE
62
+ severity: "error"
63
+ },
64
+ {
65
+ path: "lib/cc/importer/blti_converter.rb",
66
+ position: 145,
67
+ message: <<-MESSAGE.strip,
68
+ [brakeman] SSL Verification Bypass: SSL certificate verification was bypassed
69
+ Code: Net::HTTP.new(URI.parse(url).host, URI.parse(url).port).verify_mode = OpenSSL::SSL::VERIFY_NONE
70
+ See: http://brakemanscanner.org/docs/warning_types/ssl_verification_bypass/
71
+ MESSAGE
72
+ severity: "error"
73
+ },
74
+ {
75
+ path: "lib/cc/importer/canvas/quiz_converter.rb",
76
+ position: 44,
77
+ message: <<-MESSAGE.strip,
78
+ [brakeman] Command Injection: Possible command injection
79
+ Code: `\#{Qti.get_conversion_command(File.join(qti_folder, "qti_2_1"), qti_folder)}`
80
+ User Input: Qti.get_conversion_command(File.join(qti_folder, "qti_2_1"), qti_folder)
81
+ See: http://brakemanscanner.org/docs/warning_types/command_injection/
82
+ MESSAGE
83
+ severity: "warn"
84
+ }
85
+ ]
86
+ end
87
+
88
+ it_behaves_like "a captor"
89
+ end
@@ -23,10 +23,10 @@ lib/gergich.rb:22:55: W: Line is too long. [55/54]
23
23
  path: "lib/gergich.rb",
24
24
  position: 22,
25
25
  message: <<-OUTPUT,
26
- [rubocop] Line is too long. [55/54]
26
+ [rubocop] Line is too long. [55/54]
27
27
 
28
- def initialize(ref = "HEAD", revision_number = nil)
29
- ^^
28
+ def initialize(ref = "HEAD", revision_number = nil)
29
+ ^^
30
30
  OUTPUT
31
31
  severity: "warn"
32
32
  }
@@ -11,7 +11,7 @@ RSpec.shared_examples_for "a captor" do
11
11
  end
12
12
 
13
13
  it "catches errors" do
14
- comments = subject.run(output)
15
- expect(comments).to match_array(comments)
14
+ parsed_comments = subject.run(output)
15
+ expect(parsed_comments).to match_array(comments)
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,43 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gergich
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-26 00:00:00.000000000 Z
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
41
97
  description: Gergich is a little command-line tool for wiring up linters to Gerrit
42
98
  so you can get nice inline comments right on the review
43
99
  email: jon@instructure.com
@@ -56,6 +112,7 @@ files:
56
112
  - lib/gergich.rb
57
113
  - lib/gergich/capture.rb
58
114
  - lib/gergich/capture/androidlint_capture.rb
115
+ - lib/gergich/capture/brakeman_capture.rb
59
116
  - lib/gergich/capture/eslint_capture.rb
60
117
  - lib/gergich/capture/flake8_capture.rb
61
118
  - lib/gergich/capture/i18nliner_capture.rb
@@ -66,6 +123,7 @@ files:
66
123
  - lib/gergich/cli/gergich.rb
67
124
  - lib/gergich/cli/master_bouncer.rb
68
125
  - spec/gergich/capture/androidlint_capture_spec.rb
126
+ - spec/gergich/capture/brakeman_capture_spec.rb
69
127
  - spec/gergich/capture/custom_capture_spec.rb
70
128
  - spec/gergich/capture/eslint_capture_spec.rb
71
129
  - spec/gergich/capture/flake8_capture_spec.rb
@@ -87,19 +145,18 @@ require_paths:
87
145
  - lib
88
146
  required_ruby_version: !ruby/object:Gem::Requirement
89
147
  requirements:
90
- - - ">="
148
+ - - '>='
91
149
  - !ruby/object:Gem::Version
92
150
  version: 1.9.3
93
151
  required_rubygems_version: !ruby/object:Gem::Requirement
94
152
  requirements:
95
- - - ">="
153
+ - - '>='
96
154
  - !ruby/object:Gem::Version
97
155
  version: '0'
98
156
  requirements: []
99
157
  rubyforge_project:
100
- rubygems_version: 2.2.5
158
+ rubygems_version: 2.4.8
101
159
  signing_key:
102
160
  specification_version: 4
103
161
  summary: Command-line tool for adding Gerrit comments
104
162
  test_files: []
105
- has_rdoc: