code_quality 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80898f3a14a7a561070acc6cbc3a4e6d8285d451adcd921f51c8cd99535016dc
4
- data.tar.gz: 20b1ed6739d35f1abc60143205518dfedb9c716b29f06134872c94aa5548afd3
3
+ metadata.gz: c97a301536ac1e5078182bd45230e6adfa3a2c472bdceee4982844e27d536441
4
+ data.tar.gz: 98a33f7a35c23d1a787f534e2847c3b664310b7751d1864ef109b9c88412b841
5
5
  SHA512:
6
- metadata.gz: 91dab9cb07414281a9f6fad6a6906ab3e5b8d69a59ff045e88f284e4c0ecd0df30b1fa872258882ae065edcd13170dd4e24387d323547501d2dad44eb43005ca
7
- data.tar.gz: aa5c50f26224d0a170b731f4a8a2f394d083247e49b4e088c69cbf38180c8f6137c7f1d5a61fdad37543c229cf1beeb14fcc97e1d527cf887f10bc7fe9b95add
6
+ metadata.gz: d394a0c35a8ee45ca255f071b279a8eb6effda067333e9c5df9b938b3f1c2c27c281516147f0a91efa4939dd53280c27caa5e34d01adf3758d0bc7cd3863c040
7
+ data.tar.gz: d6a4d1502a04558ba0d6be06bdf0d080723b10d18203edf21268798af22a621d398026b84103808f958b00ff1c53738e95233882f15b422b604ddea54229da01
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ config/.rubocop-https---rawgit-com-rails-rails-master--rubocop-yml
14
+ Gemfile.lock
@@ -4,12 +4,26 @@ rvm:
4
4
  - 2.4.3
5
5
  before_install: gem install bundler -v 1.16.0
6
6
 
7
- # automatically release Ruby gem to RubyGems after a successful build with `git push --tags`
7
+ # config GitHub OAuth Token
8
+ env:
9
+ global:
10
+ secure: HLfW6QDOiyxaM7wBRDzdF9ud0Ey1EVL/rdnvt8TvM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rHeCnjmhcMsKopzc4FLOq9B7j1WCbmeGx3scXsZkjcugwnAUm07imlUQzHO85tVxZuDbPvBQ/J/vBhuUIl1E7ptUx0eUXrVWTGDsM7RIgt87O96QXthGgVg9NYmTmvMAjts8W0zfhAQIc/13QZUYvXQ6qX95Xu4RkmeTX7T63hpqKlwSCbYbQTBF3T5X9xyKkeF0BLHZ1jMIyoOoKZFsZL+ESrpCEeq8ZDaod6Az2rIa3KgszKxV/w5vyIInhg+lzX9RF5JL8X9q9hVEvIIx5BGQWXI=
12
- gem: code_quality
13
- on:
14
- tags: true
15
- repo: rainchen/code_quality
13
+ # automatically release Ruby gem to RubyGems after a successful build with `git push --tags`
14
+ - provider: rubygems
15
+ api_key:
16
+ secure: mzjlQXKByIn4jdGzUayX65Xqnl9zSkvJJZZnoqZuVnRjz93veVm9mwfUGGcSNQj9dvQTedrxMLyOKINJMIH+SlveHUeU04a7QxbM6i7o+sWRFEq98p7DauSpJJTB4fDINSwjcHU8t43PjhBItA6n4PLUrCuIzXqxvY4VLHgGLGkXV17ngdHBRRFFDuMS0npsTLLfaqaFtyYx/mer/z9pSGR9g4ETsfVFSBNafPfDAoXfK3WRLbqS8EkB7SXCSliOUuzLBEOSLy8xMOAS682dEsPZzUvUGBMrXLYhxVBECfzAMzk2VxRX0MujJxzQyGiKZUShLkDVSulkah+aHhcMqcQ0VewcELihNj86tPEtT7Uiwd6aSe0J9WrgeVE2jkaPcIZyN3eAfZ4QhQrdrHeCnjmhcMsKopzc4FLOq9B7j1WCbmeGx3scXsZkjcugwnAUm07imlUQzHO85tVxZuDbPvBQ/J/vBhuUIl1E7ptUx0eUXrVWTGDsM7RIgt87O96QXthGgVg9NYmTmvMAjts8W0zfhAQIc/13QZUYvXQ6qX95Xu4RkmeTX7T63hpqKlwSCbYbQTBF3T5X9xyKkeF0BLHZ1jMIyoOoKZFsZL+ESrpCEeq8ZDaod6Az2rIa3KgszKxV/w5vyIInhg+lzX9RF5JL8X9q9hVEvIIx5BGQWXI=
17
+ gem: code_quality
18
+ on:
19
+ tags: true
20
+ repo: rainchen/code_quality
21
+
22
+ # publish generated files to GitHub pages
23
+ - provider: script
24
+ skip_cleanup: true
25
+ script: bin/travis-update-gh-pages.sh
26
+ on:
27
+ branch: master
28
+ tags: true
29
+ condition: $TRAVIS_PULL_REQUEST = "false"
data/README.md CHANGED
@@ -4,6 +4,7 @@ Run code quality and security audit report with one rake task as `rake code_qual
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/code_quality.svg)](https://badge.fury.io/rb/code_quality)
6
6
  [![Build Status](https://travis-ci.org/rainchen/code_quality.svg)](https://travis-ci.org/rainchen/code_quality)
7
+ [![HitCount](http://hits.dwyl.io/rainchen/code_quality.svg)](http://hits.dwyl.io/rainchen/code_quality)
7
8
 
8
9
  ## Principle
9
10
 
@@ -47,6 +48,8 @@ Generated by code_quality (v0.1.3) @ 2018-01-12 16:32:20 +0800
47
48
 
48
49
  [Code Quality Report Example](doc/code_quality_report_example.md)
49
50
 
51
+ [Code Quality Report Details Example](https://rainchen.github.io/code_quality/)
52
+
50
53
  ### Two major audit tasks
51
54
 
52
55
  There are 2 types of audit tasks: `security_audit` and `quality_audit`, each sub task can be run separately.
@@ -0,0 +1,20 @@
1
+ <html>
2
+ <head>
3
+ <title>Code Quality Report</title>
4
+ </head>
5
+ <body>
6
+
7
+ <h1>Code Quality Report</h1>
8
+
9
+ <ul>
10
+ <% @audit_tasks.each do |task_name, report| %>
11
+ <li>[<%= report[:failure].empty? ? "✓" : "✗" %>] <a href="<%= report[:report_path] %>"><%= task_name %></a> <%= report[:failure] %></li>
12
+ <% end %>
13
+ </ul>
14
+
15
+ <footer>
16
+ Generated by code_quality (v<%= CodeQuality::VERSION %>) @ <%= Time.now %>
17
+ </footer>
18
+
19
+ </body>
20
+ </html>
@@ -0,0 +1,35 @@
1
+ #!/bin/sh
2
+ # This script is used to run on Travis CI to publish generated files to GitHub pages
3
+ if [ ${TRAVIS} = "true" ]; then
4
+ echo "Starting to update gh-pages"
5
+
6
+ #copy data we're interested in to other place
7
+ mkdir $HOME/tmp
8
+ cp -R tmp/code_quality $HOME/tmp/code_quality
9
+
10
+ #go to home
11
+ cd $HOME
12
+
13
+ #using token clone gh-pages branch
14
+ git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages > /dev/null
15
+
16
+ #go into diractory and copy data we're interested in to that directory
17
+ cd gh-pages
18
+ cp -Rf $HOME/tmp/code_quality/* .
19
+
20
+ #setup git user
21
+ git config user.email "travis@travis-ci.org"
22
+ git config user.name "Travis CI"
23
+
24
+ #add, commit and push files
25
+ travis_build_url="https://travis-ci.org/${TRAVIS_REPO_SLUG}/builds/${TRAVIS_BUILD_ID}"
26
+ git add -f .
27
+ git commit -m "Travis CI build $travis_build_url pushed to gh-pages"
28
+ git push -fq origin gh-pages > /dev/null
29
+
30
+ #display GitHub Project Pages url
31
+ owner_name=`echo $TRAVIS_REPO_SLUG|cut -d / -f 1`
32
+ repo_name=`echo $TRAVIS_REPO_SLUG|cut -d / -f 2`
33
+ gh_pages_url="https://$owner_name.github.io/$repo_name"
34
+ echo "Push to $gh_pages_url"
35
+ fi
@@ -1,3 +1,3 @@
1
1
  module CodeQuality
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,7 +1,8 @@
1
1
  desc "Generate security audit and code quality report"
2
+ # e.g.: rake code_quality lowest_score=90 max_offenses=100 metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=10 roodi_max_offenses=10
2
3
  task :code_quality => :"code_quality:default" do; end
3
4
  namespace :code_quality do
4
- task :default => [:summary, :security_audit, :quality_audit] do; end
5
+ task :default => [:summary, :security_audit, :quality_audit, :generate_index] do; end
5
6
 
6
7
  # desc "show summary"
7
8
  task :summary do
@@ -9,6 +10,23 @@ namespace :code_quality do
9
10
  puts "Generated by code_quality (v#{CodeQuality::VERSION}) @ #{Time.now}", "\n"
10
11
  end
11
12
 
13
+ # desc "generate a report index page"
14
+ task :generate_index => :helpers do
15
+ require "erb"
16
+ prepare_dir "tmp/code_quality"
17
+ gem_app_dir = File.expand_path("../../../app", __FILE__)
18
+ erb_file = "#{gem_app_dir}/views/code_quality/index.html.erb"
19
+ index_path = "tmp/code_quality/index.html"
20
+
21
+ # render view
22
+ erb = ERB.new(File.read(erb_file))
23
+ output = erb.result(binding)
24
+
25
+ File.open(index_path, 'w') {|f| f.write output }
26
+ # puts "Generate report index to #{index_path}"
27
+ show_in_browser File.realpath(index_path)
28
+ end
29
+
12
30
  desc "security audit using bundler-audit, brakeman"
13
31
  task :security_audit => [:"security_audit:default"] do; end
14
32
  namespace :security_audit do
@@ -26,22 +44,24 @@ namespace :code_quality do
26
44
  end
27
45
 
28
46
  desc "bundler audit"
29
- task :bundler_audit => :prepare do
30
- run_audit "bundler audit - checks for vulnerable versions of gems in Gemfile.lock" do
47
+ task :bundler_audit => :prepare do |task|
48
+ run_audit task, "bundler audit - checks for vulnerable versions of gems in Gemfile.lock" do
31
49
  # Update the ruby-advisory-db and check Gemfile.lock
32
50
  report = `bundle audit check --update`
33
- File.open("#{report_dir}/bundler-audit-report.txt", 'w') {|f| f.write report }
51
+ @report_path = "#{report_dir}/bundler-audit-report.txt"
52
+ File.open(@report_path, 'w') {|f| f.write report }
34
53
  puts report
35
54
  audit_faild "Must fix vulnerabilities ASAP" unless report =~ /No vulnerabilities found/
36
55
  end
37
56
  end
38
57
 
39
58
  desc "brakeman"
40
- task :brakeman => :prepare do
59
+ task :brakeman => :prepare do |task|
41
60
  require 'json'
42
- run_audit "Brakeman audit - checks Ruby on Rails applications for security vulnerabilities" do
43
- `brakeman -o #{report_dir}/brakeman-report.txt -o #{report_dir}/brakeman-report.json`
44
- puts `cat #{report_dir}/brakeman-report.txt`
61
+ run_audit task, "Brakeman audit - checks Ruby on Rails applications for security vulnerabilities" do
62
+ @report_path = "#{report_dir}/brakeman-report.txt"
63
+ `brakeman -o #{@report_path} -o #{report_dir}/brakeman-report.json`
64
+ puts `cat #{@report_path}`
45
65
  report = JSON.parse(File.read("#{report_dir}/brakeman-report.json"))
46
66
  audit_faild "There are #{report["errors"].size} errors, must fix them ASAP." if report["errors"].any?
47
67
  end
@@ -81,12 +101,12 @@ namespace :code_quality do
81
101
 
82
102
  desc "rubycritic"
83
103
  # e.g.: rake code_quality:quality_audit:rubycritic lowest_score=94.5
84
- task :rubycritic => :prepare do
104
+ task :rubycritic => :prepare do |task|
85
105
  options = options_from_env(:lowest_score)
86
- run_audit "Rubycritic - static analysis gems such as Reek, Flay and Flog to provide a quality report of your Ruby code." do
106
+ run_audit task, "Rubycritic - static analysis gems such as Reek, Flay and Flog to provide a quality report of your Ruby code." do
87
107
  report = `rubycritic -p #{report_dir}/rubycritic app lib --no-browser`
88
108
  puts report
89
- report_path = "#{report_dir}/rubycritic/overview.html"
109
+ @report_path = report_path = "#{report_dir}/rubycritic/overview.html"
90
110
  show_in_browser File.realpath(report_path)
91
111
 
92
112
  # if config lowest_score then audit it with report score
@@ -106,8 +126,8 @@ namespace :code_quality do
106
126
  # config_formula: use which formula for config, supports "github, "rails" or path_to_your_local_config.yml, default is "github"
107
127
  # cli_options: pass extract options, e.g.: cli_options="--show-cops"
108
128
  # max_offenses: if config max_offenses then audit it with detected offenses number in report, e.g.: max_offenses=100
109
- task :rubocop => :prepare do
110
- run_audit "rubocop - RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide." do
129
+ task :rubocop => :prepare do |task|
130
+ run_audit task, "rubocop - RuboCop is a Ruby static code analyzer. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide." do
111
131
  options = options_from_env(:config_formula, :cli_options, :max_offenses)
112
132
 
113
133
  config_formulas = {
@@ -125,7 +145,7 @@ namespace :code_quality do
125
145
  config_file = "#{gem_config_dir}/rubocop-#{config_formula}.yml"
126
146
  puts "Using config formula: [#{config_formula}](#{config_formulas[config_formula]})"
127
147
  end
128
- report_path = "#{report_dir}/rubocop-report.html"
148
+ @report_path = report_path = "#{report_dir}/rubocop-report.html"
129
149
 
130
150
  # generate report
131
151
  report = `rubocop -c #{config_file} -S -R -P #{options[:cli_options]} --format offenses --format html -o #{report_path}`
@@ -153,7 +173,7 @@ namespace :code_quality do
153
173
  # rails_best_practices_max_offenses: offenses number for audit
154
174
  # reek_max_offenses: offenses number for audit
155
175
  # roodi_max_offenses: offenses number for audit
156
- task :metric_fu => :prepare do
176
+ task :metric_fu => :prepare do |task|
157
177
  metrics_offenses_patterns = {
158
178
  "flay" => /Total Score (\d+)/,
159
179
  "cane" => /Total Violations (\d+)/,
@@ -163,7 +183,7 @@ namespace :code_quality do
163
183
  }
164
184
  metrics_have_offenses = metrics_offenses_patterns.keys.map { |metric| "#{metric}_max_offenses".to_sym }
165
185
  options = options_from_env(:metrics, *metrics_have_offenses)
166
- run_audit "metric_fu - Code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Code Statistics, and Rails Best Practices. (and optionally RCov)" do
186
+ run_audit task, "metric_fu - Code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Code Statistics, and Rails Best Practices. (and optionally RCov)" do
167
187
  report_path = "#{report_dir}/metric_fu"
168
188
  available_metrics = %w{cane churn flay flog hotspots rails_best_practices rcov reek roodi saikuro stats}
169
189
  metric_fu_opts = ""
@@ -183,6 +203,7 @@ namespace :code_quality do
183
203
  puts report
184
204
  puts "Report generated to #{report_path}"
185
205
  show_in_browser File.realpath(report_path)
206
+ @report_path = "#{report_path}/index.html"
186
207
 
187
208
  # audit report result
188
209
  report_result_path = "tmp/metric_fu/report.yml"
@@ -225,10 +246,25 @@ namespace :code_quality do
225
246
 
226
247
  # desc "helper methods"
227
248
  task :helpers do
228
- def run_audit(title, &block)
249
+ def run_audit(task, title, &block)
250
+ task_name = task.name.split(":").last
251
+ @audit_tasks ||= {}
252
+ @audit_tasks[task_name] ||= {
253
+ report_path: "",
254
+ failure: "",
255
+ }
256
+
229
257
  puts "## #{title}"
230
258
  puts "", "```"
231
- realtime(&block)
259
+ begin
260
+ realtime(&block)
261
+ rescue SystemExit => exc
262
+ # audit faild
263
+ @audit_tasks[task_name][:failure] = exc.message.gsub(/(\e\[\d+m)/, "")
264
+ ensure
265
+ # get @report_path set in each audit task
266
+ @audit_tasks[task_name][:report_path] = @report_path.sub("tmp/code_quality/", "")
267
+ end
232
268
  puts "```", ""
233
269
  end
234
270
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_quality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RainChen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-17 00:00:00.000000000 Z
11
+ date: 2018-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -151,8 +151,10 @@ files:
151
151
  - README.md
152
152
  - Rakefile
153
153
  - app/readme
154
+ - app/views/code_quality/index.html.erb
154
155
  - bin/console
155
156
  - bin/setup
157
+ - bin/travis-update-gh-pages.sh
156
158
  - code_quality.gemspec
157
159
  - config/rubocop-github.yml
158
160
  - config/rubocop-rails.yml