danger-dangermattic 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/reusable-run-danger.yml +3 -3
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +1 -1
- data/lib/dangermattic/gem_version.rb +1 -1
- data/lib/dangermattic/plugins/common/git_utils.rb +4 -2
- data/lib/dangermattic/plugins/tracks_checker.rb +1 -1
- data/spec/tracks_checker_spec.rb +42 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615ffb488aacbecf44a30b87c7c782d97bbf4a5104ada852ea6565d20d092ed4
|
4
|
+
data.tar.gz: f7d16f0afcd180ea5271865f091d0c33866900f3102745cb31b886b59cb8348f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbbd4c83b4c026dec016433abc3fbb2c8275c28aceab5863e4c39160031484550b1bc41092c74ba6786738863b43431089d2b5e02e239e95eca2ee5045c01a6f
|
7
|
+
data.tar.gz: df4b5edf15a414ead103abc8b0c0bc182baac45425170be3aea0df1186f6a233f2f401b894da1cbd3c204668be97cc43c527bd6e969fabc7ce5e1f30fb8b26d6
|
@@ -34,13 +34,13 @@ jobs:
|
|
34
34
|
- name: "☢️ Danger PR Check"
|
35
35
|
env:
|
36
36
|
PR_URL: ${{ github.event.pull_request.html_url }}
|
37
|
-
|
37
|
+
READ_ONLY_MODE: ${{ github.event.pull_request.head.repo.fork || github.actor == 'dependabot[bot]' }}
|
38
38
|
REMOVE_PREVIOUS_COMMENTS: ${{ inputs.remove-previous-comments }}
|
39
|
-
DANGER_GITHUB_API_TOKEN: ${{ secrets.github-token }}
|
39
|
+
DANGER_GITHUB_API_TOKEN: ${{ secrets.github-token || secrets.GITHUB_TOKEN }}
|
40
40
|
run: |
|
41
41
|
echo "--- 🏃 Running Danger: PR Check"
|
42
42
|
|
43
|
-
if [ "$
|
43
|
+
if [ "$READ_ONLY_MODE" = true ]; then
|
44
44
|
danger_output=$(bundle exec danger pr "$PR_URL" --verbose)
|
45
45
|
|
46
46
|
echo "$danger_output"
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
---
|
4
4
|
|
5
|
+
## 1.0.1
|
6
|
+
|
7
|
+
### Bug Fixes
|
8
|
+
|
9
|
+
- Fix `tracks_checker` plugin so that only additions / removals in a diff are considered in the check, therefore not including the context parts of the diff.
|
10
|
+
|
5
11
|
## 1.0.0
|
6
12
|
|
7
|
-
After some time being developed and tested across a few repositories, this is our first stable release.
|
13
|
+
- After some time being developed and tested across a few repositories, this is our first stable release.
|
data/Gemfile.lock
CHANGED
@@ -81,9 +81,11 @@ module Danger
|
|
81
81
|
#
|
82
82
|
# @param files [Array<String>] List of file names to check
|
83
83
|
# @param line_matcher [Proc] A callable that takes a line and returns true if it matches the desired pattern
|
84
|
-
# @param change_type [Symbol, nil] Change type to filter lines (e.g.,
|
84
|
+
# @param change_type [Symbol, Array<Symbol>, nil] Change type(s) to filter lines (e.g., `:added`, `:removed`,
|
85
|
+
# `:context`, `[:added, :removed]`, …), or nil for no filter
|
85
86
|
# @return [Array<MatchedData>] Array of MatchedData objects representing matched lines in files
|
86
87
|
def matching_lines_in_diff_files(files:, line_matcher:, change_type: nil)
|
88
|
+
change_types = Array(change_type).map(&:to_sym)
|
87
89
|
matched_data = []
|
88
90
|
|
89
91
|
files.each do |file|
|
@@ -92,7 +94,7 @@ module Danger
|
|
92
94
|
diff = danger.git.diff_for_file(file)
|
93
95
|
|
94
96
|
diff.patch.each_line do |line|
|
95
|
-
matched_lines << line if line_matcher.call(line) && (change_type.nil? || change_type(diff_line: line)
|
97
|
+
matched_lines << line if line_matcher.call(line) && (change_type.nil? || change_types.include?(change_type(diff_line: line)))
|
96
98
|
end
|
97
99
|
|
98
100
|
matched_data << MatchedData.new(file, matched_lines) unless matched_lines.empty?
|
@@ -63,7 +63,7 @@ module Danger
|
|
63
63
|
matched_lines = git_utils.matching_lines_in_diff_files(
|
64
64
|
files: git_utils.all_changed_files,
|
65
65
|
line_matcher: ->(line) { tracks_usage_matchers.any? { |tracks_usage_match| line.match(tracks_usage_match) } },
|
66
|
-
change_type:
|
66
|
+
change_type: %i[added removed]
|
67
67
|
)
|
68
68
|
|
69
69
|
!matched_lines.empty?
|
data/spec/tracks_checker_spec.rb
CHANGED
@@ -68,7 +68,7 @@ module Danger
|
|
68
68
|
it 'does nothing when there are no changes in Tracks-related files' do
|
69
69
|
modified_files = ['MyClass.swift']
|
70
70
|
allow(@plugin.git_utils).to receive(:all_changed_files).and_return(modified_files)
|
71
|
-
allow(@plugin.git_utils).to receive(:matching_lines_in_diff_files).with(files: modified_files, line_matcher: kind_of(Proc), change_type:
|
71
|
+
allow(@plugin.git_utils).to receive(:matching_lines_in_diff_files).with(files: modified_files, line_matcher: kind_of(Proc), change_type: %i[added removed]).and_return([])
|
72
72
|
|
73
73
|
@plugin.check_tracks_changes(tracks_files: track_files, tracks_usage_matchers: tracks_matchers, tracks_label: nil)
|
74
74
|
|
@@ -83,12 +83,7 @@ module Danger
|
|
83
83
|
modified_files = ['MyClass.kt']
|
84
84
|
allow(@plugin.git_utils).to receive(:all_changed_files).and_return(modified_files)
|
85
85
|
|
86
|
-
|
87
|
-
analytics_call_in_diff = '- AnalyticsTracker.track("myEvent1")'
|
88
|
-
expect(args[:line_matcher].call(analytics_call_in_diff)).to be true
|
89
|
-
|
90
|
-
[analytics_call_in_diff]
|
91
|
-
end
|
86
|
+
allow_diff_match(modified_files: modified_files, diff_line: '- AnalyticsTracker.track("myEvent1")', expect_match: true)
|
92
87
|
|
93
88
|
@plugin.check_tracks_changes(tracks_files: track_files, tracks_usage_matchers: tracks_matchers, tracks_label: tracks_label)
|
94
89
|
|
@@ -99,12 +94,7 @@ module Danger
|
|
99
94
|
modified_files = ['MyClass.kt']
|
100
95
|
allow(@plugin.git_utils).to receive(:all_changed_files).and_return(modified_files)
|
101
96
|
|
102
|
-
|
103
|
-
analytics_call_in_diff = '- AnalyticsTracker.track("evento")'
|
104
|
-
expect(args[:line_matcher].call(analytics_call_in_diff)).to be true
|
105
|
-
|
106
|
-
[analytics_call_in_diff]
|
107
|
-
end
|
97
|
+
allow_diff_match(modified_files: modified_files, diff_line: '+ AnalyticsTracker.track("evento")', expect_match: true)
|
108
98
|
|
109
99
|
@plugin.check_tracks_changes(tracks_files: track_files, tracks_usage_matchers: tracks_matchers, tracks_label: nil)
|
110
100
|
|
@@ -116,12 +106,7 @@ module Danger
|
|
116
106
|
modified_files = ['MyClass.kt']
|
117
107
|
allow(@plugin.git_utils).to receive(:all_changed_files).and_return(modified_files)
|
118
108
|
|
119
|
-
|
120
|
-
analytics_call_in_diff = '- AnalyticsTracker.track("myEvent1")'
|
121
|
-
expect(args[:line_matcher].call(analytics_call_in_diff)).to be true
|
122
|
-
|
123
|
-
[analytics_call_in_diff]
|
124
|
-
end
|
109
|
+
allow_diff_match(modified_files: modified_files, diff_line: '- AnalyticsTracker.track("evento")', expect_match: true)
|
125
110
|
|
126
111
|
tracks_label = 'TRACKS PR'
|
127
112
|
@plugin.check_tracks_changes(tracks_files: track_files, tracks_usage_matchers: tracks_matchers, tracks_label: tracks_label)
|
@@ -133,12 +118,34 @@ module Danger
|
|
133
118
|
modified_files = ['MyClass.kt']
|
134
119
|
allow(@plugin.git_utils).to receive(:all_changed_files).and_return(modified_files)
|
135
120
|
|
136
|
-
|
137
|
-
|
138
|
-
|
121
|
+
allow_diff_match(modified_files: modified_files, diff_line: '- AnalyticsHelper.log("event_1")', expect_match: false)
|
122
|
+
|
123
|
+
@plugin.check_tracks_changes(tracks_files: track_files, tracks_usage_matchers: tracks_matchers, tracks_label: nil)
|
124
|
+
|
125
|
+
expect(@dangerfile).to not_report
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'does nothing when there are matching changes but in the context parts of the diff' do
|
129
|
+
modified_file = 'MyClass.kt'
|
130
|
+
allow(@plugin.git_utils).to receive(:all_changed_files).and_return([modified_file])
|
131
|
+
|
132
|
+
tracks_diff = <<~STRINGS
|
133
|
+
diff --git a/MyClass.kt b/MyClass.kt
|
134
|
+
index 5794d472..772e2b99 100644
|
135
|
+
- a/MyClass
|
136
|
+
+ b/MyClass
|
137
|
+
@@ -1,3 +1,6 @@
|
138
|
+
AnalyticsTracker.track("myMagicEvent1")
|
139
|
+
// call magic
|
140
|
+
+ AnalyticsHelper.log("event_1")
|
141
|
+
+ AnalyticsHelper.log("event_2")
|
142
|
+
+ AnotherUtil.callMagic()
|
143
|
+
AnalyticsTracker.track("myMagicEvent2")
|
144
|
+
STRINGS
|
139
145
|
|
140
|
-
|
141
|
-
|
146
|
+
diff = GitDiffStruct.new('modified', modified_file, tracks_diff)
|
147
|
+
|
148
|
+
allow(@plugin.git).to receive(:diff_for_file).with(modified_file).and_return(diff)
|
142
149
|
|
143
150
|
@plugin.check_tracks_changes(tracks_files: track_files, tracks_usage_matchers: tracks_matchers, tracks_label: nil)
|
144
151
|
|
@@ -147,6 +154,17 @@ module Danger
|
|
147
154
|
end
|
148
155
|
end
|
149
156
|
|
157
|
+
def allow_diff_match(modified_files:, diff_line:, expect_match:)
|
158
|
+
allow(@plugin.git_utils).to receive(:matching_lines_in_diff_files).with(files: modified_files, line_matcher: kind_of(Proc), change_type: %i[added removed]) do |args|
|
159
|
+
expect(args[:line_matcher].call(diff_line)).to be expect_match
|
160
|
+
|
161
|
+
result = []
|
162
|
+
result.append(diff_line) if expect_match
|
163
|
+
|
164
|
+
result
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
150
168
|
def expect_label_checks(tracks_label)
|
151
169
|
expect(@dangerfile.status_report[:messages]).to eq [TracksChecker::TRACKS_PR_INSTRUCTIONS + format(TracksChecker::TRACKS_NO_LABEL_INSTRUCTION_FORMAT, tracks_label)]
|
152
170
|
expect(@dangerfile.status_report[:errors]).to eq [format(TracksChecker::TRACKS_NO_LABEL_MESSAGE_FORMAT, tracks_label)]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danger-dangermattic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Automattic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger
|