class Codeowners::Cli::Filter

List changed files. Provide an option to list all the changed files grouped by the owner of the file or filter them and show only the files owned by default owner.

Attributes

checker[R]

Public Class Methods

new(args = [], options = {}, config = {}) click to toggle source
Calls superclass method Codeowners::Cli::Base::new
# File lib/codeowners/cli/filter.rb, line 39
def initialize(args = [], options = {}, config = {})
  super
  @repo_base_path = `git rev-parse --show-toplevel`
  if !@repo_base_path || @repo_base_path.empty?
    raise 'You must be positioned in a git repository to use this tool'
  end

  @repo_base_path.chomp!
  Dir.chdir(@repo_base_path)

  @checker ||= config[:checker] || default_checker
end

Public Instance Methods

all() click to toggle source
# File lib/codeowners/cli/filter.rb, line 32
def all
  changes = checker.changes_with_ownership.select { |_owner, val| val && !val.empty? }
  changes.keys.each do |owner|
    puts(owner + ":\n  " + changes[owner].join("\n  ") + "\n\n")
  end
end
by(owner = config.default_owner) click to toggle source

option :branch, default: '', aliases: '-b'

# File lib/codeowners/cli/filter.rb, line 17
def by(owner = config.default_owner)
  return if owner.empty?

  changes = checker.changes_with_ownership(owner)
  if changes.key?(owner)
    changes.values.each { |file| puts file }
  else
    puts "Owner #{owner} not defined in .github/CODEOWNERS"
  end
end

Private Instance Methods

default_checker() click to toggle source
# File lib/codeowners/cli/filter.rb, line 58
def default_checker
  Codeowners::Checker.new(@repo_base_path, options[:from], options[:to])
end