danger-packwerk 0.1.3 → 0.4.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: e8ad610d58f87b5c05d4f55688a43be6fe566a24a987d29dbd43bc1397e42e2b
4
- data.tar.gz: d3db9e2c065272e5d1a249b81edd5ab5b4ac253fd0281df5e8cc5f5fc4ce92a9
3
+ metadata.gz: 1a50f4eb29e8b1b964d365ccdc30749842efe091d659a5d62a7252d5af487fc2
4
+ data.tar.gz: ad82d90f8db9e0a416dff61ab76ab2a9084ccd39335e1a95e2b2c9c9b566cd18
5
5
  SHA512:
6
- metadata.gz: d707148404ee53fa7ca6b7fceb595ed8e97a746e57b2f6b3ba93d6e7f8f7a435524c641c89884d3b5e243fb2f19f71119b17689429d77dd5a280efd4c212c854
7
- data.tar.gz: 8927da7749c65108bc30cfa1790e2dd2eb620c38a3895c201fad152f72c420c76950a5b5ee3f6ba5329990cb2c339af2717ebd5fc19c604e412636526b9e3c00
6
+ metadata.gz: db4b2cb2d0c4a3cb8e24667fc60e32f2172abb33f486c0613a4977a73412d15f10136a977724257a707af203314c5569375bb43447848fc27eb8e2b20ee721ef
7
+ data.tar.gz: ceb901dc21ad848fd0fabcbb8b299f2d7a3e101d3d295a5fbbbbdd49b086206f196b5996e4bf64ea40deadae893a3add09fc84df1890e80f5086ad44fa7e0dcf
@@ -45,7 +45,14 @@ module DangerPackwerk
45
45
 
46
46
  current_comment_count = 0
47
47
 
48
- violation_diff.added_violations.group_by(&:class_name).each do |_class_name, violations|
48
+ # The format for git.renamed_files is a T::Array[{after: "some/path/new", before: "some/path/old"}]
49
+ renamed_files = git.renamed_files.map { |before_after_file| before_after_file[:after] }
50
+
51
+ violations_to_comment_on = violation_diff.added_violations.reject do |violation|
52
+ renamed_files.include?(violation.file)
53
+ end
54
+
55
+ violations_to_comment_on.group_by(&:class_name).each do |_class_name, violations|
49
56
  break if current_comment_count >= max_comments
50
57
 
51
58
  location = T.must(violations.first).file_location
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'danger'
5
5
  require 'packwerk'
6
+ require 'parse_packwerk'
6
7
  require 'sorbet-runtime'
7
8
  require 'danger-packwerk/packwerk_wrapper'
8
9
 
@@ -23,13 +24,23 @@ module DangerPackwerk
23
24
  DEFAULT_FAIL = false
24
25
  DEFAULT_FAILURE_MESSAGE = 'Packwerk violations were detected! Please resolve them to unblock the build.'
25
26
 
27
+ class CommentGroupingStrategy < ::T::Enum
28
+ enums do
29
+ PerConstantPerLocation = new
30
+ PerConstantPerPack = new
31
+ end
32
+ end
33
+
34
+ PerConstantPerPackGrouping = CommentGroupingStrategy::PerConstantPerPack
35
+
26
36
  sig do
27
37
  params(
28
38
  max_comments: Integer,
29
39
  offenses_formatter: OffensesFormatter,
30
40
  fail_build: T::Boolean,
31
41
  failure_message: String,
32
- on_failure: OnFailure
42
+ on_failure: OnFailure,
43
+ grouping_strategy: CommentGroupingStrategy
33
44
  ).void
34
45
  end
35
46
  def check(
@@ -37,7 +48,8 @@ module DangerPackwerk
37
48
  offenses_formatter: DEFAULT_OFFENSES_FORMATTER,
38
49
  fail_build: DEFAULT_FAIL,
39
50
  failure_message: DEFAULT_FAILURE_MESSAGE,
40
- on_failure: DEFAULT_ON_FAILURE
51
+ on_failure: DEFAULT_ON_FAILURE,
52
+ grouping_strategy: CommentGroupingStrategy::PerConstantPerLocation
41
53
  )
42
54
  # 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
43
55
  # diff to leave its message. This is an especially bad UX because it will be a huge wall of text not connected to the source of the issue.
@@ -75,11 +87,21 @@ module DangerPackwerk
75
87
  # We group by the constant name, line number, and reference path. Any offenses with these same values should only differ on what type of violation
76
88
  # they are (privacy or dependency). We put privacy and dependency violation messages in the same comment since they would occur on the same line.
77
89
  packwerk_reference_offenses.group_by do |packwerk_reference_offense|
78
- [
79
- packwerk_reference_offense.reference.constant.name,
80
- packwerk_reference_offense.location.line,
81
- packwerk_reference_offense.reference.relative_path
82
- ]
90
+ case grouping_strategy
91
+ when CommentGroupingStrategy::PerConstantPerLocation
92
+ [
93
+ packwerk_reference_offense.reference.constant.name,
94
+ packwerk_reference_offense.location.line,
95
+ packwerk_reference_offense.reference.relative_path
96
+ ]
97
+ when CommentGroupingStrategy::PerConstantPerPack
98
+ [
99
+ packwerk_reference_offense.reference.constant.name,
100
+ ParsePackwerk.package_from_path(packwerk_reference_offense.reference.relative_path)
101
+ ]
102
+ else
103
+ T.absurd(grouping_strategy)
104
+ end
83
105
  end.each do |_group, unique_packwerk_reference_offenses|
84
106
  break if current_comment_count >= max_comments
85
107
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DangerPackwerk
5
- VERSION = '0.1.3'
5
+ VERSION = '0.4.0'
6
6
  end
@@ -0,0 +1,146 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `parse_packwerk` gem.
5
+ # Please instead update this file by running `bin/tapioca gem parse_packwerk`.
6
+
7
+ module ParsePackwerk
8
+ class << self
9
+ sig { returns(T::Array[::ParsePackwerk::Package]) }
10
+ def all; end
11
+
12
+ sig { void }
13
+ def bust_cache!; end
14
+
15
+ sig { params(name: ::String).returns(T.nilable(::ParsePackwerk::Package)) }
16
+ def find(name); end
17
+
18
+ sig { params(file_path: T.any(::Pathname, ::String)).returns(T.nilable(::ParsePackwerk::Package)) }
19
+ def package_from_path(file_path); end
20
+
21
+ sig { params(package: ::ParsePackwerk::Package).void }
22
+ def write_package_yml!(package); end
23
+
24
+ sig { returns(::ParsePackwerk::Configuration) }
25
+ def yml; end
26
+
27
+ private
28
+
29
+ sig { returns(T::Hash[::String, ::ParsePackwerk::Package]) }
30
+ def packages_by_name; end
31
+ end
32
+ end
33
+
34
+ class ParsePackwerk::Configuration < ::T::Struct
35
+ const :exclude, T::Array[::String]
36
+ const :package_paths, T::Array[::String]
37
+
38
+ class << self
39
+ sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) }
40
+ def excludes(config_hash); end
41
+
42
+ sig { returns(::ParsePackwerk::Configuration) }
43
+ def fetch; end
44
+
45
+ def inherited(s); end
46
+
47
+ sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) }
48
+ def package_paths(config_hash); end
49
+ end
50
+ end
51
+
52
+ ParsePackwerk::DEFAULT_EXCLUDE_GLOBS = T.let(T.unsafe(nil), Array)
53
+ ParsePackwerk::DEFAULT_PACKAGE_PATHS = T.let(T.unsafe(nil), Array)
54
+ ParsePackwerk::DEPENDENCIES = T.let(T.unsafe(nil), String)
55
+ ParsePackwerk::DEPRECATED_REFERENCES_YML_NAME = T.let(T.unsafe(nil), String)
56
+
57
+ class ParsePackwerk::DeprecatedReferences < ::T::Struct
58
+ const :pathname, ::Pathname
59
+ const :violations, T::Array[::ParsePackwerk::Violation]
60
+
61
+ class << self
62
+ sig { params(package: ::ParsePackwerk::Package).returns(::ParsePackwerk::DeprecatedReferences) }
63
+ def for(package); end
64
+
65
+ sig { params(pathname: ::Pathname).returns(::ParsePackwerk::DeprecatedReferences) }
66
+ def from(pathname); end
67
+
68
+ def inherited(s); end
69
+ end
70
+ end
71
+
72
+ ParsePackwerk::ENFORCE_DEPENDENCIES = T.let(T.unsafe(nil), String)
73
+ ParsePackwerk::ENFORCE_PRIVACY = T.let(T.unsafe(nil), String)
74
+ ParsePackwerk::METADATA = T.let(T.unsafe(nil), String)
75
+ ParsePackwerk::MetadataYmlType = T.type_alias { T::Hash[T.untyped, T.untyped] }
76
+
77
+ class ParsePackwerk::MissingConfiguration < ::StandardError
78
+ sig { params(packwerk_file_name: ::Pathname).void }
79
+ def initialize(packwerk_file_name); end
80
+ end
81
+
82
+ ParsePackwerk::PACKAGE_YML_NAME = T.let(T.unsafe(nil), String)
83
+ ParsePackwerk::PACKWERK_YML_NAME = T.let(T.unsafe(nil), String)
84
+
85
+ class ParsePackwerk::Package < ::T::Struct
86
+ const :dependencies, T::Array[::String]
87
+ const :enforce_dependencies, T::Boolean
88
+ const :enforce_privacy, T::Boolean
89
+ const :metadata, T::Hash[T.untyped, T.untyped]
90
+ const :name, ::String
91
+
92
+ sig { returns(::Pathname) }
93
+ def directory; end
94
+
95
+ sig { returns(T::Boolean) }
96
+ def enforces_dependencies?; end
97
+
98
+ sig { returns(T::Boolean) }
99
+ def enforces_privacy?; end
100
+
101
+ sig { returns(::Pathname) }
102
+ def yml; end
103
+
104
+ class << self
105
+ sig { params(pathname: ::Pathname).returns(::ParsePackwerk::Package) }
106
+ def from(pathname); end
107
+
108
+ def inherited(s); end
109
+ end
110
+ end
111
+
112
+ class ParsePackwerk::PackageSet
113
+ class << self
114
+ sig do
115
+ params(
116
+ package_pathspec: T::Array[::String],
117
+ exclude_pathspec: T::Array[::String]
118
+ ).returns(T::Array[::ParsePackwerk::Package])
119
+ end
120
+ def from(package_pathspec:, exclude_pathspec:); end
121
+
122
+ private
123
+
124
+ sig { params(globs: T::Array[::String], path: ::Pathname).returns(T::Boolean) }
125
+ def exclude_path?(globs, path); end
126
+ end
127
+ end
128
+
129
+ ParsePackwerk::ROOT_PACKAGE_NAME = T.let(T.unsafe(nil), String)
130
+
131
+ class ParsePackwerk::Violation < ::T::Struct
132
+ const :class_name, ::String
133
+ const :files, T::Array[::String]
134
+ const :to_package_name, ::String
135
+ const :type, ::String
136
+
137
+ sig { returns(T::Boolean) }
138
+ def dependency?; end
139
+
140
+ sig { returns(T::Boolean) }
141
+ def privacy?; end
142
+
143
+ class << self
144
+ def inherited(s); end
145
+ end
146
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.4.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: 2022-04-25 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parse_packwerk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sorbet-runtime
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -186,15 +200,16 @@ files:
186
200
  - sorbet/config
187
201
  - sorbet/rbi/gems/danger@8.5.0.rbi
188
202
  - sorbet/rbi/gems/packwerk@1.3.2.rbi
203
+ - sorbet/rbi/gems/parse_packwerk@0.12.0.rbi
189
204
  - sorbet/rbi/todo.rbi
190
205
  - sorbet/tapioca/require.rb
191
- homepage: https://github.com/bigrails/danger-packwerk
206
+ homepage: https://github.com/rubyatscale/danger-packwerk
192
207
  licenses:
193
208
  - MIT
194
209
  metadata:
195
- homepage_uri: https://github.com/bigrails/danger-packwerk
196
- source_code_uri: https://github.com/bigrails/danger-packwerk
197
- changelog_uri: https://github.com/bigrails/danger-packwerk/releases
210
+ homepage_uri: https://github.com/rubyatscale/danger-packwerk
211
+ source_code_uri: https://github.com/rubyatscale/danger-packwerk
212
+ changelog_uri: https://github.com/rubyatscale/danger-packwerk/releases
198
213
  allowed_push_host: https://rubygems.org
199
214
  post_install_message:
200
215
  rdoc_options: []