codestats-metrics-reporter 0.1.6 → 0.1.7

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: 91932706edeecb81f3190777e6838d368e03e30f
4
- data.tar.gz: 8ddedd06a3ec485074cf35409cd3a8eec9ce9da3
3
+ metadata.gz: 25358de0e33079ab4d41de8b2c78308a5ca2af04
4
+ data.tar.gz: 869c4c46322692e47cbb3dbd6560b8b343333b3f
5
5
  SHA512:
6
- metadata.gz: ef5ef37e56e1a6e16b189af9385290975cdadd51d8b30ac19392ee3d23a94f12d127d4c06db2b941510c168659a5cc48cea28ef7baf1a63f4b4ee15a67a25c84
7
- data.tar.gz: 66f099fab8be67b620c1c1d2138a3b05c0e496c2b0801ac8a8ef3920a831880ae2174e239c4145c1645cbb9e7a589623dc9946683b09c81f9101cac9e86bafaa
6
+ metadata.gz: 2deca6141e10c4aca94f445546d94a7e991f94019335d69ec5ff78e44d0021ac4d810a5d607ef7a21129e665fbbe2292efc7f384822a224393b9221e9a01bbb4
7
+ data.tar.gz: 1923e107dbde40766ac4cdd1b0e4104bbd323069e50ffbc4cb73d74809444fa64af25646c53fa403ab722dfd0ac81644c049baf7970bbae7de52d73ecd3a9b7a
@@ -27,6 +27,17 @@ metrics:
27
27
  uploader_secret: <%= ENV['CODE_STATS_S3_SECRET_KEY'] %>
28
28
  uploader_region: <%= ENV['CODE_STATS_S3_REGION'] %>
29
29
  uploader_bucket: <%= ENV['CODE_STATS_S3_BUCKET'] %>
30
+ tailor:
31
+ name: 'Code Quality'
32
+ enabled: false
33
+ minimum: 70
34
+ upload_report: true
35
+ location: 'tailor-report.json'
36
+ report_dir: 'tailor'
37
+ uploader_key: <%= ENV['CODE_STATS_S3_KEY'] %>
38
+ uploader_secret: <%= ENV['CODE_STATS_S3_SECRET_KEY'] %>
39
+ uploader_region: <%= ENV['CODE_STATS_S3_REGION'] %>
40
+ uploader_bucket: <%= ENV['CODE_STATS_S3_BUCKET'] %>
30
41
  escomplex:
31
42
  name: 'Js Maintainability'
32
43
  location: 'code-quality-report/stats.json'
@@ -6,6 +6,7 @@ require 'code_stats/metrics/reporter/cli'
6
6
  require 'code_stats/metrics/reporter/rubycritic'
7
7
  require 'code_stats/metrics/reporter/simplecov'
8
8
  require 'code_stats/metrics/reporter/slather'
9
+ require 'code_stats/metrics/reporter/tailor'
9
10
  require 'code_stats/metrics/reporter/karma_coverage'
10
11
  require 'code_stats/metrics/reporter/escomplex'
11
12
  require 'code_stats/metrics/reporter/version'
@@ -0,0 +1,117 @@
1
+ require 'json'
2
+
3
+ module CodeStats
4
+ module Metrics
5
+ module Reporter
6
+ class Tailor
7
+ class << self
8
+ EXTENSIONS = %w(swift).freeze
9
+
10
+ def generate_data(metric, config_store)
11
+ @config_store = config_store
12
+ @metric = metric
13
+ {
14
+ metric_name: metric.data['name'],
15
+ value: parse_quality,
16
+ minimum: metric.data['minimum'],
17
+ url: url
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def parse_quality
24
+ violations = parse_violations(parse_json)
25
+ violations_map = initialize_violations_map(parse_json)
26
+ filled_violations_map = fill_violations_map(violations, violations_map)
27
+ average_scores = average_scores(score_files(filled_violations_map))
28
+ upload_report
29
+ average_scores
30
+ end
31
+
32
+ def parse_json
33
+ JSON.parse(File.read(@metric.data['location']))
34
+ end
35
+
36
+ def parse_violations(json_file)
37
+ violations = json_file['files'].map do |file|
38
+ file['violations'].map do |violation|
39
+ {
40
+ location: file['path'],
41
+ rule: violation['rule']
42
+ }
43
+ end
44
+ end
45
+ violations.flatten
46
+ end
47
+
48
+ def initialize_violations_map(json_file)
49
+ files = json_file['files'].map do |file|
50
+ {
51
+ file: file['path'],
52
+ violations: []
53
+ }
54
+ end
55
+ end
56
+
57
+ # Add violations to each file
58
+ def fill_violations_map(violations, violations_map)
59
+ violations.each do |each|
60
+ violation = violations_map.find { |i| each[:location] == i[:file] }
61
+ violation[:violations].push(each[:rule]) if violation
62
+ end
63
+ violations_map
64
+ end
65
+
66
+ # Give a score to each file
67
+ def score_files(violations_map)
68
+ violations_map.each do |each|
69
+ each[:score] = each[:violations].inject(100) { |a, e| a - 5 }
70
+ each[:score] = 0 if each[:score] < 0
71
+ each.delete(:violations)
72
+ end
73
+ violations_map
74
+ end
75
+
76
+ # Return the average of scores
77
+ def average_scores(violations_map)
78
+ violations_map.inject(0) { |a, e| a + e[:score] } / violations_map.size
79
+ end
80
+
81
+ # Uploading methods
82
+
83
+ def upload_report
84
+ build_uploader.upload(File.realpath(@metric.data['report_dir']).to_s, bucket) if upload_report?
85
+ end
86
+
87
+ def build_uploader
88
+ S3Uploader::Uploader.new(s3_key: @metric.data['uploader_key'],
89
+ s3_secret: @metric.data['uploader_secret'],
90
+ destination_dir: "tailor/#{project}/#{id}",
91
+ region: @metric.data['uploader_region'])
92
+ end
93
+
94
+ def upload_report?
95
+ @metric.data['upload_report']
96
+ end
97
+
98
+ def url
99
+ "https://s3.amazonaws.com/#{bucket}/tailor/#{project}/#{id}/index.html"
100
+ end
101
+
102
+ def project
103
+ Ci.data(@config_store.ci)[:repository_name]
104
+ end
105
+
106
+ def id
107
+ Ci.data(@config_store.ci)[:branch] || Ci.data(@config_store.ci)[:pull_request]
108
+ end
109
+
110
+ def bucket
111
+ @metric.data['uploader_bucket']
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -1,7 +1,7 @@
1
1
  module CodeStats
2
2
  module Metrics
3
3
  module Reporter
4
- VERSION = '0.1.6'.freeze
4
+ VERSION = '0.1.7'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codestats-metrics-reporter
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
  - Esteban Pintos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,6 +159,7 @@ files:
159
159
  - lib/code_stats/metrics/reporter/rubycritic.rb
160
160
  - lib/code_stats/metrics/reporter/simplecov.rb
161
161
  - lib/code_stats/metrics/reporter/slather.rb
162
+ - lib/code_stats/metrics/reporter/tailor.rb
162
163
  - lib/code_stats/metrics/reporter/version.rb
163
164
  homepage: https://github.com/Wolox/codestats-metrics-reporter
164
165
  licenses:
@@ -180,9 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  requirements: []
182
183
  rubyforge_project:
183
- rubygems_version: 2.2.2
184
+ rubygems_version: 2.6.7
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Report metrics to CodeStats
187
188
  test_files: []
188
- has_rdoc: