Skip to content

Commit

Permalink
Pronto integration
Browse files Browse the repository at this point in the history
Integration of pronto required to add few new gems and to update some of the gems. The old method which provided the linter launching was reworked to launch pronto which provide the linter launching. The output of pronto is the result of all linters. The pronto result is transformed into a structure which match the original one. This integration required to change few tests and add new ones.
  • Loading branch information
europ committed Feb 23, 2018
1 parent f764857 commit 2dfe28c
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 46 deletions.
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,20 @@ gem 'travis', '~> 1.7.6'

gem 'awesome_spawn', '>= 1.4.1'
gem 'default_value_for'
gem 'haml_lint', '~> 0.20.0', :require => false
gem 'haml_lint', '~> 0.27.0', :require => false
gem 'more_core_extensions', '~> 2.0.0', :require => 'more_core_extensions/all'
gem 'rubocop', '~> 0.52.0', :require => false
gem 'rugged', :require => false

gem 'octokit', '~> 4.6.0', :require => false
gem 'octokit', '~> 4.7.0', :require => false
gem 'faraday', '~> 0.9.1'
gem 'faraday-http-cache', '~> 2.0.0'

gem 'pronto', '~> 0.9.5', :require => false
gem 'pronto-haml', '~> 0.9.0', :require => false
gem 'pronto-rubocop', :require => false
gem 'pronto-yamllint', :require => false

group :development, :test do
gem 'rspec'
gem 'rspec-rails'
Expand Down
60 changes: 45 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.4.0)
arel (6.0.4)
ast (2.3.0)
ast (2.4.0)
awesome_spawn (1.4.1)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
Expand Down Expand Up @@ -125,19 +125,26 @@ GEM
multi_json (~> 1.0)
net-http-persistent (~> 2.9)
net-http-pipeline
gitlab (4.3.0)
httparty
terminal-table
globalid (0.4.0)
activesupport (>= 4.2.0)
haml (4.0.7)
haml (5.0.4)
temple (>= 0.8.0)
tilt
haml_lint (0.20.0)
haml (~> 4.0)
haml_lint (0.27.0)
haml (>= 4.0, < 5.1)
rainbow
rake (>= 10, < 13)
rubocop (>= 0.47.0)
rubocop (>= 0.50.0)
sysexits (~> 1.1)
hashdiff (0.3.6)
highline (1.7.8)
hike (1.2.3)
hitimes (1.2.6)
httparty (0.16.0)
multi_xml (>= 0.5.2)
i18n (0.8.6)
ice_cube (0.14.0)
ice_nine (0.11.2)
Expand Down Expand Up @@ -171,18 +178,34 @@ GEM
more_core_extensions (2.0.0)
activesupport (> 3.2)
multi_json (1.12.2)
multi_xml (0.6.0)
multipart-post (2.0.0)
net-http-persistent (2.9.4)
net-http-pipeline (1.0.1)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
octokit (4.6.2)
octokit (4.7.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.12.1)
parser (2.4.0.2)
ast (~> 2.3)
parser (2.5.0.0)
ast (~> 2.4.0)
pg (0.21.0)
powerpack (0.1.1)
pronto (0.9.5)
gitlab (~> 4.0, >= 4.0.0)
httparty (>= 0.13.7)
octokit (~> 4.7, >= 4.7.0)
rainbow (~> 2.1)
rugged (~> 0.24, >= 0.23.0)
thor (~> 0.19.0)
pronto-haml (0.9.0)
haml_lint (~> 0.23)
pronto (~> 0.9.0)
pronto-rubocop (0.9.0)
pronto (~> 0.9.0)
rubocop (~> 0.38, >= 0.35.0)
pronto-yamllint (0.1.0)
pronto (~> 0.9.0)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
Expand Down Expand Up @@ -219,8 +242,9 @@ GEM
activesupport (= 4.2.10)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
rake (12.1.0)
rainbow (2.2.2)
rake
rake (12.3.0)
rb-fsevent (0.10.2)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
Expand Down Expand Up @@ -251,7 +275,7 @@ GEM
rspec-mocks (~> 3.6.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (0.52.0)
rubocop (0.52.1)
parallel (~> 1.10)
parser (>= 2.4.0.2, < 3.0)
powerpack (~> 0.1)
Expand Down Expand Up @@ -299,14 +323,16 @@ GEM
sprockets (>= 2.8, < 4.0)
sysexits (1.2.0)
temple (0.8.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
thin (1.7.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (0.20.0)
thor (0.19.4)
thread_safe (0.3.6)
tilt (1.4.1)
timecop (0.9.1)
Expand Down Expand Up @@ -368,14 +394,18 @@ DEPENDENCIES
faraday (~> 0.9.1)
faraday-http-cache (~> 2.0.0)
foreman (~> 0.64.0)
haml_lint (~> 0.20.0)
haml_lint (~> 0.27.0)
influxdb (~> 0.3.13)
jquery-rails
listen
minigit (~> 0.0.4)
more_core_extensions (~> 2.0.0)
octokit (~> 4.6.0)
octokit (~> 4.7.0)
pg
pronto (~> 0.9.5)
pronto-haml (~> 0.9.0)
pronto-rubocop
pronto-yamllint
rails (~> 4.2.4)
rspec
rspec-rails
Expand All @@ -396,4 +426,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.15.4
1.16.1
75 changes: 70 additions & 5 deletions app/workers/concerns/code_analysis_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
require 'pronto/runners'
require 'pronto/rubocop'
require 'pronto/yamllint'
require 'pronto/haml'
require 'pronto/git/repository'
require 'pronto/git/patches'
require 'pronto/git/patch'
require 'pronto/git/line'

require 'fileutils'
require 'tmpdir'

module CodeAnalysisMixin
def merged_linter_results
results = {
Expand All @@ -19,11 +31,64 @@ def merged_linter_results
results
end

# run linters via pronto and return the pronto result
def pronto_result
p_result = nil

# temporary solution for: download repo, obtain changes, get pronto result about changes
Dir.mktmpdir do |dir|
FileUtils.copy_entry(@branch.repo.path.to_s, dir)
repo = Pronto::Git::Repository.new(dir)
rg = repo.instance_variable_get(:@repo)
rg.fetch('origin', @branch.name.sub(/^prs/, 'pull'))
rg.checkout('FETCH_HEAD')
rg.reset('HEAD', :hard)
patches = repo.diff(@branch.merge_target)
p_result = Pronto::Runners.new.run(patches)
end

p_result
end

def run_all_linters
unmerged_results = []
unmerged_results << Linter::Rubocop.new(branch).run
unmerged_results << Linter::Haml.new(branch).run
unmerged_results << Linter::Yaml.new(branch).run
unmerged_results.tap(&:compact!)
pronto_result.group_by(&:runner).values.map do |linted| # group by linter
output = {}
if linted.first.runner.name == "Pronto::Rubocop"
output["metadata"] = {
"rubocop_version" => ::RuboCop::Version.version,
"ruby_engine" => RUBY_ENGINE,
"ruby_version" => RUBY_VERSION,
"ruby_patchlevel" => RUBY_PATCHLEVEL.to_s,
"ruby_platform" => RUBY_PLATFORM
}
end

output["files"] = linted.group_by(&:path).map do |path, value| # group by file in linter
{
"path" => path,
"offenses" => value.map do |msg| # put offenses of file in linter into an array
{
"severity" => msg.level.to_s,
"message" => msg.msg,
"cop_name" => msg.runner,
"corrected" => false,
"location" => {
"line" => msg.line.position,
"column" => 0, # TODO value cannot be obtained from Pronto::Message
"length" => msg.line.length
}
}
end
}
end

output["summary"] = {
"offense_count" => output["files"].reduce(0) { |sum, item| sum + item['offenses'].length },
"target_file_count" => output["files"].length,
"inspected_file_count" => 0 # TODO value cannot be obtained from the result of `pronto_result` method
}

output
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- [ ] :exclamation: - [Line 4](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/coding_convention.rb#L4), Col 5 - [Layout/AlignHash](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Layout/AlignHash) - Align the elements of a hash literal if they span more than one line.
**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb**
- [ ] :bomb: :boom: :fire: :fire_engine: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb#L3), Col 1 - [Lint/Syntax](http://rubydoc.info/gems/rubocop/0.52.0/RuboCop/Cop/Lint/Syntax) - unexpected token kEND
- [ ] :bomb: :boom: :fire: :fire_engine: - [Line 3](https://github.com/some_user/some_repo/blob/8942a195a0bfa69ceb82c020c60565408cb46d3e/spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_syntax_error.rb#L3), Col 1 - [Lint/Syntax](http://rubydoc.info/gems/rubocop/#{rubocop_version}/RuboCop/Cop/Lint/Syntax) - unexpected token kEND
(Using Ruby 2.3 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
**spec/workers/commit_monitor_handlers/commit_range/rubocop_checker/data/#{rubocop_check_directory}/ruby_warning.rb**
Expand Down
Loading

0 comments on commit 2dfe28c

Please sign in to comment.