lib/codeowners/checker.rb in codeowners-checker-1.0.0 vs lib/codeowners/checker.rb in codeowners-checker-1.0.1

- old
+ new

@@ -32,15 +32,12 @@ def added_files changes_to_analyze.select { |_k, v| v == 'A' }.keys end - def check! - { - missing_ref: missing_reference, - useless_pattern: useless_pattern - } + def fix! + catch(:user_quit) { results } end def changes_for_patterns(patterns) @git.diff(@from, @to).path(patterns).name_status.keys end @@ -80,11 +77,11 @@ def missing_reference added_files.reject(&method(:defined_owner?)) end def pattern_has_files(pattern) - @git.ls_files(pattern).any? + @git.ls_files(pattern.gsub(%r{^/}, '')).any? end def defined_owner?(file) codeowners.find do |line| next unless line.pattern? @@ -105,19 +102,31 @@ def main_group codeowners.main_group end + def consistent? + results.values.all?(&:empty?) + end + def commit_changes! @git.add(codeowners_filename) @git.commit('Fix pattern :robot:') end - private - def codeowners_filename directories = ['', '.github', 'docs', '.gitlab'] paths = directories.map { |dir| File.join(@repo_dir, dir, 'CODEOWNERS') } Dir.glob(paths).first || paths.first + end + + private + + def results + @results ||= + { + missing_ref: missing_reference, + useless_pattern: useless_pattern + } end end end