Skip to content

Commit

Permalink
Support packwerk validator for top-level owner key in package.yml fil…
Browse files Browse the repository at this point in the history
…es (#68)
  • Loading branch information
Alex Evanczuk authored May 15, 2023
1 parent 8bd467a commit 69bcee9
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 28 deletions.
119 changes: 99 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,101 @@
PATH
remote: .
specs:
code_ownership (1.32.19)
code_ownership (1.33.0)
code_teams (~> 1.0)
packs
sorbet-runtime (>= 0.5.10821)

GEM
remote: https://rubygems.org/
specs:
actionpack (7.0.4.3)
actionview (= 7.0.4.3)
activesupport (= 7.0.4.3)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionview (7.0.4.3)
activesupport (= 7.0.4.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activesupport (7.0.4.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
ast (2.4.2)
better_html (2.0.1)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
builder (3.2.4)
code_teams (1.0.1)
sorbet-runtime
coderay (1.1.3)
diff-lcs (1.4.4)
concurrent-ruby (1.2.2)
constant_resolver (0.2.0)
crass (1.0.6)
diff-lcs (1.5.0)
erubi (1.12.0)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
loofah (2.21.2)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
method_source (1.0.0)
mini_portile2 (2.8.2)
minitest (5.18.0)
netrc (0.11.0)
nokogiri (1.14.4)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.14.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.14.4-x86_64-darwin)
racc (~> 1.4)
packs (0.0.6)
sorbet-runtime
parser (3.1.2.0)
packwerk (3.0.1)
activesupport (>= 6.0)
ast
better_html
bundler
constant_resolver (>= 0.2.0)
parallel
parser
sorbet-runtime (>= 0.5.9914)
zeitwerk (>= 2.6.1)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
racc (1.6.2)
rack (2.2.7)
rack-test (2.1.0)
rack (>= 1.3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
railties (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
rbi (0.0.14)
rbi (0.0.16)
ast
parser (>= 2.6.4.0)
sorbet-runtime (>= 0.5.9204)
Expand All @@ -41,6 +113,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
smart_properties (1.17.0)
sorbet (0.5.10821)
sorbet-static (= 0.5.10821)
sorbet-runtime (0.5.10821)
Expand All @@ -54,29 +127,33 @@ GEM
sorbet-static (0.5.10821-universal-darwin-21)
sorbet-static (0.5.10821-universal-darwin-22)
sorbet-static (0.5.10821-x86_64-linux)
spoom (1.1.11)
sorbet (>= 0.5.9204)
sorbet-static-and-runtime (0.5.10821)
sorbet (= 0.5.10821)
sorbet-runtime (= 0.5.10821)
spoom (1.2.1)
sorbet (>= 0.5.10187)
sorbet-runtime (>= 0.5.9204)
thor (>= 0.19.2)
tapioca (0.7.2)
bundler (>= 1.17.3)
pry (>= 0.12.2)
rbi (~> 0.0.0, >= 0.0.14)
sorbet-runtime (>= 0.5.9204)
sorbet-static (>= 0.5.9204)
spoom (~> 1.1.0, >= 1.1.11)
tapioca (0.11.6)
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (~> 0.0.0, >= 0.0.16)
sorbet-static-and-runtime (>= 0.5.10187)
spoom (~> 1.2.0, >= 1.2.0)
thor (>= 1.2.0)
yard-sorbet
thor (1.2.1)
unparser (0.6.4)
thor (1.2.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unparser (0.6.7)
diff-lcs (~> 1.3)
parser (>= 3.1.0)
webrick (1.7.0)
yard (0.9.27)
webrick (~> 1.7.0)
yard-sorbet (0.6.1)
parser (>= 3.2.0)
yard (0.9.34)
yard-sorbet (0.8.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)
zeitwerk (2.6.8)

PLATFORMS
arm64-darwin-20
Expand All @@ -87,7 +164,9 @@ PLATFORMS

DEPENDENCIES
code_ownership!
packwerk
pry
railties
rake
rspec (~> 3.0)
sorbet
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ metadata:
owner: Team
```
You can also define `owner` as a top-level key, e.g.
```yml
enforce_dependency: true
enforce_privacy: true
owner: Team
```

To do this, add `code_ownership` to the `require` key of your `packwerk.yml`. See https://github.com/Shopify/packwerk/blob/main/USAGE.md#loading-extensions for more information.

### Glob-Based Ownership
In your team's configured YML (see [`code_teams`](https://github.com/rubyatscale/code_teams)), you can set `owned_globs` to be a glob of files your team owns. For example, in `my_team.yml`:
```yml
Expand Down
4 changes: 3 additions & 1 deletion 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.32.19'
spec.version = '1.33.0'
spec.authors = ['Gusto Engineers']
spec.email = ['[email protected]']
spec.summary = 'A gem to help engineering teams declare ownership of code'
Expand Down Expand Up @@ -35,4 +35,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'sorbet'
spec.add_development_dependency 'tapioca'
spec.add_development_dependency 'packwerk'
spec.add_development_dependency 'railties'
end
4 changes: 4 additions & 0 deletions lib/code_ownership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
require 'code_ownership/cli'
require 'code_ownership/configuration'

if defined?(Packwerk)
require 'code_ownership/private/permit_pack_owner_top_level_key'
end

module CodeOwnership
extend self
extend T::Sig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def update_cache(cache, files)

sig { params(package: Packs::Pack).returns(T.nilable(CodeTeams::Team)) }
def owner_for_package(package)
raw_owner_value = package.metadata['owner']
raw_owner_value = package.raw_hash['owner'] || package.metadata['owner']
return nil if !raw_owner_value

Private.find_team!(
Expand Down
24 changes: 24 additions & 0 deletions lib/code_ownership/private/permit_pack_owner_top_level_key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

# typed: strict
# frozen_string_literal: true

require 'packwerk'

module CodeOwnership
module Private
class PackOwnershipValidator
extend T::Sig
include Packwerk::Validator

sig { override.params(package_set: Packwerk::PackageSet, configuration: Packwerk::Configuration).returns(Result) }
def call(package_set, configuration)
Result.new(ok: true)
end

sig { override.returns(T::Array[String]) }
def permitted_keys
%w[owner]
end
end
end
end
92 changes: 92 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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module CodeOwnership
write_file('packs/my_other_package/package.yml', <<~CONTENTS)
enforce_dependency: true
enforce_privacy: true
metadata:
owner: Bar
owner: Bar
CONTENTS

write_file('packs/my_other_package/my_file.rb')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ module CodeOwnership
write_file('packs/my_pack/package.yml', <<~CONTENTS)
enforce_dependency: true
enforce_privacy: true
metadata:
owner: Bar
owner: Bar
CONTENTS

write_file('package.yml', <<~CONTENTS)
Expand Down
Loading

0 comments on commit 69bcee9

Please sign in to comment.