codeowners 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -0
- data/lib/codeowners/cli.rb +31 -5
- data/lib/codeowners/git.rb +10 -2
- data/lib/codeowners/git/contributor.rb +4 -0
- data/lib/codeowners/git/contributors.rb +21 -11
- data/lib/codeowners/list_contributors.rb +6 -2
- data/lib/codeowners/result.rb +2 -0
- data/lib/codeowners/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66eab678e31ae2c7c45bf32e8b8a92163bb3cef3147475a95775ece36081dce2
|
4
|
+
data.tar.gz: e188c85670d6cc4d1a0bb1d2f2fb6aee9085f1ad3b3ef978027d55ec4afc311d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c4e4381b4cdd046065ec83a785d742b058768d9b27cb78b765ecfe230e76e4a1cc608a3f395496196be051601ae7e9f22a3050f64e97e70a0f3761db481a204
|
7
|
+
data.tar.gz: 4037d4d9ba417ffe5ae65c3e50051f245c111f80e3880366b1bde609d936f15cef994a38a1438c64842447dbb2bb2f5685a6fd0c46268a065187699357541b9a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,17 @@ Person One
|
|
34
34
|
Person Two <person.two@company.com> / +12, -2
|
35
35
|
```
|
36
36
|
|
37
|
+
The command accepts also a pattern to match files in bulk.
|
38
|
+
|
39
|
+
```shell
|
40
|
+
$ codeowners contributors 'path/to/**/*.rb'
|
41
|
+
path/to/**/*.rb
|
42
|
+
|
43
|
+
Person One <person.one@company.com> / +243, -438
|
44
|
+
Person Three <person.three@company.com> / +104, -56
|
45
|
+
Person Two <person.two@company.com> / +12, -2
|
46
|
+
```
|
47
|
+
|
37
48
|
### Help
|
38
49
|
|
39
50
|
For a complete set of options, please run:
|
data/lib/codeowners/cli.rb
CHANGED
@@ -55,17 +55,43 @@ module Codeowners
|
|
55
55
|
DEFAULT_CODEOWNERS_PATH = ::File.join(".github", "CODEOWNERS").freeze
|
56
56
|
private_constant :DEFAULT_CODEOWNERS_PATH
|
57
57
|
|
58
|
-
|
58
|
+
FORMAT_MAPPING = { "string" => "to_s", "csv" => "to_csv" }.freeze
|
59
|
+
private_constant :FORMAT_MAPPING
|
59
60
|
|
60
|
-
|
61
|
+
FORMAT_VALUES = FORMAT_MAPPING.keys.freeze
|
62
|
+
private_constant :FORMAT_VALUES
|
63
|
+
|
64
|
+
DEFAULT_FORMAT = FORMAT_VALUES.first
|
65
|
+
private_constant :DEFAULT_FORMAT
|
66
|
+
|
67
|
+
DEFAULT_DEBUG = false
|
68
|
+
private_constant :DEFAULT_DEBUG
|
69
|
+
|
70
|
+
desc "List code contributors for a file (or a pattern)"
|
71
|
+
|
72
|
+
argument :file, required: true, desc: "File (or pattern) to check"
|
61
73
|
|
62
74
|
option :base_directory, type: :string, default: DEFAULT_BASE_DIRECTORY, desc: "Base directory"
|
75
|
+
option :format, type: :string, default: DEFAULT_FORMAT, values: FORMAT_VALUES, desc: "Output format"
|
76
|
+
option :debug, type: :boolean, default: DEFAULT_DEBUG, desc: "Print debug information to stdout"
|
77
|
+
|
78
|
+
example [
|
79
|
+
"path/to/file.rb # file",
|
80
|
+
"'path/to/**/*.rb' # pattern"
|
81
|
+
]
|
63
82
|
|
64
|
-
def call(file:, base_directory:, **)
|
65
|
-
result = Codeowners::ListContributors.new(base_directory).call(file)
|
83
|
+
def call(file:, base_directory:, format:, debug:, **)
|
84
|
+
result = Codeowners::ListContributors.new(base_directory).call(file, debug)
|
66
85
|
exit(1) unless result.successful?
|
67
86
|
|
68
|
-
out.puts result
|
87
|
+
out.puts output(result, format)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def output(result, format)
|
93
|
+
method_name = FORMAT_MAPPING.fetch(format)
|
94
|
+
result.public_send(method_name.to_sym)
|
69
95
|
end
|
70
96
|
end
|
71
97
|
|
data/lib/codeowners/git.rb
CHANGED
@@ -9,9 +9,10 @@ module Codeowners
|
|
9
9
|
@base_directory = Pathname.new(::File.expand_path(base_directory))
|
10
10
|
end
|
11
11
|
|
12
|
-
def contributors(file)
|
12
|
+
def contributors(file, debug = false)
|
13
13
|
require "codeowners/git/contributors"
|
14
|
-
output = git(["log", "--
|
14
|
+
output = git(["log", "--numstat", %(--pretty=format:"author:%aN email:%ae"), "--no-color", "--", escape(file)])
|
15
|
+
print_debug(output, debug)
|
15
16
|
|
16
17
|
Contributors.call(file, output)
|
17
18
|
end
|
@@ -42,5 +43,12 @@ module Codeowners
|
|
42
43
|
return stdout.read
|
43
44
|
end
|
44
45
|
end
|
46
|
+
|
47
|
+
def print_debug(output, debug)
|
48
|
+
return unless debug
|
49
|
+
|
50
|
+
puts output
|
51
|
+
puts "\n" * 10
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
@@ -36,27 +36,37 @@ module Codeowners
|
|
36
36
|
while lines.any?
|
37
37
|
commit = lines.take_while { |line| line != "" }
|
38
38
|
yield parse(commit.dup) unless commit.empty?
|
39
|
-
lines
|
40
|
-
lines.shift
|
39
|
+
lines.shift(commit.size + 1)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
43
|
def self.parse(commit)
|
45
|
-
stats = commit.
|
46
|
-
stats = stats.split(", ")
|
44
|
+
authors, stats = commit.partition { |line| line.match?(/author:/) }
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
deletions = deletions.to_i
|
46
|
+
[extract_authors(authors), *calculate_stats(stats)]
|
47
|
+
end
|
51
48
|
|
52
|
-
|
49
|
+
def self.extract_authors(authors)
|
50
|
+
authors.map do |author|
|
53
51
|
{
|
54
|
-
"name" =>
|
55
|
-
"email" =>
|
52
|
+
"name" => scan(author, /author:(.*)email:/).chop,
|
53
|
+
"email" => scan(author, /email:(.*)/)
|
56
54
|
}
|
55
|
+
end.uniq
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.calculate_stats(stats)
|
59
|
+
stats.each_with_object([0, 0]) do |stat, result|
|
60
|
+
stat = stat.split(/[[:space:]]+/)
|
61
|
+
|
62
|
+
insertions, deletions, = *stat
|
63
|
+
result[0] += Integer(insertions)
|
64
|
+
result[1] += Integer(deletions)
|
57
65
|
end
|
66
|
+
end
|
58
67
|
|
59
|
-
|
68
|
+
def self.scan(string, pattern)
|
69
|
+
string.scan(pattern).flatten.first
|
60
70
|
end
|
61
71
|
|
62
72
|
def initialize(data)
|
@@ -17,14 +17,18 @@ module Codeowners
|
|
17
17
|
def to_s
|
18
18
|
[@file, "", *@contributors.map(&:to_s)].join("\n")
|
19
19
|
end
|
20
|
+
|
21
|
+
def to_csv
|
22
|
+
@contributors.map(&:to_csv).join("\n")
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def initialize(base_directory, git: Git.new(base_directory))
|
23
27
|
@git = git
|
24
28
|
end
|
25
29
|
|
26
|
-
def call(file)
|
27
|
-
contributors = @git.contributors(file)
|
30
|
+
def call(file, debug = false)
|
31
|
+
contributors = @git.contributors(file, debug)
|
28
32
|
return Result.new if contributors.empty?
|
29
33
|
|
30
34
|
contributors = contributors.each.lazy.sort_by { |c| -c.insertions }
|
data/lib/codeowners/result.rb
CHANGED
data/lib/codeowners/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeowners
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|