covered-git 0.1.3 → 0.2.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/covered/git.rb +6 -35
- data/lib/covered/git/branch_changes.rb +40 -0
- data/lib/covered/git/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdb5f80dbd4b64b56932daf646d8af2216079127a37c025adb4f7526d98b39d1
|
4
|
+
data.tar.gz: 4da126aa69204de96704e2b4a1512a0d483aed8b76ac84f66743277ee754db4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe9d988f16a5bc4ae4a977abcefac2c1febae5c7472bc19d39d32b2e49d2864426535d4a1912be425c382479debb435b60255230c593706ed6c49d8a45504936
|
7
|
+
data.tar.gz: 94f56bf7eee01eccb5890f1946e5339aeba04fa10a14c677a3e34507d2e2afa91ec5bbbbc43a2ae5004400919307cebe36e95822f05902b3300ae9bd114a9415
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/bake/covered/git.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'covered/policy'
|
4
|
+
require 'covered/git/branch_changes'
|
4
5
|
|
5
6
|
def initialize(...)
|
6
7
|
super
|
7
8
|
|
8
9
|
require 'set'
|
9
10
|
require 'rugged'
|
10
|
-
@repository = nil
|
11
11
|
end
|
12
12
|
|
13
13
|
# bake load_coverage_from_simplecov git:coverage
|
14
|
+
# @parameter root [String] the root directory of the git repository.
|
14
15
|
# @parameter branch [String] the branch to compare against.
|
15
16
|
# @parameter input [Covered::Policy] the input policy to use.
|
16
|
-
def statistics(
|
17
|
+
def statistics(root: context.root, branch: nil, input:)
|
17
18
|
input ||= context.lookup("covered:policy:current").call
|
18
|
-
|
19
|
+
changes = Covered::Git::BranchChanges.new(root)
|
20
|
+
modifications = changes.lines_modified(branch)
|
19
21
|
|
20
22
|
# Calculate statistics:
|
21
23
|
statistics = Covered::Statistics.new
|
@@ -28,35 +30,4 @@ def statistics(branch: self.default_branch, input:)
|
|
28
30
|
end
|
29
31
|
|
30
32
|
return statistics
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def repository(root = context.root)
|
36
|
-
@repository ||= Rugged::Repository.discover(root)
|
37
|
-
end
|
38
|
-
|
39
|
-
def default_branch
|
40
|
-
"main"
|
41
|
-
end
|
42
|
-
|
43
|
-
# Compute the lines modified for a given branch, returning a hash of paths to a set of line numbers.
|
44
|
-
# @returns [Hash(String, Set(Integer))]
|
45
|
-
def lines_modified(branch)
|
46
|
-
result = Hash.new{|k,v| k[v] = Set.new}
|
47
|
-
|
48
|
-
diff = repository.diff(repository.rev_parse(branch), repository.last_commit)
|
49
|
-
|
50
|
-
diff.each_patch do |patch|
|
51
|
-
path = patch.delta.new_file[:path]
|
52
|
-
|
53
|
-
patch.each_hunk do |hunk|
|
54
|
-
hunk.each_line do |line|
|
55
|
-
result[path] << line.new_lineno if line.addition?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
result.default = nil
|
61
|
-
return result.freeze
|
62
|
-
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module Covered
|
3
|
+
module Git
|
4
|
+
class BranchChanges
|
5
|
+
def initialize(root)
|
6
|
+
@root = root
|
7
|
+
end
|
8
|
+
|
9
|
+
def repository
|
10
|
+
@repository ||= Rugged::Repository.discover(@root)
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_branch
|
14
|
+
"main"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Compute the lines modified for a given branch, returning a hash of paths to a set of line numbers.
|
18
|
+
# @returns [Hash(String, Set(Integer))]
|
19
|
+
def lines_modified(branch = nil)
|
20
|
+
branch ||= default_branch
|
21
|
+
result = Hash.new{|k,v| k[v] = Set.new}
|
22
|
+
|
23
|
+
diff = repository.diff(repository.rev_parse(branch), repository.last_commit)
|
24
|
+
|
25
|
+
diff.each_patch do |patch|
|
26
|
+
path = patch.delta.new_file[:path]
|
27
|
+
|
28
|
+
patch.each_hunk do |hunk|
|
29
|
+
hunk.each_line do |line|
|
30
|
+
result[path] << line.new_lineno if line.addition?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
result.default = nil
|
36
|
+
return result.freeze
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/covered/git/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: covered-git
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date: 2023-07-
|
40
|
+
date: 2023-07-25 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: bake
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- bake/covered/git.rb
|
91
91
|
- lib/covered/git.rb
|
92
|
+
- lib/covered/git/branch_changes.rb
|
92
93
|
- lib/covered/git/version.rb
|
93
94
|
- license.md
|
94
95
|
- readme.md
|
metadata.gz.sig
CHANGED
Binary file
|