code_ownership 1.32.18 → 1.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f00d3f6cebe0c0c1a832fe6bd5487b39edb84a0cb316ecbcea33bbf2b090d9bd
4
- data.tar.gz: 6092a31cf222e8b734f19338d612ac1b08c121c20dbc822b1271e97ab11980c0
3
+ metadata.gz: b47612a8dd5a036e2e0f12d5706a0f014884ca977ca0a3db9ee433b580330761
4
+ data.tar.gz: 769f104467ccfe6cf73f4eddf491064adbcafe09b9666136d1e3df79e26eb525
5
5
  SHA512:
6
- metadata.gz: 054d5179ae0516d621f71e222308c28c769dfcfe1fd66595ddbe23f6f18126bbfc683ef9a6882a67e8599e88b5fd6800eb95c8f1b55e80c66a13bd8c13a245ba
7
- data.tar.gz: a1bcaa5dce9cb34158ce59d73b17d7cdc1494502ca802aa01b5bc3f5af507fd8187b5561e8b26f24151ec1e72eeee24a12c4b314f853af4a0f9230530e6d500d
6
+ metadata.gz: 1f048953162a4d95d7c44df6fff4138f38b645d042db15bce56cb945eefa722cef616a92e2f9aeb7e1ab4fd76a6e335b6d8f67cc2ff013e076ddc16deb6e40d6
7
+ data.tar.gz: c0f981c11675470220d58e06b37c737c873482e9d4c83a19bdb3995e8ffd05a45a07528892acf405a324efc8e6687f5d2404740aa9c23de1ca6930115cbda238
data/README.md CHANGED
@@ -21,6 +21,15 @@ metadata:
21
21
  owner: Team
22
22
  ```
23
23
 
24
+ You can also define `owner` as a top-level key, e.g.
25
+ ```yml
26
+ enforce_dependency: true
27
+ enforce_privacy: true
28
+ owner: Team
29
+ ```
30
+
31
+ 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.
32
+
24
33
  ### Glob-Based Ownership
25
34
  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`:
26
35
  ```yml
@@ -53,7 +53,10 @@ module CodeOwnership
53
53
 
54
54
  cache.each do |mapper_description, ownership_map_cache|
55
55
  ownership_entries = []
56
- ownership_map_cache.each do |path, code_team|
56
+ sorted_ownership_map_cache = ownership_map_cache.sort_by do |glob, team|
57
+ glob
58
+ end
59
+ sorted_ownership_map_cache.to_h.each do |path, code_team|
57
60
  team_mapping = github_team_map[code_team.name]
58
61
  next if team_mapping.nil?
59
62
 
@@ -56,7 +56,7 @@ module CodeOwnership
56
56
 
57
57
  sig { params(package: Packs::Pack).returns(T.nilable(CodeTeams::Team)) }
58
58
  def owner_for_package(package)
59
- raw_owner_value = package.metadata['owner']
59
+ raw_owner_value = package.raw_hash['owner'] || package.metadata['owner']
60
60
  return nil if !raw_owner_value
61
61
 
62
62
  Private.find_team!(
@@ -0,0 +1,24 @@
1
+
2
+ # typed: strict
3
+ # frozen_string_literal: true
4
+
5
+ require 'packwerk'
6
+
7
+ module CodeOwnership
8
+ module Private
9
+ class PackOwnershipValidator
10
+ extend T::Sig
11
+ include Packwerk::Validator
12
+
13
+ sig { override.params(package_set: Packwerk::PackageSet, configuration: Packwerk::Configuration).returns(Result) }
14
+ def call(package_set, configuration)
15
+ Result.new(ok: true)
16
+ end
17
+
18
+ sig { override.returns(T::Array[String]) }
19
+ def permitted_keys
20
+ %w[owner]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -14,10 +14,8 @@ module CodeOwnership
14
14
 
15
15
  actual_content_lines = CodeownersFile.actual_contents_lines
16
16
  expected_content_lines = CodeownersFile.expected_contents_lines
17
- missing_lines = expected_content_lines - actual_content_lines
18
- extra_lines = actual_content_lines - expected_content_lines
19
17
 
20
- codeowners_up_to_date = !missing_lines.any? && !extra_lines.any?
18
+ codeowners_up_to_date = actual_content_lines == expected_content_lines
21
19
  errors = T.let([], T::Array[String])
22
20
 
23
21
  if !codeowners_up_to_date
@@ -26,8 +24,14 @@ module CodeOwnership
26
24
  if stage_changes
27
25
  `git add #{CodeownersFile.path}`
28
26
  end
27
+ # If there is no current file or its empty, display a shorter message.
28
+ elsif actual_content_lines == [""]
29
+ errors << <<~CODEOWNERS_ERROR
30
+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
31
+ CODEOWNERS_ERROR
29
32
  else
30
- # If there is no current file or its empty, display a shorter message.
33
+ missing_lines = expected_content_lines - actual_content_lines
34
+ extra_lines = actual_content_lines - expected_content_lines
31
35
 
32
36
  missing_lines_text = if missing_lines.any?
33
37
  <<~COMMENT
@@ -50,20 +54,19 @@ module CodeOwnership
50
54
  elsif extra_lines_text
51
55
  extra_lines_text
52
56
  else
53
- ""
57
+ <<~TEXT
58
+ There may be extra lines, or lines are out of order.
59
+ You can try to regenerate the CODEOWNERS file from scratch:
60
+ 1) `rm .github/CODEOWNERS`
61
+ 2) `bin/codeownership validate`
62
+ TEXT
54
63
  end
55
64
 
56
- if actual_content_lines == [""]
57
- errors << <<~CODEOWNERS_ERROR
58
- CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
59
- CODEOWNERS_ERROR
60
- else
61
- errors << <<~CODEOWNERS_ERROR
62
- CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
65
+ errors << <<~CODEOWNERS_ERROR
66
+ CODEOWNERS out of date. Run `bin/codeownership validate` to update the CODEOWNERS file
63
67
 
64
- #{diff_text.chomp}
65
- CODEOWNERS_ERROR
66
- end
68
+ #{diff_text.chomp}
69
+ CODEOWNERS_ERROR
67
70
  end
68
71
  end
69
72
 
@@ -13,6 +13,10 @@ require 'code_ownership/private'
13
13
  require 'code_ownership/cli'
14
14
  require 'code_ownership/configuration'
15
15
 
16
+ if defined?(Packwerk)
17
+ require 'code_ownership/private/permit_pack_owner_top_level_key'
18
+ end
19
+
16
20
  module CodeOwnership
17
21
  extend self
18
22
  extend T::Sig
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_ownership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.32.18
4
+ version: 1.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: code_teams
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: packwerk
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: railties
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  description: A gem to help engineering teams declare ownership of code
126
154
  email:
127
155
  - dev@gusto.com
@@ -146,6 +174,7 @@ files:
146
174
  - lib/code_ownership/private/ownership_mappers/team_globs.rb
147
175
  - lib/code_ownership/private/ownership_mappers/team_yml_ownership.rb
148
176
  - lib/code_ownership/private/parse_js_packages.rb
177
+ - lib/code_ownership/private/permit_pack_owner_top_level_key.rb
149
178
  - lib/code_ownership/private/team_plugins/github.rb
150
179
  - lib/code_ownership/private/team_plugins/ownership.rb
151
180
  - lib/code_ownership/private/validations/files_have_owners.rb