codemonitor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/.rubocop.yml +29 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +66 -0
- data/LICENSE +21 -0
- data/README.md +9 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codemonitor.gemspec +44 -0
- data/engines/git/extractor.rb +79 -0
- data/engines/npm/extractor.rb +79 -0
- data/engines/rubocop/extractor.rb +83 -0
- data/engines/semgrep/extractor.rb +64 -0
- data/exe/codemonitor +46 -0
- data/lib/codemonitor/version.rb +5 -0
- data/lib/shell.rb +7 -0
- data/providers/console.rb +23 -0
- data/providers/datadog.rb +31 -0
- data/providers/test.rb +17 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce80c6de6c3579fdb8bc4d52f63905ec45124f6e4a9891ac0ddae5c90608d3f2
|
4
|
+
data.tar.gz: da5354cb8704715dc4d005b2615f034a85b6c43ff0a16ef3a4ddcf45561f139e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b3ceadf4db389641f91d732038e6fc7affbd604815d3b5e50e16743b601a6471c7bab85445f20669c2ecd364e7f33984d931b941130b2b3dd31eaebf8efdfe8
|
7
|
+
data.tar.gz: e17eb93b4b386a587ac9265c63508942055a692ab2c53cd9865c20f31a1c4750c18e42bbb9ca8de70a387ceb4fcc25f7330f6c7d69695ed8364005c04652071c
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Lint/RaiseException:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Lint/StructNewOverride:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/HashEachMethods:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/HashTransformKeys:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/HashTransformValues:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/MultilineBlockChain:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Layout/LineLength:
|
23
|
+
Max: 120
|
24
|
+
|
25
|
+
Layout/MultilineMethodCallIndentation:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Max: 100
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codemonitor (0.1.0)
|
5
|
+
dogapi (~> 1.45)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
dogapi (1.45.0)
|
14
|
+
multi_json
|
15
|
+
method_source (1.0.0)
|
16
|
+
multi_json (1.15.0)
|
17
|
+
parallel (1.20.1)
|
18
|
+
parser (3.0.1.1)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
pry (0.13.1)
|
21
|
+
coderay (~> 1.1)
|
22
|
+
method_source (~> 1.0)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (13.0.3)
|
25
|
+
regexp_parser (2.1.1)
|
26
|
+
rexml (3.2.5)
|
27
|
+
rspec (3.9.0)
|
28
|
+
rspec-core (~> 3.9.0)
|
29
|
+
rspec-expectations (~> 3.9.0)
|
30
|
+
rspec-mocks (~> 3.9.0)
|
31
|
+
rspec-core (3.9.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-expectations (3.9.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-mocks (3.9.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-support (3.9.0)
|
40
|
+
rubocop (0.93.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.7.1.5)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
regexp_parser (>= 1.8)
|
45
|
+
rexml
|
46
|
+
rubocop-ast (>= 0.6.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
49
|
+
rubocop-ast (1.5.0)
|
50
|
+
parser (>= 3.0.1.1)
|
51
|
+
ruby-progressbar (1.11.0)
|
52
|
+
unicode-display_width (1.7.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 2.0)
|
59
|
+
codemonitor!
|
60
|
+
pry (~> 0.13.1)
|
61
|
+
rake (~> 13.0)
|
62
|
+
rspec (~> 3.9)
|
63
|
+
rubocop (~> 0.80)
|
64
|
+
|
65
|
+
BUNDLED WITH
|
66
|
+
2.2.17
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Ferran Basora
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rubocop/changes"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/codemonitor.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'codemonitor/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'codemonitor'
|
7
|
+
spec.version = CodeMonitor::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.required_ruby_version = '>= 2.6.0'
|
10
|
+
spec.authors = ['Ferran Basora']
|
11
|
+
spec.email = ['fcsonline@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Collect many metrics your code is generating'
|
14
|
+
spec.description = <<-DESCRIPTION
|
15
|
+
CodeMonitor collects many metrics your code is generating
|
16
|
+
DESCRIPTION
|
17
|
+
|
18
|
+
spec.homepage = 'https://rubygems.org/gems/codemonitor'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
|
21
|
+
spec.metadata = {
|
22
|
+
'source_code_uri' => 'https://github.com/fcsonline/codemonitor',
|
23
|
+
'bug_tracker_uri' => 'https://github.com/fcsonline/codemonitor/issues'
|
24
|
+
}
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
28
|
+
# into git.
|
29
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
30
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
end
|
32
|
+
spec.bindir = 'exe'
|
33
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
|
+
spec.extra_rdoc_files = ['LICENSE', 'README.md']
|
35
|
+
spec.require_paths = ['lib']
|
36
|
+
|
37
|
+
spec.add_runtime_dependency 'dogapi', '~> 1.45'
|
38
|
+
|
39
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
40
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
42
|
+
spec.add_development_dependency 'pry', '~> 0.13.1'
|
43
|
+
spec.add_development_dependency 'rubocop', '~> 0.80'
|
44
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../lib/shell'
|
4
|
+
|
5
|
+
module Engines
|
6
|
+
module Git
|
7
|
+
class Extractor
|
8
|
+
METRICS = %i[
|
9
|
+
git_number_of_commits
|
10
|
+
git_number_of_branches
|
11
|
+
git_number_of_tags
|
12
|
+
git_number_of_contributors
|
13
|
+
git_number_of_files
|
14
|
+
git_number_of_ignores_files
|
15
|
+
git_number_of_lines
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
def call(provider)
|
19
|
+
return unless requirements?
|
20
|
+
|
21
|
+
metrics = METRICS.map do |metric|
|
22
|
+
[metric, send(metric)]
|
23
|
+
end.to_h
|
24
|
+
|
25
|
+
provider.emit(metrics)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def requirements?
|
31
|
+
File.exist?('.git')
|
32
|
+
end
|
33
|
+
|
34
|
+
def git_number_of_commits
|
35
|
+
Shell.run("git log --format='%h'").lines.count
|
36
|
+
end
|
37
|
+
|
38
|
+
def git_number_of_branches
|
39
|
+
Shell.run('git ls-remote -q')
|
40
|
+
.lines
|
41
|
+
.filter { |line| line =~ %r{\Arefs/heads} }
|
42
|
+
.count
|
43
|
+
end
|
44
|
+
|
45
|
+
def git_number_of_tags
|
46
|
+
Shell.run('git ls-remote -q')
|
47
|
+
.lines
|
48
|
+
.filter { |line| line =~ %r{\Arefs/tags} }
|
49
|
+
.count
|
50
|
+
end
|
51
|
+
|
52
|
+
def git_number_of_contributors
|
53
|
+
Shell.run("git log --format='%aN'")
|
54
|
+
.lines
|
55
|
+
.sort
|
56
|
+
.uniq
|
57
|
+
.count
|
58
|
+
end
|
59
|
+
|
60
|
+
def git_number_of_files
|
61
|
+
Shell.run('git ls-tree -r master --name-only')
|
62
|
+
.lines
|
63
|
+
.count
|
64
|
+
end
|
65
|
+
|
66
|
+
def git_number_of_ignores_files
|
67
|
+
Shell.run('git check-ignore *').lines.count
|
68
|
+
end
|
69
|
+
|
70
|
+
def git_number_of_lines
|
71
|
+
Shell.run('git ls-files')
|
72
|
+
.lines
|
73
|
+
.map do |file|
|
74
|
+
File.read(File.expand_path(file.strip, Dir.pwd)).lines.count
|
75
|
+
end.sum
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require_relative '../../lib/shell'
|
6
|
+
|
7
|
+
module Engines
|
8
|
+
module Npm
|
9
|
+
class Extractor
|
10
|
+
METRICS = %i[
|
11
|
+
npm_number_of_dependencies
|
12
|
+
npm_number_of_dev_dependencies
|
13
|
+
npm_number_of_scripts
|
14
|
+
npm_number_of_vulnerable_dependencies
|
15
|
+
npm_number_of_vulnerable_dependencies_low
|
16
|
+
npm_number_of_vulnerable_dependencies_moderate
|
17
|
+
npm_number_of_vulnerable_dependencies_high
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
def call(provider)
|
21
|
+
return unless requirements?
|
22
|
+
|
23
|
+
metrics = METRICS.map do |metric|
|
24
|
+
[metric, send(metric) || 0]
|
25
|
+
end.to_h
|
26
|
+
|
27
|
+
provider.emit(metrics)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def requirements?
|
33
|
+
File.exist?('package.json')
|
34
|
+
end
|
35
|
+
|
36
|
+
def npm_number_of_dependencies
|
37
|
+
npm_package['dependencies'].keys.length
|
38
|
+
end
|
39
|
+
|
40
|
+
def npm_number_of_dev_dependencies
|
41
|
+
npm_package['devDependencies'].keys.length
|
42
|
+
end
|
43
|
+
|
44
|
+
def npm_number_of_scripts
|
45
|
+
npm_package['scripts'].keys.length
|
46
|
+
end
|
47
|
+
|
48
|
+
def npm_number_of_vulnerable_dependencies
|
49
|
+
npm_audit['advisories'].length
|
50
|
+
end
|
51
|
+
|
52
|
+
def npm_number_of_vulnerable_dependencies_low
|
53
|
+
npm_audit_by_severity['low']
|
54
|
+
end
|
55
|
+
|
56
|
+
def npm_number_of_vulnerable_dependencies_moderate
|
57
|
+
npm_audit_by_severity['moderate']
|
58
|
+
end
|
59
|
+
|
60
|
+
def npm_number_of_vulnerable_dependencies_high
|
61
|
+
npm_audit_by_severity['high']
|
62
|
+
end
|
63
|
+
|
64
|
+
def npm_package
|
65
|
+
@npm_package ||= JSON.parse(File.read('package.json'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def npm_audit
|
69
|
+
@npm_audit ||= JSON.parse(Shell.run('npm audit --json'))
|
70
|
+
end
|
71
|
+
|
72
|
+
def npm_audit_by_severity
|
73
|
+
npm_audit['advisories']
|
74
|
+
.map { |_key, value| value['severity'] }
|
75
|
+
.each_with_object(Hash.new(0)) { |e, total| total[e] += 1; }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Engines
|
6
|
+
module Rubocop
|
7
|
+
class Extractor
|
8
|
+
METRICS = %i[
|
9
|
+
rubocop_number_of_offenses
|
10
|
+
rubocop_number_of_correctable
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@threshold = ENV.fetch('CODEMONITOR_RUBOCOP_THRESHOLD', '50').to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(provider)
|
18
|
+
return unless requirements?
|
19
|
+
|
20
|
+
metrics = METRICS.map do |metric|
|
21
|
+
[metric, send(metric)]
|
22
|
+
end.to_h
|
23
|
+
|
24
|
+
metrics
|
25
|
+
.merge!(rubocop_by_severity)
|
26
|
+
.merge!(rubocop_by_cop_name)
|
27
|
+
|
28
|
+
provider.emit(metrics)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :threshold
|
34
|
+
|
35
|
+
def requirements?
|
36
|
+
File.exist?('.rubocop.yml')
|
37
|
+
end
|
38
|
+
|
39
|
+
# NOTE: This output file must be created by an external command
|
40
|
+
def rubocop
|
41
|
+
@rubocop ||= JSON.parse(File.read('rubocop.output.json'))
|
42
|
+
end
|
43
|
+
|
44
|
+
def rubocop_number_of_offenses
|
45
|
+
rubocop_offenses.length
|
46
|
+
end
|
47
|
+
|
48
|
+
def rubocop_number_of_correctable
|
49
|
+
rubocop_offenses
|
50
|
+
.filter { |offense| offense['correctable'] }
|
51
|
+
.length
|
52
|
+
end
|
53
|
+
|
54
|
+
def rubocop_offenses
|
55
|
+
rubocop['files']
|
56
|
+
.map { |file| file['offenses'] }
|
57
|
+
.flatten
|
58
|
+
end
|
59
|
+
|
60
|
+
def rubocop_by_severity
|
61
|
+
rubocop_offenses
|
62
|
+
.each_with_object(Hash.new(0)) do |offense, total|
|
63
|
+
total[offense['severity']] += 1
|
64
|
+
end.map do |key, value|
|
65
|
+
["rubocop_severity_#{key}", value]
|
66
|
+
end.to_h
|
67
|
+
end
|
68
|
+
|
69
|
+
def rubocop_by_cop_name
|
70
|
+
rubocop_offenses
|
71
|
+
.each_with_object(Hash.new(0)) do |offense, total|
|
72
|
+
total[offense['cop_name']] += 1
|
73
|
+
end.map do |key, value|
|
74
|
+
["rubocop_cop_#{clean(key)}", value] if value >= threshold
|
75
|
+
end.compact.to_h
|
76
|
+
end
|
77
|
+
|
78
|
+
def clean(key)
|
79
|
+
key.gsub(%r{[-,./ ]}, '_').downcase
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Engines
|
6
|
+
module Semgrep
|
7
|
+
class Extractor
|
8
|
+
METRICS = %i[
|
9
|
+
semgrep_number_of_offenses
|
10
|
+
semgrep_number_of_errors
|
11
|
+
].freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@threshold = ENV.fetch('CODEMONITOR_SEMGREP_THRESHOLD', '50').to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(provider)
|
18
|
+
return unless requirements?
|
19
|
+
|
20
|
+
metrics = METRICS.map do |metric|
|
21
|
+
[metric, send(metric)]
|
22
|
+
end.to_h
|
23
|
+
|
24
|
+
metrics.merge!(semgrep_by_check_id)
|
25
|
+
|
26
|
+
provider.emit(metrics)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :threshold
|
32
|
+
|
33
|
+
def requirements?
|
34
|
+
File.exist?('.semgrep.yml')
|
35
|
+
end
|
36
|
+
|
37
|
+
# NOTE: This output file must be created by an external command
|
38
|
+
def semgrep
|
39
|
+
@semgrep ||= JSON.parse(File.read('semgrep.output.json'))
|
40
|
+
end
|
41
|
+
|
42
|
+
def semgrep_number_of_offenses
|
43
|
+
semgrep['results'].length
|
44
|
+
end
|
45
|
+
|
46
|
+
def semgrep_number_of_errors
|
47
|
+
semgrep['errors'].length
|
48
|
+
end
|
49
|
+
|
50
|
+
def semgrep_by_check_id
|
51
|
+
semgrep['results']
|
52
|
+
.each_with_object(Hash.new(0)) do |offense, total|
|
53
|
+
total[offense['check_id']] += 1
|
54
|
+
end.map do |key, value|
|
55
|
+
["semgrep_check_#{clean(key)}", value] if value >= threshold
|
56
|
+
end.compact.to_h
|
57
|
+
end
|
58
|
+
|
59
|
+
def clean(key)
|
60
|
+
key.gsub(/[-,. ]/, '_')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/exe/codemonitor
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../providers/console'
|
5
|
+
require_relative '../providers/datadog'
|
6
|
+
|
7
|
+
require_relative '../engines/git/extractor'
|
8
|
+
require_relative '../engines/npm/extractor'
|
9
|
+
require_relative '../engines/semgrep/extractor'
|
10
|
+
require_relative '../engines/rubocop/extractor'
|
11
|
+
|
12
|
+
PROVIDERS = {
|
13
|
+
console: Providers::Console,
|
14
|
+
datadog: Providers::Datadog
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
EXTRACTORS = {
|
18
|
+
git: Engines::Git::Extractor,
|
19
|
+
npm: Engines::Npm::Extractor,
|
20
|
+
semgrep: Engines::Semgrep::Extractor,
|
21
|
+
rubocop: Engines::Rubocop::Extractor
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
config_provider = ENV['CODEMONITOR_PROVIDER'] || 'console'
|
25
|
+
config_extractors = ENV['CODEMONITOR_EXTRACTORS']
|
26
|
+
|
27
|
+
provider = PROVIDERS[config_provider.to_sym].new
|
28
|
+
extractors = if config_extractors
|
29
|
+
EXTRACTORS.slice(*config_extractors.split(',').map(&:to_sym)).values
|
30
|
+
else
|
31
|
+
EXTRACTORS.values
|
32
|
+
end
|
33
|
+
|
34
|
+
puts '# process start'
|
35
|
+
|
36
|
+
# Run all the extractors and collect the data
|
37
|
+
extractors
|
38
|
+
.map(&:new)
|
39
|
+
.map do |extractor|
|
40
|
+
extractor.call(provider)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Send all the data to the provider
|
44
|
+
provider.send
|
45
|
+
|
46
|
+
puts '# process end'
|
data/lib/shell.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Providers
|
4
|
+
class Console
|
5
|
+
def initialize
|
6
|
+
@pending = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def emit(metrics)
|
10
|
+
@pending = pending.merge(metrics)
|
11
|
+
end
|
12
|
+
|
13
|
+
def send
|
14
|
+
pending.map do |metric, value|
|
15
|
+
puts "#{metric}: #{value}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :pending
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dogapi'
|
4
|
+
|
5
|
+
module Providers
|
6
|
+
class Datadog
|
7
|
+
def initialize
|
8
|
+
@pending = {}
|
9
|
+
@metric_prefix = ENV['DATADOG_PREFIX'] || 'codemonitor.'
|
10
|
+
@datadog_client = Dogapi::Client.new(ENV['DATADOG_API_KEY'])
|
11
|
+
end
|
12
|
+
|
13
|
+
def emit(metrics)
|
14
|
+
@pending = pending.merge(metrics)
|
15
|
+
end
|
16
|
+
|
17
|
+
def send
|
18
|
+
datadog_client.batch_metrics do
|
19
|
+
pending.each do |metric, value|
|
20
|
+
metric = metric_prefix + metric
|
21
|
+
puts "#{metric}: #{value}"
|
22
|
+
datadog_client.emit_point(metric, value, type: 'gauge')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :pending, :datadog_client
|
30
|
+
end
|
31
|
+
end
|
data/providers/test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codemonitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ferran Basora
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dogapi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.45'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.45'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.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.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.13.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.13.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.80'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.80'
|
97
|
+
description: " CodeMonitor collects many metrics your code is generating\n"
|
98
|
+
email:
|
99
|
+
- fcsonline@gmail.com
|
100
|
+
executables:
|
101
|
+
- codemonitor
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- codemonitor.gemspec
|
118
|
+
- engines/git/extractor.rb
|
119
|
+
- engines/npm/extractor.rb
|
120
|
+
- engines/rubocop/extractor.rb
|
121
|
+
- engines/semgrep/extractor.rb
|
122
|
+
- exe/codemonitor
|
123
|
+
- lib/codemonitor/version.rb
|
124
|
+
- lib/shell.rb
|
125
|
+
- providers/console.rb
|
126
|
+
- providers/datadog.rb
|
127
|
+
- providers/test.rb
|
128
|
+
homepage: https://rubygems.org/gems/codemonitor
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata:
|
132
|
+
source_code_uri: https://github.com/fcsonline/codemonitor
|
133
|
+
bug_tracker_uri: https://github.com/fcsonline/codemonitor/issues
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 2.6.0
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubygems_version: 3.0.1
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Collect many metrics your code is generating
|
153
|
+
test_files: []
|