Class: GitlabCodeownersChecks::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/gitab_codeowners_checker/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path:, codeowners_path: nil, paths: [''], ignore_paths: [], file_ext: '') ⇒ Project

Returns a new instance of Project.



5
6
7
8
9
10
11
12
13
14
# File 'lib/gitab_codeowners_checker/project.rb', line 5

def initialize(root_path:, codeowners_path: nil, paths: [''], ignore_paths: [], file_ext: '')
  @root_path = root_path
  @paths = paths
  @ignore_paths = ignore_paths
  @file_ext = file_ext
  codeowners_path ||= 'CODEOWNERS'
  @codeowners = GitlabCodeownersChecker::CodeownersFile.new(
    Pathname.new(codeowners_path).absolute? ? codeowners_path : File.join(@root_path, codeowners_path)
  )
end

Instance Attribute Details

#codeownersObject (readonly)

Returns the value of attribute codeowners.



15
16
17
# File 'lib/gitab_codeowners_checker/project.rb', line 15

def codeowners
  @codeowners
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



15
16
17
# File 'lib/gitab_codeowners_checker/project.rb', line 15

def root_path
  @root_path
end

Instance Method Details

#file_pathsObject



17
18
19
20
21
22
23
24
# File 'lib/gitab_codeowners_checker/project.rb', line 17

def file_paths
  @file_paths ||= @paths.flat_map do |ptc|
    abs_path = File.join(@root_path, ptc, "**/*#{@file_ext}")
    Dir.glob(abs_path).map { |path| path.sub(@root_path, '') }.reject do |path|
      @ignore_paths.any? { |pti| path.start_with?(pti) }
    end
  end.sort
end