lib/code_ownership.rb in code_ownership-1.36.2 vs lib/code_ownership.rb in code_ownership-1.36.3
- old
+ new
@@ -16,11 +16,12 @@
if defined?(Packwerk)
require 'code_ownership/private/permit_pack_owner_top_level_key'
end
module CodeOwnership
- extend self
+ module_function
+
extend T::Sig
extend T::Helpers
requires_ancestor { Kernel }
GlobsToOwningTeamMap = T.type_alias { T::Hash[String, CodeTeams::Team] }
@@ -37,11 +38,11 @@
owner = T.let(nil, T.nilable(CodeTeams::Team))
Mapper.all.each do |mapper|
owner = mapper.map_file_to_owner(file)
- break if owner
+ break if owner # TODO: what if there are multiple owners? Should we respond with an error instead of the first match?
end
@for_file[file] = owner
end
@@ -55,20 +56,21 @@
Private.glob_cache.raw_cache_contents.each do |mapper_description, glob_to_owning_team_map|
ownership_information << "## #{mapper_description}"
ownership_for_mapper = []
glob_to_owning_team_map.each do |glob, owning_team|
next if owning_team != team
+
ownership_for_mapper << "- #{glob}"
end
if ownership_for_mapper.empty?
ownership_information << 'This team owns nothing in this category.'
else
ownership_information += ownership_for_mapper.sort
end
- ownership_information << ""
+ ownership_information << ''
end
ownership_information.join("\n")
end
@@ -82,25 +84,25 @@
sig do
params(
autocorrect: T::Boolean,
stage_changes: T::Boolean,
- files: T.nilable(T::Array[String]),
+ files: T.nilable(T::Array[String])
).void
end
def validate!(
autocorrect: true,
stage_changes: true,
files: nil
)
Private.load_configuration!
tracked_file_subset = if files
- files.select{|f| Private.file_tracked?(f)}
- else
- Private.tracked_files
- end
+ files.select { |f| Private.file_tracked?(f) }
+ else
+ Private.tracked_files
+ end
Private.validate!(files: tracked_file_subset, autocorrect: autocorrect, stage_changes: stage_changes)
end
# Given a backtrace from either `Exception#backtrace` or `caller`, find the
@@ -148,29 +150,29 @@
file = T.must(match[:file])
[
CodeOwnership.for_file(file),
- file,
+ file
]
end
end
private_class_method(:backtrace_with_ownership)
sig { params(klass: T.nilable(T.any(T::Class[T.anything], Module))).returns(T.nilable(::CodeTeams::Team)) }
def for_class(klass)
@memoized_values ||= T.let(@memoized_values, T.nilable(T::Hash[String, T.nilable(::CodeTeams::Team)]))
@memoized_values ||= {}
# We use key because the memoized value could be `nil`
- if !@memoized_values.key?(klass.to_s)
+ if @memoized_values.key?(klass.to_s)
+ @memoized_values[klass.to_s]
+ else
path = Private.path_from_klass(klass)
return nil if path.nil?
value_to_memoize = for_file(path)
@memoized_values[klass.to_s] = value_to_memoize
value_to_memoize
- else
- @memoized_values[klass.to_s]
end
end
sig { params(package: Packs::Pack).returns(T.nilable(::CodeTeams::Team)) }
def for_package(package)