code_owners 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ec4a3443c169b75a265f905e95b9ff9595c8dfa
4
- data.tar.gz: e877e2806c91021cffb6973eaed76b99fe51e226
3
+ metadata.gz: bddfbbd4ec9f5016192c995b8660325dae24b9aa
4
+ data.tar.gz: f04bbd2618f16253fba02cd8a40c8ba1483d7a66
5
5
  SHA512:
6
- metadata.gz: db2915fe732ca2f1136f53c4440871bf87d7ebb402a0759296796ff0496d6e9daaa126354bc34b5de6b7c81543a3bffb8e50f369877bb69524dfb017dd3453a3
7
- data.tar.gz: 95d8fed0a564d327db457f1dee58109bab2cd6847edefa51556a4a3b2342ef4562b2c20b43d58bad2018c70c4312bae50d34d3ba970cdfc4f1c090f116f67ace
6
+ metadata.gz: df7b7005d293e25b5ae35d32d450c69a2c2cafd51294dc7292eb0814a67f5126673b7511860d824d9db724145f33e6c15172cc052068d7fd79f76515df666e23
7
+ data.tar.gz: b51c33cb99006e79035e30dec7cfd5546bbd8188e48fd9dea8d47dc97b8cb58724348ce444d6bdffc1723be4d9d352ddbbce70c95e4d1c8f425d0e623617fc91
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code_owners (1.0.2)
4
+ code_owners (1.0.3)
5
5
  rake
6
6
 
7
7
  GEM
@@ -16,8 +16,7 @@ module CodeOwners
16
16
  def ownerships
17
17
  patterns, owners = pattern_owners.transpose
18
18
 
19
- raw_git_ownership(patterns).map do |status|
20
- _, _exfile, line, pattern, file = status.match(/^(.*):(\d*):(.*)\t(.*)$/).to_a
19
+ git_owner_info(patterns).map do |line, pattern, file|
21
20
  if line.empty?
22
21
  { file: file, owner: "UNOWNED" }
23
22
  else
@@ -35,15 +34,31 @@ module CodeOwners
35
34
  end
36
35
  end
37
36
 
37
+ def git_owner_info(patterns)
38
+ make_utf8(raw_git_owner_info(patterns)).lines.map do |info|
39
+ _, _exfile, line, pattern, file = info.strip.match(/^(.*):(\d*):(.*)\t(.*)$/).to_a
40
+ [line, pattern, file]
41
+ end
42
+ end
43
+
38
44
  # expects an array of gitignore compliant patterns
39
45
  # generates a check-ignore formatted string for each file in the repo
40
- def raw_git_ownership(patterns)
46
+ def raw_git_owner_info(patterns)
41
47
  Tempfile.open('codeowner_patterns') do |file|
42
48
  file.write(patterns.join("\n"))
43
49
  file.rewind
44
- cmd = "git ls-files | xargs -- git -c \"core.excludesfile=#{file.path}\" check-ignore --no-index -v -n"
45
- `#{cmd}`.lines.map(&:strip)
50
+ `git ls-files | xargs -- git -c \"core.excludesfile=#{file.path}\" check-ignore --no-index -v -n`
46
51
  end
47
52
  end
53
+
54
+ private
55
+
56
+ def make_utf8(input)
57
+ input.force_encoding(Encoding::UTF_8)
58
+ return input if input.valid_encoding?
59
+ input.encode!(Encoding::UTF_16, invalid: :replace, replace: '�')
60
+ input.encode!(Encoding::UTF_8, Encoding::UTF_16)
61
+ input
62
+ end
48
63
  end
49
64
  end
@@ -1,3 +1,3 @@
1
1
  module CodeOwners
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -4,10 +4,10 @@ RSpec.describe CodeOwners do
4
4
  describe ".ownerships" do
5
5
  it "assigns owners to things" do
6
6
  expect(CodeOwners).to receive(:pattern_owners).and_return([["pat1", "own1"], ["pat2", "own2"], ["pat3", "own3"]])
7
- expect(CodeOwners).to receive(:raw_git_ownership).and_return(
7
+ expect(CodeOwners).to receive(:git_owner_info).and_return(
8
8
  [
9
- "this_gets_discarded:2:whatever/pattern/thing\tthis/is/a/file",
10
- "::\tunowned/file"
9
+ ["2", "whatever/pattern/thing", "this/is/a/file"],
10
+ ["", "", "unowned/file"]
11
11
  ]
12
12
  )
13
13
  expect(CodeOwners.ownerships).to eq(
@@ -35,11 +35,23 @@ RSpec.describe CodeOwners do
35
35
  end
36
36
  end
37
37
 
38
- describe ".raw_git_ownership" do
38
+ describe ".git_owner_info" do
39
+ it "returns a massaged list of git ownership info" do
40
+ expect(CodeOwners).to receive(:raw_git_owner_info).and_return("this_gets_discarded:2:whatever/pattern/thing\tthis/is/a/file\n::\tBad\xEF\xEF\xEF\xEF chars\xC3\xA5\xE2\x88\x86\xC6\x92.txt" )
41
+ expect(CodeOwners.git_owner_info(["/lib/*"])).to eq(
42
+ [
43
+ ["2", "whatever/pattern/thing", "this/is/a/file"],
44
+ ["", "", "Bad���� charså∆ƒ.txt"]
45
+ ]
46
+ )
47
+ end
48
+ end
49
+
50
+ describe ".raw_git_owner_info" do
39
51
  it "establishes code owners from a list of patterns" do
40
- raw_ownership = CodeOwners.raw_git_ownership(["/lib/*"])
52
+ raw_ownership = CodeOwners.raw_git_owner_info(["/lib/*"])
41
53
  expect(raw_ownership.size).to be >= 1
42
- expect(raw_ownership).to all( match(/^.*:\d*:.*\t.*$/) )
54
+ expect(raw_ownership).to match(/^(?:.*:\d*:.*\t.*\n)+$/)
43
55
  end
44
56
  end
45
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_owners
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Cheatham
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.4.5.1
80
+ rubygems_version: 2.5.1
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: ".github/CODEOWNERS introspection utility gem"