Class: Codeowners::Cli::Filter

Inherits:
Base
  • Object
show all
Defined in:
lib/codeowners/cli/filter.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Filter

Returns a new instance of Filter.



39
40
41
42
43
44
45
46
47
48
49
50
# 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

Instance Method Details

#allObject



32
33
34
35
36
37
# 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) ⇒ Object

option :local, default: false, type: :boolean, aliases: ‘-l’ option :branch, default: ”, aliases: ‘-b’



17
18
19
20
21
22
23
24
25
26
# 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