danger-packwerk 0.14.4 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9961bce735a4a3e2ffd6e2f67719059652d08bcadcd06c8ab349b27452137e5
4
- data.tar.gz: 3eca02e4593c388f7170036cc78fde2b4efa4b2fe616b3d1591acb68ecffe610
3
+ metadata.gz: f38fbe114e0e85afe924da1be42e39c8479a6ef13523fc126edf5bfd203a98fc
4
+ data.tar.gz: 5bdc17faafe562b47dd446e2fe7b499ac00ae3d4409079b642ce2e5b379b100d
5
5
  SHA512:
6
- metadata.gz: 7167772693389751363dfd0c8e9956b30d7e2a237265d625f54de748453a3585a40b5e165e18bc6672d241344da08f216fd3614c031e9eea12b0e6eecca08c07
7
- data.tar.gz: 0a8df0931b48669d9cb3d779824c6391622666c7614ca4fffa1cf03e83d1ba63ac891a7b621f736b1ddeeec0044694fc93c2ea15dbee4d633acd9cec52e1621c
6
+ metadata.gz: eaecf4c410532cd52c535137a6f8d22d2aa259b5c8642924168da0b0c05846f4f8932e8e7ee80ea5908162e2eafbae5a3a6fb592417ccb4fd2ce9d29b0566fdf
7
+ data.tar.gz: 6ef4da09535909112982266995d556af9a6b6f78ce946df87045e4937841cc8d73c528b79a2ee5e0b7f6206bb8185a9d907733ad7c4b072ac2f7e80c75cd8d47
data/README.md CHANGED
@@ -43,8 +43,15 @@ class MyFormatter
43
43
  extend T::Sig
44
44
  include DangerPackwerk::Check::OffensesFormatter
45
45
  # Packwerk::ReferenceOffense: https://github.com/Shopify/packwerk/blob/main/lib/packwerk/reference_offense.rb
46
- sig { override.params(offenses: T::Array[Packwerk::ReferenceOffense], repo_link: String, org_name: String).returns(String) }
47
- def format_offenses(offenses, repo_link, org_name)
46
+ sig do
47
+ override.params(
48
+ offenses: T::Array[Packwerk::ReferenceOffense],
49
+ repo_link: String,
50
+ org_name: String
51
+ repo_url_builder: T.nilable(T.proc.params(constant_path: String).returns(String))
52
+ ).returns(String)
53
+ end
54
+ def format_offenses(offenses, repo_link, org_name, repo_builder_url: nil)
48
55
  # your logic here
49
56
  end
50
57
  end
@@ -98,8 +105,15 @@ class MyFormatter
98
105
  extend T::Sig
99
106
  include DangerPackwerk::Update::OffensesFormatter
100
107
  # DangerPackwerk::BasicReferenceOffense
101
- sig { override.params(offenses: T::Array[DangerPackwerk::BasicReferenceOffense], repo_link: String, org_name: String).returns(String) }
102
- def format_offenses(offenses, repo_link, org_name)
108
+ sig do
109
+ override.params(
110
+ offenses: T::Array[Packwerk::ReferenceOffense],
111
+ repo_link: String,
112
+ org_name: String
113
+ repo_url_builder: T.nilable(T.proc.params(constant_path: String).returns(String))
114
+ ).returns(String)
115
+ end
116
+ def format_offenses(offenses, repo_link, org_name, repo_builder_url: nil)
103
117
  # your logic here
104
118
  end
105
119
  end
@@ -21,10 +21,11 @@ module DangerPackwerk
21
21
  override.params(
22
22
  offenses: T::Array[Packwerk::ReferenceOffense],
23
23
  repo_link: String,
24
- org_name: String
24
+ org_name: String,
25
+ repo_url_builder: T.nilable(T.proc.params(constant_path: String).returns(String))
25
26
  ).returns(String)
26
27
  end
27
- def format_offenses(offenses, repo_link, org_name)
28
+ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
28
29
  reference_offense = T.must(offenses.first)
29
30
  violation_types = offenses.map(&:violation_type)
30
31
  referencing_file = reference_offense.reference.relative_path
@@ -45,11 +46,18 @@ module DangerPackwerk
45
46
  team_to_work_with = constant_source_package_ownership_info.owning_team ? constant_source_package_ownership_info.markdown_link_to_github_members_no_tag : 'the pack owner'
46
47
  privacy_violation_message = "- Does API in #{constant_source_package.name}/public support this use case?\n - If not, can we work with #{team_to_work_with} to create and use a public API?\n - If `#{constant_name}` should already be public, try `bin/packs make_public #{constant_location}`."
47
48
 
49
+ constant_location_url =
50
+ if repo_url_builder
51
+ repo_url_builder.call(constant_location)
52
+ else
53
+ "#{repo_link}/blob/main/#{constant_location}"
54
+ end
55
+
48
56
  if violation_types.include?(::DangerPackwerk::DEPENDENCY_VIOLATION_TYPE) && violation_types.include?(::DangerPackwerk::PRIVACY_VIOLATION_TYPE)
49
57
  <<~MESSAGE
50
58
  **Packwerk Violation**
51
59
  - Type: Privacy :lock: + Dependency :knot:
52
- - Constant: [<ins>`#{constant_name}`</ins>](#{repo_link}/blob/main/#{constant_location})
60
+ - Constant: [<ins>`#{constant_name}`</ins>](#{constant_location_url})
53
61
  - Owning pack: #{constant_source_package_name}
54
62
  #{constant_source_package_ownership_info.ownership_copy}
55
63
 
@@ -69,7 +77,7 @@ module DangerPackwerk
69
77
  <<~MESSAGE
70
78
  **Packwerk Violation**
71
79
  - Type: Dependency :knot:
72
- - Constant: [<ins>`#{constant_name}`</ins>](#{repo_link}/blob/main/#{constant_location})
80
+ - Constant: [<ins>`#{constant_name}`</ins>](#{constant_location_url})
73
81
  - Owning pack: #{constant_source_package_name}
74
82
  #{constant_source_package_ownership_info.ownership_copy}
75
83
 
@@ -88,7 +96,7 @@ module DangerPackwerk
88
96
  <<~MESSAGE
89
97
  **Packwerk Violation**
90
98
  - Type: Privacy :lock:
91
- - Constant: [<ins>`#{constant_name}`</ins>](#{repo_link}/blob/main/#{constant_location})
99
+ - Constant: [<ins>`#{constant_name}`</ins>](#{constant_location_url})
92
100
  - Owning pack: #{constant_source_package_name}
93
101
  #{constant_source_package_ownership_info.ownership_copy}
94
102
 
@@ -14,10 +14,11 @@ module DangerPackwerk
14
14
  abstract.params(
15
15
  offenses: T::Array[Packwerk::ReferenceOffense],
16
16
  repo_link: String,
17
- org_name: String
17
+ org_name: String,
18
+ repo_url_builder: T.nilable(T.proc.params(constant_path: String).returns(String))
18
19
  ).returns(String)
19
20
  end
20
- def format_offenses(offenses, repo_link, org_name); end
21
+ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil); end
21
22
  end
22
23
  end
23
24
  end
@@ -42,6 +42,7 @@ module DangerPackwerk
42
42
  )
43
43
  offenses_formatter ||= Update::DefaultFormatter.new
44
44
  repo_link = github.pr_json[:base][:repo][:html_url]
45
+ repo_url_builder = ->(constant_path) { "#{repo_link}/blob/#{github.pr_json[:head][:ref]}/#{constant_path}" }
45
46
  org_name = github.pr_json[:base][:repo][:owner][:login]
46
47
 
47
48
  git_filesystem = Private::GitFilesystem.new(git: git, root: root_path || '')
@@ -56,13 +57,13 @@ module DangerPackwerk
56
57
 
57
58
  current_comment_count = 0
58
59
 
59
- violation_diff.added_violations.group_by(&:class_name).each do |_class_name, violations|
60
+ violation_diff.added_violations.group_by(&:class_name).each_value do |violations|
60
61
  break if current_comment_count >= max_comments
61
62
 
62
63
  location = T.must(violations.first).file_location
63
64
 
64
65
  markdown(
65
- offenses_formatter.format_offenses(violations, repo_link, org_name),
66
+ offenses_formatter.format_offenses(violations, repo_link, org_name, repo_url_builder: repo_url_builder),
66
67
  line: location.line_number,
67
68
  file: git_filesystem.convert_to_filesystem(location.file)
68
69
  )
@@ -36,6 +36,10 @@ module DangerPackwerk
36
36
 
37
37
  PerConstantPerPackGrouping = CommentGroupingStrategy::PerConstantPerPack
38
38
 
39
+ # We probably want to check the `include` key of `packwerk.yml`. By default, this value is "**/*.{rb,rake,erb}",
40
+ # so we hardcode this in for now. If this blocks a user, we can take that opportunity to read from `packwerk.yml`.
41
+ TARGETED_FILES_EXTENSIONS = T.let(%w[.erb .rake .rb].freeze, T::Array[String])
42
+
39
43
  sig do
40
44
  params(
41
45
  offenses_formatter: T.nilable(Check::OffensesFormatter),
@@ -60,6 +64,7 @@ module DangerPackwerk
60
64
  )
61
65
  offenses_formatter ||= Check::DefaultFormatter.new
62
66
  repo_link = github.pr_json[:base][:repo][:html_url]
67
+ repo_url_builder = ->(constant_path) { "#{repo_link}/blob/#{github.pr_json[:head][:ref]}/#{constant_path}" }
63
68
  org_name = github.pr_json[:base][:repo][:owner][:login]
64
69
 
65
70
  # This is important because by default, Danger will leave a concantenated list of all its messages if it can't find a commentable place in the
@@ -80,7 +85,7 @@ module DangerPackwerk
80
85
 
81
86
  # We probably want to check the `include` key of `packwerk.yml`. By default, this value is "**/*.{rb,rake,erb}",
82
87
  # so we hardcode this in for now. If this blocks a user, we can take that opportunity to read from `packwerk.yml`.
83
- extension_is_targeted = ['.erb', '.rake', '.rb'].include?(path.extname)
88
+ extension_is_targeted = TARGETED_FILES_EXTENSIONS.include?(path.extname)
84
89
 
85
90
  # If a file has been modified via a rename, then `git.modified_files` will return an array that includes that file's *original* name.
86
91
  # Packwerk will ignore input files that do not exist, and when the PR only contains renamed Ruby files, that means packwerk check works
@@ -127,7 +132,7 @@ module DangerPackwerk
127
132
  else
128
133
  T.absurd(grouping_strategy)
129
134
  end
130
- end.each do |_group, unique_packwerk_reference_offenses|
135
+ end.each_value do |unique_packwerk_reference_offenses|
131
136
  break if current_comment_count >= max_comments
132
137
 
133
138
  current_comment_count += 1
@@ -136,7 +141,7 @@ module DangerPackwerk
136
141
  line_number = reference_offense.location&.line
137
142
  referencing_file = reference_offense.reference.relative_path
138
143
 
139
- message = offenses_formatter.format_offenses(unique_packwerk_reference_offenses, repo_link, org_name)
144
+ message = offenses_formatter.format_offenses(unique_packwerk_reference_offenses, repo_link, org_name, repo_url_builder: repo_url_builder)
140
145
  markdown(message, file: git_filesystem.convert_to_filesystem(referencing_file), line: line_number)
141
146
  end
142
147
 
@@ -13,14 +13,16 @@ module DangerPackwerk
13
13
 
14
14
  sig { returns(ConstantResolver) }
15
15
  def self.constant_resolver
16
- @constant_resolver = T.let(@constant_resolver, T.nilable(ConstantResolver))
17
- @constant_resolver ||= begin
18
- load_paths = Packwerk::RailsLoadPaths.for(Dir.pwd, environment: 'test')
19
- ConstantResolver.new(
20
- root_path: Dir.pwd,
21
- load_paths: T.unsafe(load_paths).keys
22
- )
23
- end
16
+ @constant_resolver ||= T.let(
17
+ begin
18
+ load_paths = Packwerk::RailsLoadPaths.for(Dir.pwd, environment: 'test')
19
+ ConstantResolver.new(
20
+ root_path: Dir.pwd,
21
+ load_paths: T.unsafe(load_paths).keys
22
+ )
23
+ end,
24
+ T.nilable(ConstantResolver)
25
+ )
24
26
  end
25
27
  end
26
28
 
@@ -15,8 +15,15 @@ module DangerPackwerk
15
15
  @custom_help_message = custom_help_message
16
16
  end
17
17
 
18
- sig { override.params(offenses: T::Array[BasicReferenceOffense], repo_link: String, org_name: String).returns(String) }
19
- def format_offenses(offenses, repo_link, org_name)
18
+ sig do
19
+ override.params(
20
+ offenses: T::Array[BasicReferenceOffense],
21
+ repo_link: String,
22
+ org_name: String,
23
+ repo_url_builder: T.nilable(T.proc.params(constant_path: String).returns(String))
24
+ ).returns(String)
25
+ end
26
+ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
20
27
  violation = T.must(offenses.first)
21
28
  referencing_file_pack = ParsePackwerk.package_from_path(violation.file)
22
29
  # We remove leading double colons as they feel like an implementation detail of packwerk.
@@ -14,10 +14,11 @@ module DangerPackwerk
14
14
  abstract.params(
15
15
  offenses: T::Array[BasicReferenceOffense],
16
16
  repo_link: String,
17
- org_name: String
17
+ org_name: String,
18
+ repo_url_builder: T.nilable(T.proc.params(constant_path: String).returns(String))
18
19
  ).returns(String)
19
20
  end
20
- def format_offenses(offenses, repo_link, org_name); end
21
+ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil); end
21
22
  end
22
23
  end
23
24
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DangerPackwerk
5
- VERSION = '0.14.4'
5
+ VERSION = '0.15.0'
6
6
  end
@@ -5,7 +5,7 @@
5
5
  require 'sorbet-runtime'
6
6
 
7
7
  module DangerPackwerk
8
- PACKAGE_TODO_PATTERN = T.let(/.*?package_todo\.yml\z/.freeze, Regexp)
8
+ PACKAGE_TODO_PATTERN = T.let(/.*?package_todo\.yml\z/, Regexp)
9
9
  DEPENDENCY_VIOLATION_TYPE = 'dependency'
10
10
  PRIVACY_VIOLATION_TYPE = 'privacy'
11
11
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.4
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
10
+ date: 2025-03-25 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: code_ownership
@@ -94,118 +93,6 @@ dependencies:
94
93
  - - ">="
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: bundler
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '2.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '2.0'
111
- - !ruby/object:Gem::Dependency
112
- name: pry
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rake
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: rspec
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '3.0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '3.0'
153
- - !ruby/object:Gem::Dependency
154
- name: rubocop
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: 1.26.0
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: 1.26.0
167
- - !ruby/object:Gem::Dependency
168
- name: rubocop-sorbet
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: 0.6.0
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: 0.6.0
181
- - !ruby/object:Gem::Dependency
182
- name: sorbet
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: tapioca
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
96
  description: Danger plugin for packwerk.
210
97
  email:
211
98
  - dev@gusto.com
@@ -238,7 +125,6 @@ metadata:
238
125
  source_code_uri: https://github.com/rubyatscale/danger-packwerk
239
126
  changelog_uri: https://github.com/rubyatscale/danger-packwerk/releases
240
127
  allowed_push_host: https://rubygems.org
241
- post_install_message:
242
128
  rdoc_options: []
243
129
  require_paths:
244
130
  - lib
@@ -246,15 +132,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
132
  requirements:
247
133
  - - ">="
248
134
  - !ruby/object:Gem::Version
249
- version: '2.6'
135
+ version: '3.1'
250
136
  required_rubygems_version: !ruby/object:Gem::Requirement
251
137
  requirements:
252
138
  - - ">="
253
139
  - !ruby/object:Gem::Version
254
140
  version: '0'
255
141
  requirements: []
256
- rubygems_version: 3.5.9
257
- signing_key:
142
+ rubygems_version: 3.6.2
258
143
  specification_version: 4
259
144
  summary: Danger plugin for packwerk.
260
145
  test_files: []