owners 0.0.3 → 0.0.4
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
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/example/OWNERS.csv +0 -0
- data/example/app/controllers/posts_controller.rb +1 -0
- data/example/app/models/post.rb +1 -0
- data/lib/owners.rb +22 -0
- data/lib/owners/cli.rb +9 -0
- data/lib/owners/config.rb +9 -5
- data/lib/owners/search.rb +7 -2
- data/lib/owners/version.rb +1 -1
- data/spec/owners_cli_spec.rb +34 -10
- data/spec/owners_spec.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5b8497545c8bae9b0559c54ab774eca59b76902
|
4
|
+
data.tar.gz: 713afb83cfb32bd97564fe357b00af5fd75f18fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e680ddde0602250c8265365b241d3da884f6f6f55c0e249f1a2da57a63c94b099c0818e675a2b7b58ccdcb9d4e29d4b45430b92059736e7cfad645901586763d
|
7
|
+
data.tar.gz: 83aa63b203e8abec894387322c26265ab28c06f6586e2b1c721f1cd258999a7cf9c2724cc0fee2341b30533c3db6f364108d070add048b682886e2cc69156932
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -48,11 +48,10 @@ Find the owners for specific files by passing them to the `Owners.for` method.
|
|
48
48
|
Owners.for(".env", "app/controllers/posts_controller.rb", "app/models/user.rb")
|
49
49
|
```
|
50
50
|
|
51
|
-
|
51
|
+
To find the owners for files changed with `git diff` use the `Owners.for_diff` method.
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
|
55
|
-
Owners.for(*files)
|
54
|
+
Owners.for_diff("your-feature-branch-or-ref", "optional-base-ref-defaults-to-master")
|
56
55
|
```
|
57
56
|
|
58
57
|
This method returns a unique array of all the owners who have subscribed to changes for the specified files. These subscribers can then be notified however you see fit!
|
@@ -66,6 +65,10 @@ This gem also comes with a convenient `owners` command line interface. Each owne
|
|
66
65
|
owners for .env app/controllers/posts_controller.rb app/models/user.rb
|
67
66
|
```
|
68
67
|
|
68
|
+
```bash
|
69
|
+
owners for_diff my-feature-branch
|
70
|
+
```
|
71
|
+
|
69
72
|
See `owners help` for more information.
|
70
73
|
|
71
74
|
|
@@ -76,6 +79,7 @@ See `owners help` for more information.
|
|
76
79
|
* `Owners.file`
|
77
80
|
* `Owners.file=`
|
78
81
|
* `Owners.for`
|
82
|
+
* `Owners.for_diff`
|
79
83
|
|
80
84
|
|
81
85
|
## Testing
|
data/example/OWNERS.csv
ADDED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# touched
|
data/example/app/models/post.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# touched
|
data/lib/owners.rb
CHANGED
@@ -27,5 +27,27 @@ module Owners
|
|
27
27
|
def for(*files)
|
28
28
|
Search.new(files).owners
|
29
29
|
end
|
30
|
+
|
31
|
+
# Accepts a git ref and an optional base ref and returns
|
32
|
+
# an array of owners that have subscribed to the changes.
|
33
|
+
#
|
34
|
+
# The base ref defaults to "master".
|
35
|
+
#
|
36
|
+
# @api public
|
37
|
+
def for_diff(ref, base = "master")
|
38
|
+
files = `git diff --name-only #{base}...#{ref}`.split("\n")
|
39
|
+
|
40
|
+
# TODO: why doesn't this work? It works in the command line...
|
41
|
+
# blobs = `git ls-tree -r #{ref} | **/#{file}`.split("\n")
|
42
|
+
blobs = `git ls-tree -r #{ref} | egrep "(^|/)#{file}$"`.split("\n")
|
43
|
+
|
44
|
+
configs = blobs.reduce({}) do |hash, line|
|
45
|
+
_, _, sha, file = line.split(/\s+/, 4)
|
46
|
+
contents = `git show #{sha}`
|
47
|
+
hash.update(file => contents)
|
48
|
+
end
|
49
|
+
|
50
|
+
Search.new(files, configs).owners
|
51
|
+
end
|
30
52
|
end
|
31
53
|
end
|
data/lib/owners/cli.rb
CHANGED
@@ -8,5 +8,14 @@ module Owners
|
|
8
8
|
puts owner
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
desc "for_diff REF [BASE_REF]", "List owners for a set of git changes"
|
13
|
+
method_option :file, desc: "The name of the OWNERS file"
|
14
|
+
def for_diff(ref, base_ref = "master")
|
15
|
+
Owners.file = options[:file] if options[:file]
|
16
|
+
Owners.for_diff(ref, base_ref).each do |owner|
|
17
|
+
puts owner
|
18
|
+
end
|
19
|
+
end
|
11
20
|
end
|
12
21
|
end
|
data/lib/owners/config.rb
CHANGED
@@ -4,14 +4,14 @@ module Owners
|
|
4
4
|
#
|
5
5
|
# @api private
|
6
6
|
class Config
|
7
|
-
def initialize(file)
|
8
|
-
@contents = file.read
|
9
|
-
@root =
|
7
|
+
def initialize(file, contents = nil)
|
8
|
+
@contents = contents || file.read
|
9
|
+
@root = File.dirname(file.to_s)
|
10
10
|
end
|
11
11
|
|
12
12
|
def owners(path)
|
13
|
-
if path
|
14
|
-
relative = path.sub(
|
13
|
+
if path =~ prefix
|
14
|
+
relative = path.sub(prefix, "")
|
15
15
|
|
16
16
|
search do |subscription, results|
|
17
17
|
owner, pattern = subscription.split(/\s+/, 2)
|
@@ -23,6 +23,10 @@ module Owners
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
def prefix
|
27
|
+
/\.?\/?#{@root}\//
|
28
|
+
end
|
29
|
+
|
26
30
|
def search(&block)
|
27
31
|
subscriptions.each_with_object([], &block)
|
28
32
|
end
|
data/lib/owners/search.rb
CHANGED
@@ -4,8 +4,9 @@ module Owners
|
|
4
4
|
#
|
5
5
|
# @api private
|
6
6
|
class Search
|
7
|
-
def initialize(files)
|
7
|
+
def initialize(files, configs = nil)
|
8
8
|
@files = files
|
9
|
+
@configs = configs
|
9
10
|
end
|
10
11
|
|
11
12
|
def owners
|
@@ -26,7 +27,11 @@ module Owners
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def configs
|
29
|
-
|
30
|
+
if @configs
|
31
|
+
@configs.map { |file, contents| Config.new(file, contents) }
|
32
|
+
else
|
33
|
+
subscriptions.map { |file| Config.new(file) }
|
34
|
+
end
|
30
35
|
end
|
31
36
|
|
32
37
|
def subscriptions
|
data/lib/owners/version.rb
CHANGED
data/spec/owners_cli_spec.rb
CHANGED
@@ -1,21 +1,45 @@
|
|
1
1
|
RSpec.describe Owners::CLI do
|
2
|
+
subject { capture { command } }
|
3
|
+
|
4
|
+
let(:command) { described_class.start(args) }
|
5
|
+
|
6
|
+
def capture
|
7
|
+
stdout = $stdout
|
8
|
+
$stdout = StringIO.new
|
9
|
+
yield
|
10
|
+
$stdout.string
|
11
|
+
ensure
|
12
|
+
$stdout = stdout
|
13
|
+
end
|
14
|
+
|
2
15
|
describe "for" do
|
3
|
-
subject { capture { command } }
|
4
|
-
let(:command) { described_class.start(args) }
|
5
16
|
let(:args) { ["for", "example/app/controllers/users_controller.rb"] }
|
6
17
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
$stdout.string
|
12
|
-
ensure
|
13
|
-
$stdout = stdout
|
18
|
+
context "without a specified file" do
|
19
|
+
it "parses owners correctly" do
|
20
|
+
expect(subject).to eq("@org/auth\n@org/blog\n")
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
24
|
+
context "with a specified file" do
|
25
|
+
before { args << "--file" << "SOMETHING_ELSE" }
|
26
|
+
|
27
|
+
it "overrides the default OWNERS filename" do
|
28
|
+
begin
|
29
|
+
expect(subject).to eq("")
|
30
|
+
ensure
|
31
|
+
Owners.file = nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "for_diff" do
|
38
|
+
let(:args) { ["for_diff", "0757297", "d0e67df"] }
|
39
|
+
|
16
40
|
context "without a specified file" do
|
17
41
|
it "parses owners correctly" do
|
18
|
-
expect(subject).to eq("@org/
|
42
|
+
expect(subject).to eq("@org/blog\n@whitespace\ndata@example.com\n")
|
19
43
|
end
|
20
44
|
end
|
21
45
|
|
data/spec/owners_spec.rb
CHANGED
@@ -61,4 +61,26 @@ RSpec.describe Owners do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
describe ".for_diff" do
|
66
|
+
subject { described_class.for_diff(ref, base_ref) }
|
67
|
+
|
68
|
+
context "when comparing one commit" do
|
69
|
+
let(:ref) { "0757297" }
|
70
|
+
let(:base_ref) { "6683118" }
|
71
|
+
|
72
|
+
it "parses owners correctly" do
|
73
|
+
expect(subject).to eq(["@org/blog"])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when comparing multiple commits" do
|
78
|
+
let(:ref) { "0757297" }
|
79
|
+
let(:base_ref) { "d0e67df" }
|
80
|
+
|
81
|
+
it "parses owners correctly" do
|
82
|
+
expect(subject).to eq(["@org/blog", "@whitespace", "data@example.com"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
64
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: owners
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- README.md
|
55
55
|
- bin/owners
|
56
56
|
- example/OWNERS
|
57
|
+
- example/OWNERS.csv
|
57
58
|
- example/app/OWNERS
|
58
59
|
- example/app/controllers/posts_controller.rb
|
59
60
|
- example/app/controllers/users_controller.rb
|