lib/codeowner_validator/lists/whitelist.rb
# the pathspec is a combination of files and variables:
# * CODEOWNERS_WHITELIST - if provided a repo_path, file that exists in either the root repo path
#   or alongside the CODEOWNERS file
# * CODEOWNERS_WHITELIST - env variable of comma separated
# * .gitignore - if provided a repo_path, this file is automatically added
the pathspec is a combination of files and variables:
CODEOWNERS_WHITELIST - if provided a repo_path, file that exists in either the root repo path
or alongside the CODEOWNERS file
CODEOWNERS_WHITELIST - env variable of comma separated
.gitignore - if provided a repo_path, this file is automatically added
the pathspec is a combination of files and variables : CODEOWNERS_WHITELIST - if provided a repo_path file that exists in either the root repo path or alongside the CODEOWNERS file CODEOWNERS_WHITELIST - env variable of comma separated . gitignore - if provided a repo_path this file is automatically added
def pathspec
        return @pathspec if defined?(@pathspec) && @pathspec
        @pathspec = PathSpec.new([])
        @pathspec.add ::File.readlines(whitelist_file).map(&:chomp) if whitelist_file
        @pathspec.add ::File.readlines(@filename).map(&:chomp) if @filename && File.exist?(@filename)
        if ENV['CODEOWNERS_WHITELIST']
          new_items =
            [].tap do |ar|
              ENV['CODEOWNERS_WHITELIST']&.split(',')&.each(&:strip!)&.each do |str|
                ar << str
              end
            end
          @pathspec.add new_items
        end
        if git_ignore_file
          @pathspec.add ['**'] if @pathspec.empty?
          @pathspec.add ::File.readlines(git_ignore_file).map do |line|
            "!#{line.chomp}"
          end
        end
        @pathspec
      end
def pathspec return @pathspec if defined? ( @pathspec ) && @pathspec @pathspec = PathSpec . new ( [ ] ) @pathspec . add :: File . readlines ( whitelist_file ) . map ( & :chomp ) if whitelist_file @pathspec . add :: File . readlines ( @filename ) . map ( & :chomp ) if @filename && File . exist? ( @filename ) if ENV [ 'CODEOWNERS_WHITELIST' ] new_items = [ ] . tap do | ar | ENV [ 'CODEOWNERS_WHITELIST' ] &. split ( ',' ) &. each ( & :strip! ) &. each do | str | ar << str end end @pathspec . add new_items end if git_ignore_file @pathspec . add [ '**' ] if @pathspec . empty? @pathspec . add :: File . readlines ( git_ignore_file ) . map do | line | "!#{line.chomp}" end end @pathspec end
the pathspec is a combination of files and variables:
 CODEOWNERS_WHITELIST - if provided a repo_path, file that exists in either the root repo path
or alongside the CODEOWNERS file
 CODEOWNERS_WHITELIST - env variable of comma separated
 .gitignore - if provided a repo_path, this file is automatically added
the pathspec is a combination of files and variables : CODEOWNERS_WHITELIST - if provided a repo_path file that exists in either the root repo path or alongside the CODEOWNERS file CODEOWNERS_WHITELIST - env variable of comma separated . gitignore - if provided a repo_path this file is automatically added
# to avoid instance variable @pathspec not initialized must check if defined prior # first, add repo driven codeowners whitelist file # second, add provided file # third, add items from the CODEOWNERS_WHITELIST # last, add items from the .gitignore.  this must always be last because # of the check for empty specs at this point in which will require inclusion of # all files prior to adding items to exclude. # if a gitignore exists, add each reference # first, check if existing pathspec evaluation is empty, if yes, need to add all files '**' # because the pathspec evaluation will only make evaluations based on the inclusive=false so need # to first include all files to provide an entry to inclusive=true