danger-dangermattic 1.2.3 → 1.2.4

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: 20a5e57d91cc796def3533c72a3a674ea494356982fa78015ccc016ce19b61c9
4
- data.tar.gz: 376d14c60ba7aadc6107b4a6de9a40dc968a658a0fe326aaad208866bf4583e9
3
+ metadata.gz: ad580440b78f9c9bd16790cb679c1a38a2ab32f22e9936f12e88398cef578a9f
4
+ data.tar.gz: ca179653e7759647821a2653f659ff04d56d38ce725993a31454f493180f1ffa
5
5
  SHA512:
6
- metadata.gz: 10ed4e5e5772cc7631470fe591c79004a5a237ddaffb6c708204d4823a204f15cc068530c5e8b05bc0f150577037f93bcb675a93ae47eb4c71a5d1b245e658fe
7
- data.tar.gz: 06c85ea386f290706300db05c3a07439859bda94d025a6dd9bab9068786a2040b247c09c8d1314c31f44c09d07e5aded50434d3092c55aeca1ff9fce2aad78d2
6
+ metadata.gz: a30553a0ff163ac72fa5492fc6db0047bf8e7569241a8cdce1de71bf8e8224703a271ca32afe0947ba61a751bcfbb048ed744c22e527513a2d0ae26adbd40ef0
7
+ data.tar.gz: f7657a8e47f25a63169a0e965a067792df749ee3fd8468199744dff509083f8b292da4475bef161bd38edcfe3acbf1c747e7a929d24136b3cd59bce0130e408c
data/CHANGELOG.md CHANGED
@@ -20,6 +20,12 @@ _None_
20
20
 
21
21
  _None_
22
22
 
23
+ ## 1.2.4
24
+
25
+ ### Internal Changes
26
+
27
+ - `pr_size_checker` and `manifest_pr_checker`: optimize performance for large PRs [#103]
28
+
23
29
  ## 1.2.3
24
30
 
25
31
  ### Bug Fixes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-dangermattic (1.2.3)
4
+ danger-dangermattic (1.2.4)
5
5
  danger (~> 9.4)
6
6
  danger-plugin-api (~> 1.0)
7
7
  danger-rubocop (~> 0.13)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dangermattic
4
- VERSION = '1.2.3'
4
+ VERSION = '1.2.4'
5
5
  end
@@ -115,13 +115,19 @@ module Danger
115
115
  private
116
116
 
117
117
  def check_manifest_lock_updated(file_name:, lock_file_name:, instruction:, report_type: :warning)
118
+ all_files = git_utils.all_changed_files
119
+
118
120
  # Find all the modified manifest files
119
- manifest_modified_files = git_utils.all_changed_files.select { |f| File.basename(f) == file_name }
121
+ manifest_modified_files = all_files.select { |f| File.basename(f) == file_name }
122
+
123
+ # Build a hash mapping directory -> set of basenames for O(1) lookup
124
+ files_by_dir = all_files.group_by { |f| File.dirname(f) }
125
+ .transform_values { |files| files.to_set { |f| File.basename(f) } }
120
126
 
121
127
  # For each manifest file, check if the corresponding lockfile (in the same dir) was also modified
122
128
  manifest_modified_files.each do |manifest_file|
123
- lockfile_modified = git_utils.all_changed_files.any? { |f| File.dirname(f) == File.dirname(manifest_file) && File.basename(f) == lock_file_name }
124
- next if lockfile_modified
129
+ manifest_dir = File.dirname(manifest_file)
130
+ next if files_by_dir[manifest_dir]&.include?(lock_file_name)
125
131
 
126
132
  message = format(MESSAGE, manifest_file, lock_file_name, instruction)
127
133
  reporter.report(message: message, type: report_type)
@@ -129,11 +135,10 @@ module Danger
129
135
  end
130
136
 
131
137
  def check_manifest_lock_updated_strict(manifest_path:, manifest_lock_path:, instruction:, report_type: :warning)
132
- manifest_modified = git_utils.all_changed_files.include?(manifest_path)
133
- return unless manifest_modified
138
+ all_files_set = git_utils.all_changed_files.to_set
134
139
 
135
- lockfile_modified = git_utils.all_changed_files.include?(manifest_lock_path)
136
- return if lockfile_modified
140
+ return unless all_files_set.include?(manifest_path)
141
+ return if all_files_set.include?(manifest_lock_path)
137
142
 
138
143
  message = format(MESSAGE, manifest_path, File.basename(manifest_lock_path), instruction)
139
144
  reporter.report(message: message, type: report_type)
@@ -76,13 +76,12 @@ module Danger
76
76
  def insertions_size(file_selector: nil)
77
77
  return danger.git.insertions unless file_selector
78
78
 
79
- filtered_files = git_utils.all_changed_files.select(&file_selector)
79
+ # Only check added and modified files - deleted files have 0 insertions
80
+ filtered_files = git_utils.added_and_modified_files.select(&file_selector)
80
81
 
81
82
  filtered_files.sum do |file|
82
- # stats for a file in the GitHub API might be nil, making `info_for_file()` crash
83
- next 0 if danger.git.diff.stats[:files][file].nil?
84
-
85
- danger.git.info_for_file(file)&.[](:insertions).to_i
83
+ # Use cached stats directly instead of calling info_for_file for each file
84
+ danger.git.diff.stats[:files][file]&.[](:insertions).to_i
86
85
  end
87
86
  end
88
87
 
@@ -97,10 +96,8 @@ module Danger
97
96
  filtered_files = git_utils.all_changed_files.select(&file_selector)
98
97
 
99
98
  filtered_files.sum do |file|
100
- # stats for a file in the GitHub API might be nil, making `info_for_file()` crash
101
- next 0 if danger.git.diff.stats[:files][file].nil?
102
-
103
- danger.git.info_for_file(file)&.[](:deletions).to_i
99
+ # Use cached stats directly instead of calling info_for_file for each file
100
+ danger.git.diff.stats[:files][file]&.[](:deletions).to_i
104
101
  end
105
102
  end
106
103
 
@@ -115,10 +112,11 @@ module Danger
115
112
  filtered_files = git_utils.all_changed_files.select(&file_selector)
116
113
 
117
114
  filtered_files.sum do |file|
118
- # stats for a file in the GitHub API might be nil, making `info_for_file()` crash
119
- next 0 if danger.git.diff.stats[:files][file].nil?
115
+ # Use cached stats directly instead of calling info_for_file for each file
116
+ stats = danger.git.diff.stats[:files][file]
117
+ next 0 unless stats
120
118
 
121
- danger.git.info_for_file(file)&.[](:deletions).to_i + danger.git.info_for_file(file)&.[](:insertions).to_i
119
+ stats[:deletions].to_i + stats[:insertions].to_i
122
120
  end
123
121
  end
124
122
  end
@@ -146,19 +146,20 @@ module Danger
146
146
  allow(@plugin.git).to receive_messages(added_files: [added_config, added_file], modified_files: [modified_file1, modified_file2, added_test_file, modified_strings], deleted_files: [deleted_file1, deleted_test_file, deleted_strings, deleted_file2])
147
147
 
148
148
  allow(@plugin.git).to receive(:diff).and_return(instance_double(Git::Diff))
149
- expected_files = { added_test_file => {}, added_config => {}, added_file => {}, modified_file1 => {}, modified_file2 => {}, modified_strings => {}, deleted_file1 => {}, deleted_file2 => {}, deleted_test_file => {}, deleted_strings => {} }
149
+ # Populate stats hash directly with insertions/deletions data for the optimized code path
150
+ expected_files = {
151
+ added_test_file => { insertions: 201 },
152
+ added_config => { insertions: 311 },
153
+ added_file => { insertions: 13 },
154
+ modified_file1 => { insertions: 127, deletions: 159 },
155
+ modified_file2 => { insertions: 43, deletions: 37 },
156
+ modified_strings => { insertions: 432, deletions: 297 },
157
+ deleted_file1 => { deletions: 246 },
158
+ deleted_file2 => { deletions: 493 },
159
+ deleted_test_file => { deletions: 222 },
160
+ deleted_strings => { deletions: 593 }
161
+ }
150
162
  allow(@plugin.git.diff).to receive(:stats).and_return({ files: expected_files })
151
-
152
- allow(@plugin.git).to receive(:info_for_file).with(added_test_file).and_return({ insertions: 201 })
153
- allow(@plugin.git).to receive(:info_for_file).with(added_config).and_return({ insertions: 311 })
154
- allow(@plugin.git).to receive(:info_for_file).with(added_file).and_return({ insertions: 13 })
155
- allow(@plugin.git).to receive(:info_for_file).with(modified_file1).and_return({ insertions: 127, deletions: 159 })
156
- allow(@plugin.git).to receive(:info_for_file).with(modified_file2).and_return({ insertions: 43, deletions: 37 })
157
- allow(@plugin.git).to receive(:info_for_file).with(modified_strings).and_return({ insertions: 432, deletions: 297 })
158
- allow(@plugin.git).to receive(:info_for_file).with(deleted_file1).and_return({ deletions: 246 })
159
- allow(@plugin.git).to receive(:info_for_file).with(deleted_file2).and_return({ deletions: 493 })
160
- allow(@plugin.git).to receive(:info_for_file).with(deleted_test_file).and_return({ deletions: 222 })
161
- allow(@plugin.git).to receive(:info_for_file).with(deleted_strings).and_return({ deletions: 593 })
162
163
  end
163
164
  end
164
165
 
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.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-25 00:00:00.000000000 Z
11
+ date: 2025-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger