simplecov-db 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ae93ea85098d3cfb21b6e75ecc92bb8d52aa4b23cae12e8f81fa1692ba38c5fd
4
+ data.tar.gz: fcbd26b3ce5605f4fd50a9f225f2979756f04f5ff1779181f2838bb24468663d
5
+ SHA512:
6
+ metadata.gz: bb7f7111045bad7ccf20a8ba2a0f59a8cbddcb39eb45bab2475423d8327fe1d32129f866a9a05bd6d2e28fef21d71369b5f60cba1646c3ad441ce1a0284ddb98
7
+ data.tar.gz: 792790fc2cc3e5053f7249e945957b605415b9e3b6bae8cd6e4c547a533b50addd5955029eb4e91e6f4f76cf64dc40713bd8633e409c15fa48c7876eb8a09f5f
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ module DB
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'pathname'
5
+ require 'active_record'
6
+ require 'sqlite3'
7
+ require 'simplecov'
8
+ require_relative 'simplecov/db/version'
9
+
10
+ module SimpleCov
11
+ module Formatter
12
+ class DBFormatter
13
+ class ApplicationRecord < ActiveRecord::Base
14
+ self.abstract_class = true
15
+ establish_connection(
16
+ adapter: 'sqlite3',
17
+ database: "#{SimpleCov.coverage_path}/coverage.sqlite3"
18
+ )
19
+ end
20
+
21
+ class Run < ApplicationRecord
22
+ has_many :groups
23
+ has_many :results
24
+ end
25
+
26
+ class Group < ApplicationRecord
27
+ belongs_to :run
28
+ has_many :results
29
+ end
30
+
31
+ class Result < ApplicationRecord
32
+ belongs_to :run
33
+ belongs_to :group
34
+
35
+ before_save :set_run_id
36
+
37
+ def set_run_id
38
+ self.run_id = group.run_id
39
+ end
40
+ end
41
+
42
+ def format(result)
43
+ create_coverage_table
44
+ create_groups(create_run(result), result.groups)
45
+ end
46
+
47
+ private
48
+
49
+ def create_coverage_table
50
+ return true if ApplicationRecord.connection.table_exists?(:results)
51
+
52
+ Run.connection.create_table :runs do |t|
53
+ t.string :command_name, null: false
54
+ t.integer :seed, null: false
55
+ t.string :branch_name, null: false
56
+ t.datetime :created_at, null: false
57
+ t.float :covered_percent, null: false
58
+ t.float :covered_strength, null: false
59
+ t.integer :covered_lines, null: false
60
+ t.integer :missed_lines, null: false
61
+ t.integer :total_branches
62
+ t.integer :covered_branches
63
+ t.integer :missed_branches
64
+ t.integer :total_lines, null: false
65
+ end
66
+
67
+ Group.connection.create_table :groups do |t|
68
+ t.string :name, null: false
69
+ t.integer :run_id, null: false
70
+ t.integer :lines_covered
71
+ t.integer :never_lines
72
+ t.integer :skipped_lines
73
+ t.integer :lines_total
74
+ t.integer :branches_covered
75
+ t.integer :branches_total
76
+ t.integer :covered_branches
77
+ t.integer :missed_branches
78
+ t.float :covered_percent
79
+ t.float :branch_covered_percent
80
+ end
81
+
82
+ # SimpleCov::SourceFile
83
+ Result.connection.create_table :results do |t|
84
+ t.integer :run_id, null: false
85
+ t.string :group_id, null: false
86
+ t.string :filename, null: false
87
+ t.integer :covered_lines, null: false
88
+ t.integer :missed_lines, null: false
89
+ t.integer :never_lines, null: false
90
+ t.integer :lines_of_code, null: false
91
+ t.float :covered_percent, null: false
92
+ t.float :covered_strength, null: false
93
+ end
94
+ true
95
+ end
96
+
97
+ def create_run(result)
98
+ data = {
99
+ created_at: result.created_at,
100
+ command_name: result.command_name,
101
+ seed: Minitest.seed,
102
+ covered_percent: result.covered_percent,
103
+ covered_strength: result.covered_strength,
104
+ covered_lines: result.covered_lines,
105
+ missed_lines: result.missed_lines,
106
+ total_branches: result.total_branches,
107
+ covered_branches: result.covered_branches,
108
+ missed_branches: result.missed_branches,
109
+ total_lines: result.total_lines,
110
+ branch_name: `git rev-parse --abbrev-ref HEAD`
111
+ }
112
+
113
+ Run.create!(data)
114
+ end
115
+
116
+ def create_groups(run, groups)
117
+ groups.each do |group|
118
+ generate_lcov_report_for_group(run, group)
119
+ end
120
+ end
121
+
122
+ def prepare_group_data(group_name, file_list)
123
+ {
124
+ name: group_name,
125
+ lines_covered: file_list.covered_lines,
126
+ never_lines: file_list.never_lines,
127
+ skipped_lines: file_list.skipped_lines,
128
+ lines_total: file_list.lines_of_code,
129
+ branches_covered: file_list.covered_branches,
130
+ branches_total: file_list.total_branches,
131
+ covered_branches: file_list.covered_branches,
132
+ missed_branches: file_list.missed_branches,
133
+ covered_percent: file_list.covered_percent,
134
+ branch_covered_percent: file_list.branch_covered_percent
135
+ }
136
+ end
137
+
138
+ def generate_lcov_report_for_group(run, group)
139
+ group_name = group.first
140
+ file_list = group.last
141
+ group_record = run.groups.create!(prepare_group_data(group_name, file_list))
142
+ generate_lcov_report(group_record, file_list)
143
+ end
144
+
145
+ def generate_lcov_report(group_record, files)
146
+ files.each do |file|
147
+ group_record.results.create!(
148
+ format_file(file)
149
+ )
150
+ end
151
+ end
152
+
153
+ def format_file(file)
154
+ {
155
+ filename: file.project_filename,
156
+ covered_lines: file.covered_lines.count,
157
+ missed_lines: file.missed_lines.count,
158
+ never_lines: file.never_lines.count,
159
+ lines_of_code: file.lines_of_code,
160
+ covered_percent: file.covered_percent,
161
+ covered_strength: file.covered_strength
162
+ }
163
+ end
164
+ end
165
+ end
166
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplecov-db
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: SimpleCov DB is formatter for SimpleCov to save coverage data to a database.
56
+ email:
57
+ - terminale@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/simplecov-db.rb
63
+ - lib/simplecov/db/version.rb
64
+ homepage: https://github.com/seuros/simplecov-db
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ homepage_uri: https://github.com/seuros/simplecov-db
69
+ source_code_uri: https://github.com/seuros/simplecov-db
70
+ changelog_uri: https://github.com/seuros/simplecov-db/blob/master/CHANGELOG.md
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.2.33
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: SimpleCov DB is formatter for SimpleCov to save coverage data to a database.
90
+ test_files: []