Skip to content

Commit

Permalink
Use packs standard (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Evanczuk authored Dec 28, 2022
1 parent b73662e commit ed56424
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 162 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PATH
remote: .
specs:
code_ownership (1.29.1)
code_ownership (1.29.2)
code_teams (~> 1.0)
parse_packwerk
packs
sorbet-runtime

GEM
Expand All @@ -15,7 +15,7 @@ GEM
coderay (1.1.3)
diff-lcs (1.4.4)
method_source (1.0.0)
parse_packwerk (0.14.0)
packs (0.0.2)
sorbet-runtime
parser (3.1.2.0)
ast (~> 2.4.1)
Expand Down
4 changes: 2 additions & 2 deletions code_ownership.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "code_ownership"
spec.version = '1.29.1'
spec.version = '1.29.2'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'A gem to help engineering teams declare ownership of code'
Expand All @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'code_teams', '~> 1.0'
spec.add_dependency 'parse_packwerk'
spec.add_dependency 'packs'
spec.add_dependency 'sorbet-runtime'

spec.add_development_dependency 'rake'
Expand Down
4 changes: 2 additions & 2 deletions lib/code_ownership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require 'code_teams'
require 'sorbet-runtime'
require 'json'
require 'parse_packwerk'
require 'packs'
require 'code_ownership/cli'
require 'code_ownership/private'

Expand Down Expand Up @@ -140,7 +140,7 @@ def for_class(klass)
end
end

sig { params(package: ParsePackwerk::Package).returns(T.nilable(::CodeTeams::Team)) }
sig { params(package: Packs::Pack).returns(T.nilable(::CodeTeams::Team)) }
def for_package(package)
Private::OwnershipMappers::PackageOwnership.new.owner_for_package(package)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class PackageOwnership
extend T::Sig
include Interface

@@package_yml_cache = T.let({}, T::Hash[String, T.nilable(ParsePackwerk::Package)]) # rubocop:disable Style/ClassVars
@@package_yml_cache = T.let({}, T::Hash[String, T.nilable(Packs::Pack)]) # rubocop:disable Style/ClassVars

sig do
override.params(file: String).
returns(T.nilable(::CodeTeams::Team))
end
def map_file_to_owner(file)
package = ParsePackwerk.package_from_path(file)
package = Packs.for_file(file)

return nil if package.nil?

Expand All @@ -29,11 +29,11 @@ def map_file_to_owner(file)
returns(T::Hash[String, T.nilable(::CodeTeams::Team)])
end
def map_files_to_owners(files) # rubocop:disable Lint/UnusedMethodArgument
ParsePackwerk.all.each_with_object({}) do |package, res|
Packs.all.each_with_object({}) do |package, res|
owner = owner_for_package(package)
next if owner.nil?

glob = package.directory.join('**/**').to_s
glob = package.relative_path.join('**/**').to_s
Dir.glob(glob).each do |path|
res[path] = owner
end
Expand All @@ -52,11 +52,11 @@ def map_files_to_owners(files) # rubocop:disable Lint/UnusedMethodArgument
override.returns(T::Hash[String, T.nilable(::CodeTeams::Team)])
end
def codeowners_lines_to_owners
ParsePackwerk.all.each_with_object({}) do |package, res|
Packs.all.each_with_object({}) do |package, res|
owner = owner_for_package(package)
next if owner.nil?

res[package.directory.join('**/**').to_s] = owner
res[package.relative_path.join('**/**').to_s] = owner
end
end

Expand All @@ -65,7 +65,7 @@ def description
'Owner metadata key in package.yml'
end

sig { params(package: ParsePackwerk::Package).returns(T.nilable(CodeTeams::Team)) }
sig { params(package: Packs::Pack).returns(T.nilable(CodeTeams::Team)) }
def owner_for_package(package)
raw_owner_value = package.metadata['owner']
return nil if !raw_owner_value
Expand Down
80 changes: 80 additions & 0 deletions sorbet/rbi/gems/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

146 changes: 0 additions & 146 deletions sorbet/rbi/gems/[email protected]

This file was deleted.

2 changes: 1 addition & 1 deletion spec/lib/code_ownership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def prevent_false_positive!
before { create_non_empty_application }

it 'returns the right team' do
team = CodeOwnership.for_package(ParsePackwerk.find('packs/my_other_package'))
team = CodeOwnership.for_package(Packs.find('packs/my_other_package'))
expect(team.name).to eq 'Bar'
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
config.before do
CodeOwnership.bust_caches!
CodeTeams.bust_caches!
ParsePackwerk.bust_cache!
Packs.bust_cache!
allow(CodeTeams::Plugin).to receive(:registry).and_return({})
end
end
Expand Down

0 comments on commit ed56424

Please sign in to comment.