Module: CodeOwners
- Defined in:
- lib/code_owners.rb,
lib/code_owners/version.rb
Constant Summary collapse
- VERSION =
"1.0.4"
Class Method Summary collapse
- .git_owner_info(patterns) ⇒ Object
-
.ownerships ⇒ Object
github’s CODEOWNERS rules (help.github.com/articles/about-codeowners/) are allegedly based on the gitignore format.
-
.pattern_owners ⇒ Object
read the github file and spit out a slightly formatted list of patterns and their owners.
-
.raw_git_owner_info(patterns) ⇒ Object
expects an array of gitignore compliant patterns generates a check-ignore formatted string for each file in the repo.
Class Method Details
.git_owner_info(patterns) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/code_owners.rb', line 36 def git_owner_info(patterns) make_utf8(raw_git_owner_info(patterns)).lines.map do |info| _, _exfile, line, pattern, file = info.strip.match(/^(.*):(\d*):(.*)\t(.*)$/).to_a [line, pattern, file] end end |
.ownerships ⇒ Object
github’s CODEOWNERS rules (help.github.com/articles/about-codeowners/) are allegedly based on the gitignore format. but you can’t tell ls-files to ignore tracked files via an arbitrary pattern file so we need to jump through some hacky git-fu hoops
-c “core.excludesfiles=somefile” -> tells git to use this as our gitignore pattern source check-ignore -> debug gitignore / exclude files –no-index -> don’t look in the index when checking, can be used to debug why a path became tracked -v -> verbose, outputs details about the matching pattern (if any) for each given pathname -n -> non-matching, shows given paths which don’t match any pattern
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/code_owners.rb', line 16 def ownerships patterns, owners = pattern_owners.transpose git_owner_info(patterns).map do |line, pattern, file| if line.empty? { file: file, owner: "UNOWNED" } else { file: file, owner: owners[line.to_i - 1], line: line, pattern: pattern } end end end |
.pattern_owners ⇒ Object
read the github file and spit out a slightly formatted list of patterns and their owners
29 30 31 32 33 34 |
# File 'lib/code_owners.rb', line 29 def pattern_owners codeowner_path = File.join(current_repo_path, ".github/CODEOWNERS") File.read(codeowner_path).split("\n").map do |line| line.gsub(/#.*/, '').gsub(/^$/, " @").split(/\s+@/, 2) end end |
.raw_git_owner_info(patterns) ⇒ Object
expects an array of gitignore compliant patterns generates a check-ignore formatted string for each file in the repo
45 46 47 48 49 50 51 |
# File 'lib/code_owners.rb', line 45 def raw_git_owner_info(patterns) Tempfile.open('codeowner_patterns') do |file| file.write(patterns.join("\n")) file.rewind `cd #{current_repo_path} && git ls-files | xargs -- git -c \"core.excludesfile=#{file.path}\" check-ignore --no-index -v -n` end end |