code_owners 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc307747a22792a128d695f174820316e1854c24
4
+ data.tar.gz: 3a8d98cb08c68ae917211a158b29851338c1485a
5
+ SHA512:
6
+ metadata.gz: 5d041bcf4991ae7a2a93a79fb9d0504707544d78c7b8e5881cb6e48e58628db9bf5f02d12037d755730360a6954b0abd9ce706503509bdac4efb25df65381572
7
+ data.tar.gz: d6e685e7f8815541e0c6278e7dde16572b74218c02cc81ad8dfa97c1c0e940e05db2ac2b9d7e16985acae63103ca908b9c12fc04f4d3a559dca1b578a3a4cbc5
@@ -0,0 +1,13 @@
1
+ # This is a CODEOWNERS file. See https://help.github.com/articles/about-codeowners/
2
+ # this is also intentionally poorly written for testing purposes
3
+
4
+
5
+ # empty line followed by a comment?! madness
6
+ lib/* @jcheatham
7
+ spec/* @jcheatham
8
+ Rakefile @jcheatham
9
+
10
+ *code_owners* @jcheatham
11
+
12
+ Gemfile* @jcheatham
13
+ .git* @jcheatham
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ code_owners (1.0.0)
5
+ rake (~> 12.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ byebug (9.0.6)
11
+ diff-lcs (1.3)
12
+ rake (12.3.1)
13
+ rspec (3.7.0)
14
+ rspec-core (~> 3.7.0)
15
+ rspec-expectations (~> 3.7.0)
16
+ rspec-mocks (~> 3.7.0)
17
+ rspec-core (3.7.1)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-expectations (3.7.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-mocks (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-support (3.7.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ byebug (~> 9.0)
32
+ code_owners!
33
+ rspec (~> 3.7)
34
+
35
+ BUNDLED WITH
36
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Jonathan Cheatham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ [:build, :install, :release].each do |task_name|
4
+ Rake::Task[task_name].prerequisites << :spec
5
+ end
6
+
7
+ require "rspec/core/rake_task"
8
+ RSpec::Core::RakeTask.new
9
+
10
+ desc "Run tests"
11
+ task :default => :spec
data/bin/code_owners ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'code_owners'
5
+
6
+ CodeOwners.ownerships.each do |ownership_status|
7
+ owner_info = ownership_status[:owner].dup
8
+ owner_info += " per line #{ownership_status[:line]}, #{ownership_status[:pattern]}" if owner_info != "UNOWNED"
9
+ puts "#{ownership_status[:file].ljust(100,' ')} #{owner_info}"
10
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ name = "code_owners"
3
+ require "#{name}/version"
4
+
5
+ Gem::Specification.new name, CodeOwners::VERSION do |s|
6
+ s.date = "2018-03-29"
7
+ s.summary = ".github/CODEOWNERS introspection utility gem"
8
+ s.description = "utility gem for .github/CODEOWNERS introspection"
9
+ s.authors = "Jonathan Cheatham"
10
+ s.email = "coaxis@gmail.com"
11
+ s.homepage = "http://github.com/jcheatham/#{s.name}"
12
+ s.licenses = "MIT"
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.bindir = 'bin'
16
+ s.test_files = `git ls-files -- test/*`.split("\n")
17
+ s.require_paths = ["lib"]
18
+ s.executables = ["code_owners"]
19
+
20
+ s.add_development_dependency "rspec"
21
+ s.add_runtime_dependency "rake"
22
+ end
@@ -0,0 +1,47 @@
1
+ require "code_owners/version"
2
+ require "tempfile"
3
+
4
+ module CodeOwners
5
+ class << self
6
+ # github's CODEOWNERS rules (https://help.github.com/articles/about-codeowners/) are allegedly based on the gitignore format.
7
+ # but you can't tell ls-files to ignore tracked files via an arbitrary pattern file
8
+ # so we need to jump through some hacky git-fu hoops
9
+ #
10
+ # -c "core.excludesfiles=somefile" -> tells git to use this as our gitignore pattern source
11
+ # check-ignore -> debug gitignore / exclude files
12
+ # --no-index -> don't look in the index when checking, can be used to debug why a path became tracked
13
+ # -v -> verbose, outputs details about the matching pattern (if any) for each given pathname
14
+ # -n -> non-matching, shows given paths which don't match any pattern
15
+
16
+ def ownerships
17
+ patterns, owners = pattern_owners.transpose
18
+
19
+ raw_git_ownership(patterns).map do |status|
20
+ _, _exfile, line, pattern, file = status.match(/^(.*):(\d*):(.*)\t(.*)$/).to_a
21
+ if line.empty?
22
+ { file: file, owner: "UNOWNED" }
23
+ else
24
+ { file: file, owner: owners[line.to_i - 1], line: line, pattern: pattern }
25
+ end
26
+ end
27
+ end
28
+
29
+ # read the github file and spit out a slightly formatted list of patterns and their owners
30
+ def pattern_owners
31
+ File.read(".github/CODEOWNERS").split("\n").map do |line|
32
+ line.gsub(/#.*/, '').gsub(/^$/, " @").split(/\s+@/, 2)
33
+ end
34
+ end
35
+
36
+ # expects an array of gitignore compliant patterns
37
+ # generates a check-ignore formatted string for each file in the repo
38
+ def raw_git_ownership(patterns)
39
+ Tempfile.open('codeowner_patterns') do |file|
40
+ file.write(patterns.join("\n"))
41
+ file.rewind
42
+ cmd = "git ls-files | xargs -- git -c \"core.excludesfile=#{file.path}\" check-ignore --no-index -v -n"
43
+ `#{cmd}`.lines.map(&:strip)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module CodeOwners
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'code_owners'
2
+
3
+ RSpec.describe CodeOwners do
4
+ describe ".ownerships" do
5
+ it "assigns owners to things" do
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(
8
+ [
9
+ "this_gets_discarded:2:whatever/pattern/thing\tthis/is/a/file",
10
+ "::\tunowned/file"
11
+ ]
12
+ )
13
+ expect(CodeOwners.ownerships).to eq(
14
+ [
15
+ { file: "this/is/a/file", owner: "own2", line: "2", pattern: "whatever/pattern/thing" },
16
+ { file: "unowned/file", owner: "UNOWNED"}
17
+ ]
18
+ )
19
+ end
20
+ end
21
+
22
+ describe ".pattern_owners" do
23
+ it "returns a list of patterns and owners" do
24
+ patterns, owners = CodeOwners.pattern_owners.transpose
25
+ expect(owners).to include("jcheatham")
26
+ expect(patterns).to include("lib/*")
27
+ end
28
+ end
29
+
30
+ describe ".raw_git_ownership" do
31
+ it "establishes code owners from a list of patterns" do
32
+ raw_ownership = CodeOwners.raw_git_ownership(["/lib/*"])
33
+ expect(raw_ownership.size).to be >= 1
34
+ expect(raw_ownership).to all( match(/^.*:\d*:.*\t.*$/) )
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: code_owners
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Cheatham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: utility gem for .github/CODEOWNERS introspection
42
+ email: coaxis@gmail.com
43
+ executables:
44
+ - code_owners
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/CODEOWNERS"
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - Rakefile
54
+ - bin/code_owners
55
+ - code_owners.gemspec
56
+ - lib/code_owners.rb
57
+ - lib/code_owners/version.rb
58
+ - spec/code_owners_spec.rb
59
+ homepage: http://github.com/jcheatham/code_owners
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.5.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: ".github/CODEOWNERS introspection utility gem"
83
+ test_files: []