class Codeowners::Checker::OwnersList
Manage OWNERS file reading, re-writing and fetching
Attributes
filename[RW]
owners[W]
validate_owners[RW]
Public Class Methods
new(repo, _config = nil)
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 13 def initialize(repo, _config = nil) @validate_owners = true # doing gsub here ensures the files are always in the same directory @filename = CodeOwners.filename(repo).gsub('CODEOWNERS', 'OWNERS') @config ||= Codeowners::Config.new end
persist!(repo, owners, config = nil)
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 20 def self.persist!(repo, owners, config = nil) owner_list = new(repo, config) owner_list.owners = owners owner_list.persist! end
Public Instance Methods
<<(owner)
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 64 def <<(owner) return if @owners.include?(owner) @owners << owner end
github_credentials_exist?()
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 47 def github_credentials_exist? token = ENV['GITHUB_TOKEN'] organization = @config.default_organization token && !organization.empty? end
invalid_owners(codeowners)
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 53 def invalid_owners(codeowners) return [] unless @validate_owners codeowners.each_with_object([]) do |line, acc| next unless line.pattern? missing = line.owners - owners acc.push([line, missing]) if missing.any? end end
owners()
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 36 def owners return [] unless @validate_owners @owners ||= if github_credentials_exist? Codeowners::GithubFetcher.get_owners(@config.default_organization, ENV['GITHUB_TOKEN']) else FileAsArray.new(@filename).content end end
persist!()
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 26 def persist! owners_file = FileAsArray.new(@filename) owners_file.content = @owners owners_file.persist! end
valid_owner?(owner)
click to toggle source
# File lib/codeowners/checker/owners_list.rb, line 32 def valid_owner?(owner) !@validate_owners || owners.include?(owner) end