lib/code_ownership/private.rb in code_ownership-1.31.1 vs lib/code_ownership/private.rb in code_ownership-1.32.0
- old
+ new
@@ -1,33 +1,30 @@
# frozen_string_literal: true
# typed: strict
-require 'code_ownership/private/configuration'
+require 'code_ownership/private/extension_loader'
require 'code_ownership/private/team_plugins/ownership'
require 'code_ownership/private/team_plugins/github'
require 'code_ownership/private/parse_js_packages'
-require 'code_ownership/private/validations/interface'
require 'code_ownership/private/validations/files_have_owners'
require 'code_ownership/private/validations/github_codeowners_up_to_date'
require 'code_ownership/private/validations/files_have_unique_owners'
-require 'code_ownership/private/validations/no_overlapping_globs'
-require 'code_ownership/private/ownership_mappers/interface'
require 'code_ownership/private/ownership_mappers/file_annotations'
require 'code_ownership/private/ownership_mappers/team_globs'
require 'code_ownership/private/ownership_mappers/package_ownership'
require 'code_ownership/private/ownership_mappers/js_package_ownership'
require 'code_ownership/private/ownership_mappers/team_yml_ownership'
module CodeOwnership
module Private
extend T::Sig
- sig { returns(Private::Configuration) }
+ sig { returns(Configuration) }
def self.configuration
- @configuration ||= T.let(@configuration, T.nilable(Private::Configuration))
- @configuration ||= Private::Configuration.fetch
+ @configuration ||= T.let(@configuration, T.nilable(Configuration))
+ @configuration ||= Configuration.fetch
end
sig { void }
def self.bust_caches!
@configuration = nil
@@ -35,18 +32,11 @@
@files_by_mapper = nil
end
sig { params(files: T::Array[String], autocorrect: T::Boolean, stage_changes: T::Boolean).void }
def self.validate!(files:, autocorrect: true, stage_changes: true)
- validators = [
- Validations::FilesHaveOwners.new,
- Validations::FilesHaveUniqueOwners.new,
- Validations::GithubCodeownersUpToDate.new,
- Validations::NoOverlappingGlobs.new,
- ]
-
- errors = validators.flat_map do |validator|
+ errors = Validator.all.flat_map do |validator|
validator.validation_errors(
files: files,
autocorrect: autocorrect,
stage_changes: stage_changes
)
@@ -56,27 +46,10 @@
errors << 'See https://github.com/rubyatscale/code_ownership#README.md for more details'
raise InvalidCodeOwnershipConfigurationError.new(errors.join("\n")) # rubocop:disable Style/RaiseArgs
end
end
- sig { returns(T::Array[Private::OwnershipMappers::Interface]) }
- def self.mappers
- [
- file_annotations_mapper,
- Private::OwnershipMappers::TeamGlobs.new,
- Private::OwnershipMappers::PackageOwnership.new,
- Private::OwnershipMappers::JsPackageOwnership.new,
- Private::OwnershipMappers::TeamYmlOwnership.new,
- ]
- end
-
- sig { returns(Private::OwnershipMappers::FileAnnotations) }
- def self.file_annotations_mapper
- @file_annotations_mapper = T.let(@file_annotations_mapper, T.nilable(Private::OwnershipMappers::FileAnnotations))
- @file_annotations_mapper ||= Private::OwnershipMappers::FileAnnotations.new
- end
-
# Returns a string version of the relative path to a Rails constant,
# or nil if it can't find something
sig { params(klass: T.nilable(T.any(Class, Module))).returns(T.nilable(String)) }
def self.path_from_klass(klass)
if klass
@@ -110,10 +83,10 @@
def self.files_by_mapper(files)
@files_by_mapper ||= T.let(@files_by_mapper, T.nilable(T::Hash[String, T::Array[String]]))
@files_by_mapper ||= begin
files_by_mapper = files.map { |file| [file, []] }.to_h
- Private.mappers.each do |mapper|
+ Mapper.all.each do |mapper|
mapper.map_files_to_owners(files).each do |file, _team|
files_by_mapper[file] ||= []
T.must(files_by_mapper[file]) << mapper.description
end
end