danger-dangermattic 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.buildkite/gem-push.sh +15 -0
  3. data/.buildkite/pipeline.yml +69 -0
  4. data/.bundle/config +2 -0
  5. data/.github/workflows/reusable-check-labels-on-issues.yml +91 -0
  6. data/.github/workflows/reusable-run-danger.yml +54 -0
  7. data/.gitignore +30 -0
  8. data/.rubocop.yml +67 -0
  9. data/.ruby-version +1 -0
  10. data/.yardopts +7 -0
  11. data/CHANGELOG.md +7 -0
  12. data/Gemfile +5 -0
  13. data/Gemfile.lock +191 -0
  14. data/Guardfile +21 -0
  15. data/LICENSE +373 -0
  16. data/README.md +68 -0
  17. data/Rakefile +24 -0
  18. data/danger-dangermattic.gemspec +58 -0
  19. data/lib/danger_dangermattic.rb +3 -0
  20. data/lib/danger_plugin.rb +4 -0
  21. data/lib/dangermattic/gem_version.rb +5 -0
  22. data/lib/dangermattic/plugins/android_release_checker.rb +50 -0
  23. data/lib/dangermattic/plugins/android_strings_checker.rb +31 -0
  24. data/lib/dangermattic/plugins/android_unit_test_checker.rb +187 -0
  25. data/lib/dangermattic/plugins/common/common_release_checker.rb +113 -0
  26. data/lib/dangermattic/plugins/common/git_utils.rb +166 -0
  27. data/lib/dangermattic/plugins/common/github_utils.rb +68 -0
  28. data/lib/dangermattic/plugins/common/reporter.rb +38 -0
  29. data/lib/dangermattic/plugins/ios_release_checker.rb +106 -0
  30. data/lib/dangermattic/plugins/labels_checker.rb +74 -0
  31. data/lib/dangermattic/plugins/manifest_pr_checker.rb +106 -0
  32. data/lib/dangermattic/plugins/milestone_checker.rb +98 -0
  33. data/lib/dangermattic/plugins/podfile_checker.rb +122 -0
  34. data/lib/dangermattic/plugins/pr_size_checker.rb +125 -0
  35. data/lib/dangermattic/plugins/tracks_checker.rb +72 -0
  36. data/lib/dangermattic/plugins/view_changes_checker.rb +46 -0
  37. data/spec/android_release_checker_spec.rb +93 -0
  38. data/spec/android_strings_checker_spec.rb +185 -0
  39. data/spec/android_unit_test_checker_spec.rb +343 -0
  40. data/spec/common_release_checker_spec.rb +70 -0
  41. data/spec/fixtures/android_unit_test_checker/Abc.java +7 -0
  42. data/spec/fixtures/android_unit_test_checker/AbcFeatureConfig.java +7 -0
  43. data/spec/fixtures/android_unit_test_checker/Abcdef.kt +5 -0
  44. data/spec/fixtures/android_unit_test_checker/AbcdefgViewHelper.java +7 -0
  45. data/spec/fixtures/android_unit_test_checker/AnotherViewHelper.kt +7 -0
  46. data/spec/fixtures/android_unit_test_checker/MyNewClass.java +7 -0
  47. data/spec/fixtures/android_unit_test_checker/Polygon.kt +3 -0
  48. data/spec/fixtures/android_unit_test_checker/Shape.kt +10 -0
  49. data/spec/fixtures/android_unit_test_checker/TestsINeedThem.java +5 -0
  50. data/spec/fixtures/android_unit_test_checker/TestsINeedThem.kt +7 -0
  51. data/spec/fixtures/android_unit_test_checker/TestsINeedThem2.kt +12 -0
  52. data/spec/fixtures/android_unit_test_checker/src/android/java/org/activities/MyActivity.kt +7 -0
  53. data/spec/fixtures/android_unit_test_checker/src/android/java/org/activities/MyJavaActivity.java +7 -0
  54. data/spec/fixtures/android_unit_test_checker/src/android/java/org/fragments/MyFragment.kt +6 -0
  55. data/spec/fixtures/android_unit_test_checker/src/android/java/org/fragments/MyNewJavaFragment.java +7 -0
  56. data/spec/fixtures/android_unit_test_checker/src/android/java/org/module/MyModule.java +13 -0
  57. data/spec/fixtures/android_unit_test_checker/src/android/java/org/view/ActionCardViewHolder.kt +22 -0
  58. data/spec/fixtures/android_unit_test_checker/src/android/java/org/view/MyRecyclerView.java +7 -0
  59. data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/AbcTests.java +5 -0
  60. data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/AnotherTestClass.java +7 -0
  61. data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/PolygonTest.kt +4 -0
  62. data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/TestMyNewClass.java +9 -0
  63. data/spec/fixtures/android_unit_test_checker/src/androidTest/java/org/test/ToolTest.kt +5 -0
  64. data/spec/fixtures/android_unit_test_checker/src/main/java/org/wordpress/android/widgets/NestedWebView.kt +32 -0
  65. data/spec/fixtures/android_unit_test_checker/src/main/java/org/wordpress/util/config/BloggingPromptsFeatureConfig.kt +23 -0
  66. data/spec/fixtures/android_unit_test_checker/src/test/java/org/test/TestsINeedThem.java +9 -0
  67. data/spec/github_utils_spec.rb +110 -0
  68. data/spec/ios_release_checker_spec.rb +191 -0
  69. data/spec/labels_checker_spec.rb +169 -0
  70. data/spec/manifest_pr_checker_spec.rb +140 -0
  71. data/spec/milestone_checker_spec.rb +222 -0
  72. data/spec/podfile_checker_spec.rb +595 -0
  73. data/spec/pr_size_checker_spec.rb +250 -0
  74. data/spec/spec_helper.rb +115 -0
  75. data/spec/tracks_checker_spec.rb +156 -0
  76. data/spec/view_changes_checker_spec.rb +168 -0
  77. metadata +341 -0
@@ -0,0 +1,595 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ module Danger
6
+ describe Danger::PodfileChecker do
7
+ it 'is a plugin' do
8
+ expect(described_class.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe 'with Dangerfile' do
12
+ before do
13
+ @dangerfile = testing_dangerfile
14
+ @plugin = @dangerfile.podfile_checker
15
+
16
+ allow(@plugin.git).to receive_messages(added_files: [], modified_files: [], deleted_files: [])
17
+
18
+ stub_const('GitDiffStruct', Struct.new(:type, :path, :patch))
19
+ end
20
+
21
+ context 'when checking the entire Podfile.lock file for commit references' do
22
+ it 'reports an error when there is a podfile dependency reference to a commit' do
23
+ podfile_lock_content = <<~CONTENT
24
+ PODS:
25
+ - Kingfisher (7.8.1)
26
+ - SwiftGen (6.5.1)
27
+ - SwiftLint (0.49.1)
28
+
29
+ DEPENDENCIES:
30
+ - Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, commit `c1f60c63f356d364f4284ba82961acbe7de79bcc`)
31
+ - SwiftGen (~> 6.0)
32
+ - SwiftLint (~> 0.49)
33
+
34
+ SPEC REPOS:
35
+ trunk:
36
+ - SwiftGen
37
+ - SwiftLint
38
+
39
+ EXTERNAL SOURCES:
40
+ Kingfisher:
41
+ :commit: c1f60c63f356d364f4284ba82961acbe7de79bcc
42
+ :git: https://github.com/onevcat/Kingfisher.git
43
+
44
+ CHECKOUT OPTIONS:
45
+ Kingfisher:
46
+ :commit: c1f60c63f356d364f4284ba82961acbe7de79bcc
47
+ :git: https://github.com/onevcat/Kingfisher.git
48
+
49
+ SPEC CHECKSUMS:
50
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
51
+ SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
52
+ SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
53
+
54
+ PODFILE CHECKSUM: 58bea7d9e64aa93550617dd989b9e5ceed3df3f4
55
+
56
+ COCOAPODS: 1.12.1
57
+ CONTENT
58
+
59
+ allow(File).to receive(:read).with('./Podfile.lock').and_return(podfile_lock_content)
60
+
61
+ @plugin.check_podfile_does_not_have_commit_references
62
+
63
+ expected_message = "Podfile reference(s) to a commit hash:\n```Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, commit `c1f60c63f356d364f4284ba82961acbe7de79bcc`)```"
64
+ expect(@dangerfile).to report_errors([expected_message])
65
+ end
66
+
67
+ it 'reports the right errors when there are multiple podfile dependencies referencing a commit' do
68
+ podfile_lock_content = <<~CONTENT
69
+ PODS:
70
+ - Kingfisher (7.8.1)
71
+ - SwiftGen (6.6.1)
72
+ - SwiftLint (0.50.1)
73
+
74
+ DEPENDENCIES:
75
+ - Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, commit `c1f60c63f356d364f4284ba82961acbe7de79bcc`)
76
+ - SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, commit `759cc111dfdc01dd8d66edf20ff88402b0978591`)
77
+ - SwiftLint (from `https://github.com/realm/SwiftLint.git`, commit `28a4aa2`)
78
+
79
+ EXTERNAL SOURCES:
80
+ Kingfisher:
81
+ :commit: c1f60c63f356d364f4284ba82961acbe7de79bcc
82
+ :git: https://github.com/onevcat/Kingfisher.git
83
+ SwiftGen:
84
+ :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
85
+ :git: https://github.com/SwiftGen/SwiftGen.git
86
+ SwiftLint:
87
+ :commit: 28a4aa2
88
+ :git: https://github.com/realm/SwiftLint.git
89
+
90
+ CHECKOUT OPTIONS:
91
+ Kingfisher:
92
+ :commit: c1f60c63f356d364f4284ba82961acbe7de79bcc
93
+ :git: https://github.com/onevcat/Kingfisher.git
94
+ SwiftGen:
95
+ :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
96
+ :git: https://github.com/SwiftGen/SwiftGen.git
97
+ SwiftLint:
98
+ :commit: 28a4aa2
99
+ :git: https://github.com/realm/SwiftLint.git
100
+
101
+ SPEC CHECKSUMS:
102
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
103
+ SwiftGen: 787181d7895fa2f5e7313d05de92c387010149c2
104
+ SwiftLint: 6b0cf1f4d619808dbc16e4fab064ce6fc79f090b
105
+
106
+ PODFILE CHECKSUM: 33ada736a0466cd5db78f4a568b5cdafdeeddb22
107
+
108
+ COCOAPODS: 1.12.1
109
+ CONTENT
110
+
111
+ allow(File).to receive(:read).with('./Podfile.lock').and_return(podfile_lock_content)
112
+
113
+ @plugin.check_podfile_does_not_have_commit_references
114
+
115
+ expected_message = <<~MESSAGE.chomp
116
+ Podfile reference(s) to a commit hash:
117
+ ```Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, commit `c1f60c63f356d364f4284ba82961acbe7de79bcc`)
118
+ SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, commit `759cc111dfdc01dd8d66edf20ff88402b0978591`)
119
+ SwiftLint (from `https://github.com/realm/SwiftLint.git`, commit `28a4aa2`)```
120
+ MESSAGE
121
+ expect(@dangerfile).to report_errors([expected_message])
122
+ end
123
+
124
+ it 'reports no error when there are no Podfile dependencies reference to a commit' do
125
+ podfile_lock_content = <<~CONTENT
126
+ PODS:
127
+ - SwiftGen (6.5.1)
128
+ - SwiftLint (0.49.1)
129
+
130
+ DEPENDENCIES:
131
+ - SwiftGen (~> 6.0)
132
+ - SwiftLint (~> 0.49)
133
+
134
+ SPEC REPOS:
135
+ trunk:
136
+ - SwiftGen
137
+ - SwiftLint
138
+
139
+ SPEC CHECKSUMS:
140
+ SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
141
+ SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
142
+
143
+ PODFILE CHECKSUM: 58bea7d9e64aa93550617dd989b9e5ceed3df3f4
144
+
145
+ COCOAPODS: 1.12.1
146
+ CONTENT
147
+
148
+ allow(File).to receive(:read).with('./Podfile.lock').and_return(podfile_lock_content)
149
+
150
+ @plugin.check_podfile_does_not_have_commit_references
151
+
152
+ expect(@dangerfile).to not_report
153
+ end
154
+ end
155
+
156
+ context 'when changing the Podfile.lock in a Pull Request and checking for commit references' do
157
+ it 'reports warnings when a PR adds pods pointing to a specific commit' do
158
+ podfile_path = './path/to/podfile/Podfile.lock'
159
+ allow(@plugin.git).to receive(:modified_files).and_return([podfile_path])
160
+
161
+ podfile_lock_diff = <<~PODFILE
162
+ diff --git a/Podfile.lock b/Podfile.lock
163
+ index 4a47d5fc..d57533f5 100644
164
+ --- a/Podfile.lock
165
+ +++ b/Podfile.lock
166
+ @@ -1,24 +1,38 @@
167
+ PODS:
168
+ - Kingfisher (7.8.1)
169
+ - - SwiftGen (6.6.2)
170
+ - - SwiftLint (0.51.0)
171
+ + - SwiftGen (6.6.1)
172
+ + - SwiftLint (0.50.1)
173
+
174
+ DEPENDENCIES:
175
+ - Kingfisher
176
+ - - SwiftGen
177
+ - - SwiftLint
178
+ + - SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, commit `759cc111dfdc01dd8d66edf20ff88402b0978591`)
179
+ + - SwiftLint (from `https://github.com/realm/SwiftLint.git`, commit `28a4aa2`)
180
+
181
+ SPEC REPOS:
182
+ trunk:
183
+ - Kingfisher
184
+ - - SwiftGen
185
+ - - SwiftLint
186
+ +
187
+ +EXTERNAL SOURCES:
188
+ + SwiftGen:
189
+ + :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
190
+ + :git: https://github.com/SwiftGen/SwiftGen.git
191
+ + SwiftLint:
192
+ + :commit: 28a4aa2
193
+ + :git: https://github.com/realm/SwiftLint.git
194
+ +
195
+ +CHECKOUT OPTIONS:
196
+ + SwiftGen:
197
+ + :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
198
+ + :git: https://github.com/SwiftGen/SwiftGen.git
199
+ + SwiftLint:
200
+ + :commit: 28a4aa2
201
+ + :git: https://github.com/realm/SwiftLint.git
202
+
203
+ SPEC CHECKSUMS:
204
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
205
+ - SwiftGen: 1366a7f71aeef49954ca5a63ba4bef6b0f24138c
206
+ - SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
207
+ + SwiftGen: 787181d7895fa2f5e7313d05de92c387010149c2
208
+ + SwiftLint: 6b0cf1f4d619808dbc16e4fab064ce6fc79f090b
209
+
210
+ -PODFILE CHECKSUM: 2c09a6c90634ae2e0afd8d992b96b06ae68cabc2
211
+ +PODFILE CHECKSUM: 8dc39244eeee7e5d107d943a6269ca525115094b
212
+
213
+ COCOAPODS: 1.12.1
214
+ PODFILE
215
+
216
+ diff = GitDiffStruct.new('modified', podfile_path, podfile_lock_diff)
217
+
218
+ allow(@plugin.git).to receive(:diff_for_file).with(podfile_path).and_return(diff)
219
+
220
+ @plugin.check_podfile_diff_does_not_have_commit_references
221
+
222
+ expected_warning = <<~WARNING
223
+ This PR adds a Podfile reference to a commit hash:
224
+ File `#{podfile_path}`:
225
+ ```diff
226
+ + - SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, commit `759cc111dfdc01dd8d66edf20ff88402b0978591`)
227
+ ```
228
+ WARNING
229
+
230
+ expected_warning2 = <<~WARNING
231
+ This PR adds a Podfile reference to a commit hash:
232
+ File `#{podfile_path}`:
233
+ ```diff
234
+ + - SwiftLint (from `https://github.com/realm/SwiftLint.git`, commit `28a4aa2`)
235
+ ```
236
+ WARNING
237
+
238
+ expect(@dangerfile).to report_warnings([expected_warning, expected_warning2])
239
+ end
240
+
241
+ it 'does nothing when a PR removes Podfile.lock commit references' do
242
+ podfile_path = './path/to/podfile/Podfile.lock'
243
+ allow(@plugin.git).to receive(:modified_files).and_return([podfile_path])
244
+
245
+ podfile_lock_diff = <<~PODFILE
246
+ diff --git a/Podfile.lock b/Podfile.lock
247
+ index 369b66d6..4a47d5fc 100644
248
+ --- a/Podfile.lock
249
+ +++ b/Podfile.lock
250
+ @@ -1,33 +1,24 @@
251
+ PODS:
252
+ - Kingfisher (7.8.1)
253
+ - SwiftGen (6.6.2)
254
+ - - SwiftLint (0.50.1)
255
+ + - SwiftLint (0.51.0)
256
+
257
+ DEPENDENCIES:
258
+ - - Kingfisher (>= 7.6.2, ~> 7.6)
259
+ + - Kingfisher
260
+ - SwiftGen
261
+ - - SwiftLint (from `https://github.com/realm/SwiftLint.git`, commit `28a4aa2`)
262
+ + - SwiftLint
263
+
264
+ SPEC REPOS:
265
+ trunk:
266
+ - Kingfisher
267
+ - SwiftGen
268
+ -
269
+ -EXTERNAL SOURCES:
270
+ - SwiftLint:
271
+ - :commit: 28a4aa2
272
+ - :git: https://github.com/realm/SwiftLint.git
273
+ -
274
+ -CHECKOUT OPTIONS:
275
+ - SwiftLint:
276
+ - :commit: 28a4aa2
277
+ - :git: https://github.com/realm/SwiftLint.git
278
+ + - SwiftLint
279
+
280
+ SPEC CHECKSUMS:
281
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
282
+ SwiftGen: 1366a7f71aeef49954ca5a63ba4bef6b0f24138c
283
+ - SwiftLint: 6b0cf1f4d619808dbc16e4fab064ce6fc79f090b
284
+ + SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
285
+
286
+ -PODFILE CHECKSUM: 7eea968a423d51c238de59edf2a857d882a9d762
287
+ +PODFILE CHECKSUM: 2c09a6c90634ae2e0afd8d992b96b06ae68cabc2
288
+
289
+ COCOAPODS: 1.12.1
290
+ PODFILE
291
+
292
+ diff = GitDiffStruct.new('modified', podfile_path, podfile_lock_diff)
293
+
294
+ allow(@plugin.git).to receive(:diff_for_file).with(podfile_path).and_return(diff)
295
+
296
+ @plugin.check_podfile_diff_does_not_have_commit_references
297
+
298
+ expect(@dangerfile).to not_report
299
+ end
300
+ end
301
+
302
+ context 'when checking the entire Podfile.lock file for branch references' do
303
+ it 'reports an error when there is a podfile dependency reference to a branch' do
304
+ podfile_lock_content = <<~CONTENT
305
+ PODS:
306
+ - Kingfisher (7.8.1)
307
+ - SwiftGen (6.5.1)
308
+ - SwiftLint (0.49.1)
309
+
310
+ DEPENDENCIES:
311
+ - Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, branch `main`)
312
+ - SwiftGen (~> 6.0)
313
+ - SwiftLint (~> 0.49)
314
+
315
+ SPEC REPOS:
316
+ trunk:
317
+ - SwiftGen
318
+ - SwiftLint
319
+
320
+ EXTERNAL SOURCES:
321
+ Kingfisher:
322
+ :branch: main
323
+ :git: https://github.com/onevcat/Kingfisher.git
324
+
325
+ CHECKOUT OPTIONS:
326
+ Kingfisher:
327
+ :commit: c1f60c63f356d364f4284ba82961acbe7de79bcc
328
+ :git: https://github.com/onevcat/Kingfisher.git
329
+
330
+ SPEC CHECKSUMS:
331
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
332
+ SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
333
+ SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
334
+
335
+ PODFILE CHECKSUM: 58bea7d9e64aa93550617dd989b9e5ceed3df3f4
336
+
337
+ COCOAPODS: 1.12.1
338
+ CONTENT
339
+
340
+ allow(File).to receive(:read).with('./Podfile.lock').and_return(podfile_lock_content)
341
+
342
+ @plugin.check_podfile_does_not_have_branch_references
343
+
344
+ expected_message = "Podfile reference(s) to a branch:\n```Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, branch `main`)```"
345
+ expect(@dangerfile).to report_errors([expected_message])
346
+ end
347
+
348
+ it 'reports the right errors when there are multiple podfile dependencies referencing a branch' do
349
+ podfile_lock_content = <<~CONTENT
350
+ PODS:
351
+ - Kingfisher (7.8.1)
352
+ - SwiftGen (6.6.1)
353
+ - SwiftLint (0.50.1)
354
+
355
+ DEPENDENCIES:
356
+ - Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, branch `main`)
357
+ - SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, branch `test/a-test-branch`)
358
+ - SwiftLint (from `https://github.com/realm/SwiftLint.git`, branch `feature-branch`)
359
+
360
+ EXTERNAL SOURCES:
361
+ Kingfisher:
362
+ :branch: main
363
+ :git: https://github.com/onevcat/Kingfisher.git
364
+ SwiftGen:
365
+ :branch: test/a-test-branch
366
+ :git: https://github.com/SwiftGen/SwiftGen.git
367
+ SwiftLint:
368
+ :branch: feature-branch
369
+ :git: https://github.com/realm/SwiftLint.git
370
+
371
+ CHECKOUT OPTIONS:
372
+ Kingfisher:
373
+ :commit: c1f60c63f356d364f4284ba82961acbe7de79bcc
374
+ :git: https://github.com/onevcat/Kingfisher.git
375
+ SwiftGen:
376
+ :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
377
+ :git: https://github.com/SwiftGen/SwiftGen.git
378
+ SwiftLint:
379
+ :commit: 28a4aa2
380
+ :git: https://github.com/realm/SwiftLint.git
381
+
382
+ SPEC CHECKSUMS:
383
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
384
+ SwiftGen: 787181d7895fa2f5e7313d05de92c387010149c2
385
+ SwiftLint: 6b0cf1f4d619808dbc16e4fab064ce6fc79f090b
386
+
387
+ PODFILE CHECKSUM: 33ada736a0466cd5db78f4a568b5cdafdeeddb22
388
+
389
+ COCOAPODS: 1.12.1
390
+ CONTENT
391
+
392
+ allow(File).to receive(:read).with('./Podfile.lock').and_return(podfile_lock_content)
393
+
394
+ @plugin.check_podfile_does_not_have_branch_references
395
+
396
+ expected_message = <<~MESSAGE.chomp
397
+ Podfile reference(s) to a branch:
398
+ ```Kingfisher (from `https://github.com/onevcat/Kingfisher.git`, branch `main`)
399
+ SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, branch `test/a-test-branch`)
400
+ SwiftLint (from `https://github.com/realm/SwiftLint.git`, branch `feature-branch`)```
401
+ MESSAGE
402
+ expect(@dangerfile).to report_errors([expected_message])
403
+ end
404
+
405
+ it 'reports no error when there are no Podfile dependency references to a branch' do
406
+ podfile_lock_content = <<~CONTENT
407
+ PODS:
408
+ - SwiftGen (6.5.1)
409
+ - SwiftLint (0.49.1)
410
+
411
+ DEPENDENCIES:
412
+ - SwiftGen (~> 6.0)
413
+ - SwiftLint (from `https://github.com/realm/SwiftLint.git`, commit `759cc111dfdc01dd8d66edf20ff88402b0978591`)
414
+
415
+ SPEC REPOS:
416
+ trunk:
417
+ - SwiftGen
418
+ - SwiftLint
419
+
420
+ EXTERNAL SOURCES:
421
+ SwiftLint:
422
+ :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
423
+ :git: https://github.com/realm/SwiftLint.git
424
+
425
+ CHECKOUT OPTIONS:
426
+ SwiftLint:
427
+ :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
428
+ :git: https://github.com/realm/SwiftLint.git
429
+
430
+
431
+ SPEC CHECKSUMS:
432
+ SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
433
+ SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
434
+
435
+ PODFILE CHECKSUM: 58bea7d9e64aa93550617dd989b9e5ceed3df3f4
436
+
437
+ COCOAPODS: 1.12.1
438
+ CONTENT
439
+
440
+ allow(File).to receive(:read).with('./Podfile.lock').and_return(podfile_lock_content)
441
+
442
+ @plugin.check_podfile_does_not_have_branch_references
443
+
444
+ expect(@dangerfile).to not_report
445
+ end
446
+ end
447
+
448
+ context 'when changing the Podfile.lock in a Pull Request and checking for branch references' do
449
+ it 'reports warnings when a PR adds pods pointing to a branch' do
450
+ podfile_path = './path/to/podfile/Podfile.lock'
451
+ allow(@plugin.git).to receive(:modified_files).and_return([podfile_path])
452
+
453
+ podfile_lock_diff = <<~PODFILE
454
+ diff --git a/Podfile.lock b/Podfile.lock
455
+ index 4a47d5fc..d57533f5 100644
456
+ --- a/Podfile.lock
457
+ +++ b/Podfile.lock
458
+ @@ -1,24 +1,38 @@
459
+ PODS:
460
+ - Kingfisher (7.8.1)
461
+ - - SwiftGen (6.6.2)
462
+ - - SwiftLint (0.51.0)
463
+ + - SwiftGen (6.6.1)
464
+ + - SwiftLint (0.50.1)
465
+
466
+ DEPENDENCIES:
467
+ - Kingfisher
468
+ - - SwiftGen
469
+ - - SwiftLint
470
+ + - SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, branch `trunk`)
471
+ + - SwiftLint (from `https://github.com/realm/SwiftLint.git`, branch `develop`)
472
+
473
+ SPEC REPOS:
474
+ trunk:
475
+ - Kingfisher
476
+ - - SwiftGen
477
+ - - SwiftLint
478
+ +
479
+ +EXTERNAL SOURCES:
480
+ + SwiftGen:
481
+ + :branch: trunk
482
+ + :git: https://github.com/SwiftGen/SwiftGen.git
483
+ + SwiftLint:
484
+ + :branch: develop
485
+ + :git: https://github.com/realm/SwiftLint.git
486
+ +
487
+ +CHECKOUT OPTIONS:
488
+ + SwiftGen:
489
+ + :commit: 759cc111dfdc01dd8d66edf20ff88402b0978591
490
+ + :git: https://github.com/SwiftGen/SwiftGen.git
491
+ + SwiftLint:
492
+ + :commit: 28a4aa2
493
+ + :git: https://github.com/realm/SwiftLint.git
494
+
495
+ SPEC CHECKSUMS:
496
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
497
+ - SwiftGen: 1366a7f71aeef49954ca5a63ba4bef6b0f24138c
498
+ - SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
499
+ + SwiftGen: 787181d7895fa2f5e7313d05de92c387010149c2
500
+ + SwiftLint: 6b0cf1f4d619808dbc16e4fab064ce6fc79f090b
501
+
502
+ -PODFILE CHECKSUM: 2c09a6c90634ae2e0afd8d992b96b06ae68cabc2
503
+ +PODFILE CHECKSUM: 8dc39244eeee7e5d107d943a6269ca525115094b
504
+
505
+ COCOAPODS: 1.12.1
506
+ PODFILE
507
+
508
+ diff = GitDiffStruct.new('modified', podfile_path, podfile_lock_diff)
509
+
510
+ allow(@plugin.git).to receive(:diff_for_file).with(podfile_path).and_return(diff)
511
+
512
+ @plugin.check_podfile_diff_does_not_have_branch_references
513
+
514
+ expected_warning = <<~WARNING
515
+ This PR adds a Podfile reference to a branch:
516
+ File `#{podfile_path}`:
517
+ ```diff
518
+ + - SwiftGen (from `https://github.com/SwiftGen/SwiftGen.git`, branch `trunk`)
519
+ ```
520
+ WARNING
521
+
522
+ expected_warning2 = <<~WARNING
523
+ This PR adds a Podfile reference to a branch:
524
+ File `#{podfile_path}`:
525
+ ```diff
526
+ + - SwiftLint (from `https://github.com/realm/SwiftLint.git`, branch `develop`)
527
+ ```
528
+ WARNING
529
+
530
+ expect(@dangerfile).to report_warnings([expected_warning, expected_warning2])
531
+ end
532
+
533
+ it 'does nothing when a PR removes Podfile.lock branch references' do
534
+ podfile_path = './path/to/podfile/Podfile.lock'
535
+ allow(@plugin.git).to receive(:modified_files).and_return([podfile_path])
536
+
537
+ podfile_lock_diff = <<~PODFILE
538
+ diff --git a/Podfile.lock b/Podfile.lock
539
+ index 369b66d6..4a47d5fc 100644
540
+ --- a/Podfile.lock
541
+ +++ b/Podfile.lock
542
+ @@ -1,33 +1,24 @@
543
+ PODS:
544
+ - Kingfisher (7.8.1)
545
+ - SwiftGen (6.6.2)
546
+ - - SwiftLint (0.50.1)
547
+ + - SwiftLint (0.51.0)
548
+
549
+ DEPENDENCIES:
550
+ - - Kingfisher (>= 7.6.2, ~> 7.6)
551
+ + - Kingfisher
552
+ - SwiftGen
553
+ - - SwiftLint (from `https://github.com/realm/SwiftLint.git`, branch `a-feature-branch`)
554
+ + - SwiftLint
555
+
556
+ SPEC REPOS:
557
+ trunk:
558
+ - Kingfisher
559
+ - SwiftGen
560
+ -
561
+ -EXTERNAL SOURCES:
562
+ - SwiftLint:
563
+ - :branch: a-feature-branch
564
+ - :git: https://github.com/realm/SwiftLint.git
565
+ -
566
+ -CHECKOUT OPTIONS:
567
+ - SwiftLint:
568
+ - :commit: 28a4aa2
569
+ - :git: https://github.com/realm/SwiftLint.git
570
+ + SwiftLint
571
+
572
+ SPEC CHECKSUMS:
573
+ Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
574
+ SwiftGen: 1366a7f71aeef49954ca5a63ba4bef6b0f24138c
575
+ - SwiftLint: 6b0cf1f4d619808dbc16e4fab064ce6fc79f090b
576
+ + SwiftLint: 1b7561918a19e23bfed960e40759086e70f4dba5
577
+
578
+ -PODFILE CHECKSUM: 7eea968a423d51c238de59edf2a857d882a9d762
579
+ +PODFILE CHECKSUM: 2c09a6c90634ae2e0afd8d992b96b06ae68cabc2
580
+
581
+ COCOAPODS: 1.12.1
582
+ PODFILE
583
+
584
+ diff = GitDiffStruct.new('modified', podfile_path, podfile_lock_diff)
585
+
586
+ allow(@plugin.git).to receive(:diff_for_file).with(podfile_path).and_return(diff)
587
+
588
+ @plugin.check_podfile_diff_does_not_have_branch_references
589
+
590
+ expect(@dangerfile).to not_report
591
+ end
592
+ end
593
+ end
594
+ end
595
+ end