lib/codeowners/checker.rb in codeowners-checker-1.1.1 vs lib/codeowners/checker.rb in codeowners-checker-1.1.2

- old
+ new

@@ -5,10 +5,11 @@ require_relative 'checker/code_owners' require_relative 'checker/file_as_array' require_relative 'checker/group' require_relative 'checker/owners_list' +require_relative 'checker/whitelist' module Codeowners # Check if code owners are consistent between a git repository and the CODEOWNERS file. # It compares what's being changed in the PR and check if the current files and folders # are also being declared in the CODEOWNERS file. @@ -25,11 +26,11 @@ @to = to @owners_list = OwnersList.new(@repo_dir) end def changes_to_analyze - @git.diff(@from, @to).name_status + @git.diff(@from, @to).name_status.reject(&whitelist) end def added_files changes_to_analyze.select { |_k, v| v == 'A' }.keys end @@ -37,11 +38,11 @@ def fix! Enumerator.new { |yielder| catch(:user_quit) { results.each { |r| yielder << r } } } end def changes_for_patterns(patterns) - @git.diff(@from, @to).path(patterns).name_status.keys + @git.diff(@from, @to).path(patterns).name_status.keys.reject(&whitelist) end def patterns_by_owner @patterns_by_owner ||= codeowners.each_with_object(hash_of_arrays) do |line, patterns_by_owner| @@ -72,11 +73,11 @@ def missing_reference @missing_reference ||= added_files.reject(&method(:defined_owner?)) end def pattern_has_files(pattern) - @git.ls_files(pattern.gsub(%r{^/}, '')).any? + @git.ls_files(pattern.gsub(%r{^/}, '')).reject(&whitelist).any? end def defined_owner?(file) codeowners.find do |line| next unless line.pattern? @@ -85,10 +86,22 @@ end false end + def whitelist? + whitelist.exist? + end + + def whitelist_filename + @whitelist_filename ||= CodeOwners.filename(@repo_dir) + '_WHITELIST' + end + + def whitelist + @whitelist ||= Whitelist.new(whitelist_filename) + end + def codeowners @codeowners ||= CodeOwners.new( FileAsArray.new(CodeOwners.filename(@repo_dir)) ) end @@ -106,10 +119,12 @@ @git.add(File.realpath(@owners_list.filename)) @git.commit('Fix pattern :robot:') end def unrecognized_line - @unrecognized_line ||= codeowners.select { |line| line.is_a?(Codeowners::Checker::Group::UnrecognizedLine) } + @unrecognized_line ||= codeowners.select do |line| + line.is_a?(Codeowners::Checker::Group::UnrecognizedLine) + end.reject(&whitelist) end private def invalid_owners