covered-git 0.1.0 → 0.1.1

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: 138407c0e3f1aae0b6c5d02f630368a57bdd81f6ca8979f5a158a16488db1c6b
4
- data.tar.gz: 0c350304b8d56ad72d7f6312a61f4ef32c525d1104924eabc80c472329447ba9
3
+ metadata.gz: f73e8946aa0f8f6d40855ee6152e968b77c8ec7b599781f00a146c7e5900b41d
4
+ data.tar.gz: 919d022b9deaecccdbd67bde0ad039d58dd7c428477a805b63da54de0d758be3
5
5
  SHA512:
6
- metadata.gz: 95d7298b30d21d9cb7b1841d55045eb2bbd5db8f77bfc7600d557ac0919627f830f4ac1fa07b922288006c26c4e0deace16f71cc4c47094a3134340f2f82c7fb
7
- data.tar.gz: 6bdce61631d7ff6e28db78d8ed60496124581c3258c030fabb22d555f91d1fe1d11636c4b697200fc0354bf697795e415c344c5a119f2e1ad85ded1608cfca01
6
+ metadata.gz: 41d1c98e1deece86ce89f57694a0fd6d4907905bbeb9bcdbd685117918af4542809bb764f45ccec03f55bf68f5c365610a6bc99acdca1295da393e6d7fe6579b
7
+ data.tar.gz: d80973731b2f3a0ae03a5e379360f37e8e3802720a3a0250b3da662f0eb1fd12247cc39d091c325dbd31f37a55162b7369bb603ff8721e98aa6b277217c5ffe0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'covered/policy'
4
+
5
+ def initialize(...)
6
+ super
7
+
8
+ require 'set'
9
+ require 'rugged'
10
+ @repository = nil
11
+ end
12
+
13
+ # bake load_coverage_from_simplecov git:coverage
14
+ # @parameter branch [String] the branch to compare against.
15
+ # @parameter input [Covered::Policy] the input policy to use.
16
+ def statistics(branch: self.default_branch, input:)
17
+ input ||= context.lookup("covered:policy:current").call
18
+ modifications = lines_modified(branch)
19
+
20
+ # Calculate statistics:
21
+ statistics = Covered::Statistics.new
22
+
23
+ input.each do |coverage|
24
+ if modified_lines = modifications[coverage.source.path]
25
+ scoped_coverage = coverage.for_lines(modified_lines)
26
+ statistics << scoped_coverage
27
+ end
28
+ end
29
+
30
+ 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_workdir(branch)
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
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Covered
7
7
  module Git
8
- VERSION = "0.1.0"
8
+ VERSION = "0.1.1"
9
9
  end
10
10
  end
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - bake/covered/git.rb
76
77
  - lib/covered/git.rb
77
78
  - lib/covered/git/version.rb
78
79
  - license.md
metadata.gz.sig CHANGED
Binary file