dependabot-bundler 0.118.16 → 0.119.0.beta1

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: c0bbc086a9909c34ab34f8a001e6f64902cfb631e3d9206c4e1c03c6c82e992b
4
- data.tar.gz: 3d76afd7d9fded083bd3b09b8aa254235b7d284870876624a3ca46ebc29f1486
3
+ metadata.gz: b80518519da7e1a3143ede4da6e1a7dd4df2f926b7fa6a9e8e7afbaab88a578a
4
+ data.tar.gz: b3192111c15926ee5ce6bff535654c89f5e6b6f9e4bae4782d65093362b867d5
5
5
  SHA512:
6
- metadata.gz: 9bf4c6a45f132f0fba4db457010c48f8abd8378f90457db87bf41e1ca75bb0f97c8cc9ae9a3941369583bc28a211518d2fb9967728812ba408e3a908dc2c3892
7
- data.tar.gz: e6fc9e39f83abfd64d22002b3ce3a8885b014c6d8527ce8104e11c6bf8c3ffbd3453248ad5a00d712433312c3ab4e318f98ecd77e43685407a40677d81f73db6
6
+ metadata.gz: 99e0ae19b66182dda191654dde09ee6c18453c9ae5a6a3c67e3666335b595cd4ee12b3562e651b7f9a8edfd326266014b14667e97d2a57be3c5f71b876fc9c12
7
+ data.tar.gz: a48f701129cf5eaf3c44215fe32964a4a27e4c1198909b1e3e910635deba3d219f482227c7f84d64b62a96f1faa69bf40a70ab31295e5209a38a128736bd5559
@@ -118,7 +118,8 @@ module Dependabot
118
118
 
119
119
  def parsed_gemfile
120
120
  @parsed_gemfile ||=
121
- SharedHelpers.in_a_temporary_directory(base_directory) do
121
+ SharedHelpers.in_a_temporary_repo_directory(base_directory,
122
+ repo_contents_path) do
122
123
  write_temporary_dependency_files
123
124
 
124
125
  SharedHelpers.in_a_forked_process do
@@ -150,7 +151,8 @@ module Dependabot
150
151
  def parsed_gemspec(file)
151
152
  @parsed_gemspecs ||= {}
152
153
  @parsed_gemspecs[file.name] ||=
153
- SharedHelpers.in_a_temporary_directory(base_directory) do
154
+ SharedHelpers.in_a_temporary_repo_directory(base_directory,
155
+ repo_contents_path) do
154
156
  [file, *imported_ruby_files].each do |f|
155
157
  path = f.name
156
158
  FileUtils.mkdir_p(Pathname.new(path).dirname)
@@ -13,6 +13,7 @@ require "dependabot/git_commit_checker"
13
13
  module Dependabot
14
14
  module Bundler
15
15
  class FileUpdater
16
+ # rubocop:disable Metrics/ClassLength
16
17
  class LockfileUpdater
17
18
  require_relative "gemfile_updater"
18
19
  require_relative "gemspec_updater"
@@ -41,9 +42,11 @@ module Dependabot
41
42
  ]
42
43
  end
43
44
 
44
- def initialize(dependencies:, dependency_files:, credentials:)
45
+ def initialize(dependencies:, dependency_files:,
46
+ repo_contents_path: nil, credentials:)
45
47
  @dependencies = dependencies
46
48
  @dependency_files = dependency_files
49
+ @repo_contents_path = repo_contents_path
47
50
  @credentials = credentials
48
51
  end
49
52
 
@@ -62,12 +65,16 @@ module Dependabot
62
65
 
63
66
  private
64
67
 
65
- attr_reader :dependencies, :dependency_files, :credentials
68
+ attr_reader :dependencies, :dependency_files, :repo_contents_path,
69
+ :credentials
66
70
 
67
71
  def build_updated_lockfile
68
72
  base_dir = dependency_files.first.directory
69
73
  lockfile_body =
70
- SharedHelpers.in_a_temporary_directory(base_dir) do |tmp_dir|
74
+ SharedHelpers.in_a_temporary_repo_directory(
75
+ base_dir,
76
+ repo_contents_path
77
+ ) do |tmp_dir|
71
78
  write_temporary_dependency_files
72
79
 
73
80
  SharedHelpers.in_a_forked_process do
@@ -122,6 +129,7 @@ module Dependabot
122
129
  end
123
130
  end
124
131
 
132
+ # rubocop:disable Metrics/PerceivedComplexity
125
133
  def generate_lockfile
126
134
  dependencies_to_unlock = dependencies.map(&:name)
127
135
 
@@ -139,6 +147,8 @@ module Dependabot
139
147
  end
140
148
  end
141
149
 
150
+ cache_vendored_gems(definition) if ::Bundler.app_cache.exist?
151
+
142
152
  definition.to_lock
143
153
  rescue ::Bundler::GemNotFound => e
144
154
  unlock_yanked_gem(dependencies_to_unlock, e) && retry
@@ -152,6 +162,78 @@ module Dependabot
152
162
  retry
153
163
  end
154
164
  end
165
+ # rubocop:enable Metrics/PerceivedComplexity
166
+
167
+ def cache_vendored_gems(definition)
168
+ # Dependencies that have been unlocked for the update (including
169
+ # sub-dependencies)
170
+ unlocked_gems = definition.instance_variable_get(:@unlock).
171
+ fetch(:gems)
172
+ bundler_opts = {
173
+ cache_all_platforms: true,
174
+ no_prune: true
175
+ }
176
+
177
+ ::Bundler.settings.temporary(**bundler_opts) do
178
+ # Fetch and cache gems on all platforms without pruning
179
+ ::Bundler::Runtime.new(nil, definition).cache
180
+
181
+ # Only prune unlocked gems (the original implementation is in
182
+ # Bundler::Runtime)
183
+ cache_path = ::Bundler.app_cache
184
+ resolve = definition.resolve
185
+ prune_gem_cache(resolve, cache_path, unlocked_gems)
186
+ prune_git_and_path_cache(resolve, cache_path)
187
+ end
188
+ end
189
+
190
+ # Copied from Bundler::Runtime: Modified to only prune gems that have
191
+ # been unlocked
192
+ def prune_gem_cache(resolve, cache_path, unlocked_gems)
193
+ cached_gems = Dir["#{cache_path}/*.gem"]
194
+
195
+ outdated_gems = cached_gems.reject do |path|
196
+ spec = ::Bundler.rubygems.spec_from_gem path
197
+
198
+ !unlocked_gems.include?(spec.name) || resolve.any? do |s|
199
+ s.name == spec.name && s.version == spec.version &&
200
+ !s.source.is_a?(::Bundler::Source::Git)
201
+ end
202
+ end
203
+
204
+ return unless outdated_gems.any?
205
+
206
+ puts "Removing outdated .gem files from #{cache_path}"
207
+
208
+ outdated_gems.each do |path|
209
+ puts " * #{File.basename(path)}"
210
+ File.delete(path)
211
+ end
212
+ end
213
+
214
+ # Copied from Bundler::Runtime
215
+ def prune_git_and_path_cache(resolve, cache_path)
216
+ cached_git_and_path = Dir["#{cache_path}/*/.bundlecache"]
217
+
218
+ outdated_git_and_path = cached_git_and_path.reject do |path|
219
+ name = File.basename(File.dirname(path))
220
+
221
+ resolve.any? do |s|
222
+ s.source.respond_to?(:app_cache_dirname) &&
223
+ s.source.app_cache_dirname == name
224
+ end
225
+ end
226
+
227
+ return unless outdated_git_and_path.any?
228
+
229
+ puts "Removing outdated git and path gems from #{cache_path}"
230
+
231
+ outdated_git_and_path.each do |path|
232
+ path = File.dirname(path)
233
+ puts " * #{File.basename(path)}"
234
+ FileUtils.rm_rf(path)
235
+ end
236
+ end
155
237
 
156
238
  def unlock_yanked_gem(dependencies_to_unlock, error)
157
239
  raise unless error.message.match?(GEM_NOT_FOUND_ERROR_REGEX)
@@ -453,6 +535,7 @@ module Dependabot
453
535
  lockfile.content.match?(/BUNDLED WITH\s+2/m)
454
536
  end
455
537
  end
538
+ # rubocop:enable Metrics/ClassLength
456
539
  end
457
540
  end
458
541
  end
@@ -51,11 +51,57 @@ module Dependabot
51
51
  end
52
52
 
53
53
  check_updated_files(updated_files)
54
+
55
+ base_dir = updated_files.first.directory
56
+ updated_vendor_cache_files(base_directory: base_dir).each do |file|
57
+ updated_files << file
58
+ end
59
+
54
60
  updated_files
55
61
  end
56
62
 
57
63
  private
58
64
 
65
+ # Dynamically fetch the vendor cache folder from bundler
66
+ def vendor_cache_dir
67
+ return @vendor_cache_dir if defined?(@vendor_cache_dir)
68
+
69
+ @vendor_cache_dir =
70
+ SharedHelpers.in_a_forked_process do
71
+ # Set the path for path gemspec correctly
72
+ ::Bundler.instance_variable_set(:@root, repo_contents_path)
73
+ ::Bundler.app_cache
74
+ end
75
+ end
76
+
77
+ # Returns changed files in the vendor/cache folder
78
+ #
79
+ # @param base_directory [String] Update config base directory
80
+ # @return [Array<Dependabot::DependencyFile>]
81
+ def updated_vendor_cache_files(base_directory:)
82
+ return [] unless repo_contents_path && vendor_cache_dir
83
+
84
+ Dir.chdir(repo_contents_path) do
85
+ relative_dir = vendor_cache_dir.sub("#{repo_contents_path}/", "")
86
+ status = SharedHelpers.run_shell_command(
87
+ "git status --porcelain=v1 #{relative_dir}"
88
+ )
89
+ changed_paths = status.split("\n").map { |l| l.split(" ") }
90
+ changed_paths.map do |type, path|
91
+ deleted = type == "D"
92
+ encoding = Dependabot::DependencyFile::ContentEncoding::BASE64
93
+ encoded_content = Base64.encode64(File.read(path)) unless deleted
94
+ Dependabot::DependencyFile.new(
95
+ name: path,
96
+ content: encoded_content,
97
+ directory: base_directory,
98
+ deleted: deleted,
99
+ content_encoding: encoding
100
+ )
101
+ end
102
+ end
103
+ end
104
+
59
105
  def check_required_files
60
106
  file_names = dependency_files.map(&:name)
61
107
 
@@ -116,6 +162,7 @@ module Dependabot
116
162
  LockfileUpdater.new(
117
163
  dependencies: dependencies,
118
164
  dependency_files: dependency_files,
165
+ repo_contents_path: repo_contents_path,
119
166
  credentials: credentials
120
167
  ).updated_lockfile_content
121
168
  end
@@ -15,11 +15,13 @@ module Dependabot
15
15
  module Bundler
16
16
  class UpdateChecker
17
17
  class ForceUpdater
18
- def initialize(dependency:, dependency_files:, credentials:,
19
- target_version:, requirements_update_strategy:,
18
+ def initialize(dependency:, dependency_files:, repo_contents_path: nil,
19
+ credentials:, target_version:,
20
+ requirements_update_strategy:,
20
21
  update_multiple_dependencies: true)
21
22
  @dependency = dependency
22
23
  @dependency_files = dependency_files
24
+ @repo_contents_path = repo_contents_path
23
25
  @credentials = credentials
24
26
  @target_version = target_version
25
27
  @requirements_update_strategy = requirements_update_strategy
@@ -32,8 +34,8 @@ module Dependabot
32
34
 
33
35
  private
34
36
 
35
- attr_reader :dependency, :dependency_files, :credentials,
36
- :target_version, :requirements_update_strategy
37
+ attr_reader :dependency, :dependency_files, :repo_contents_path,
38
+ :credentials, :target_version, :requirements_update_strategy
37
39
 
38
40
  def update_multiple_dependencies?
39
41
  @update_multiple_dependencies
@@ -74,7 +76,8 @@ module Dependabot
74
76
 
75
77
  def in_a_temporary_bundler_context
76
78
  base_directory = dependency_files.first.directory
77
- SharedHelpers.in_a_temporary_directory(base_directory) do
79
+ SharedHelpers.in_a_temporary_repo_directory(base_directory,
80
+ repo_contents_path) do
78
81
  write_temporary_dependency_files
79
82
 
80
83
  SharedHelpers.in_a_forked_process do
@@ -18,11 +18,12 @@ module Dependabot
18
18
  require_relative "shared_bundler_helpers"
19
19
  include SharedBundlerHelpers
20
20
 
21
- def initialize(dependency:, dependency_files:, credentials:,
22
- ignored_versions:, raise_on_ignored: false,
21
+ def initialize(dependency:, dependency_files:, repo_contents_path: nil,
22
+ credentials:, ignored_versions:, raise_on_ignored: false,
23
23
  security_advisories:)
24
24
  @dependency = dependency
25
25
  @dependency_files = dependency_files
26
+ @repo_contents_path = repo_contents_path
26
27
  @credentials = credentials
27
28
  @ignored_versions = ignored_versions
28
29
  @raise_on_ignored = raise_on_ignored
@@ -39,8 +40,8 @@ module Dependabot
39
40
 
40
41
  private
41
42
 
42
- attr_reader :dependency, :dependency_files, :credentials,
43
- :ignored_versions, :security_advisories
43
+ attr_reader :dependency, :dependency_files, :repo_contents_path,
44
+ :credentials, :ignored_versions, :security_advisories
44
45
 
45
46
  def fetch_latest_version_details
46
47
  if dependency_source.is_a?(::Bundler::Source::Git)
@@ -29,14 +29,16 @@ module Dependabot
29
29
  Bundler::Fetcher::FallbackError
30
30
  ).freeze
31
31
 
32
- attr_reader :dependency_files, :credentials
32
+ attr_reader :dependency_files, :repo_contents_path, :credentials
33
33
 
34
34
  #########################
35
35
  # Bundler context setup #
36
36
  #########################
37
37
 
38
38
  def in_a_temporary_bundler_context(error_handling: true)
39
- SharedHelpers.in_a_temporary_directory(base_directory) do |tmp_dir|
39
+ SharedHelpers.
40
+ in_a_temporary_repo_directory(base_directory,
41
+ repo_contents_path) do |tmp_dir|
40
42
  write_temporary_dependency_files
41
43
 
42
44
  SharedHelpers.in_a_forked_process do
@@ -24,7 +24,7 @@ module Dependabot
24
24
  GEM_NOT_FOUND_ERROR_REGEX = /locked to (?<name>[^\s]+) \(/.freeze
25
25
 
26
26
  def initialize(dependency:, unprepared_dependency_files:,
27
- credentials:, ignored_versions:,
27
+ repo_contents_path: nil, credentials:, ignored_versions:,
28
28
  raise_on_ignored: false,
29
29
  replacement_git_pin: nil, remove_git_source: false,
30
30
  unlock_requirement: true,
@@ -32,6 +32,7 @@ module Dependabot
32
32
  @dependency = dependency
33
33
  @unprepared_dependency_files = unprepared_dependency_files
34
34
  @credentials = credentials
35
+ @repo_contents_path = repo_contents_path
35
36
  @ignored_versions = ignored_versions
36
37
  @raise_on_ignored = raise_on_ignored
37
38
  @replacement_git_pin = replacement_git_pin
@@ -47,9 +48,9 @@ module Dependabot
47
48
 
48
49
  private
49
50
 
50
- attr_reader :dependency, :unprepared_dependency_files, :credentials,
51
- :ignored_versions, :replacement_git_pin,
52
- :latest_allowable_version
51
+ attr_reader :dependency, :unprepared_dependency_files,
52
+ :repo_contents_path, :credentials, :ignored_versions,
53
+ :replacement_git_pin, :latest_allowable_version
53
54
 
54
55
  def remove_git_source?
55
56
  @remove_git_source
@@ -268,6 +269,7 @@ module Dependabot
268
269
  LatestVersionFinder.new(
269
270
  dependency: dependency,
270
271
  dependency_files: dependency_files,
272
+ repo_contents_path: repo_contents_path,
271
273
  credentials: credentials,
272
274
  ignored_versions: ignored_versions,
273
275
  raise_on_ignored: @raise_on_ignored,
@@ -145,6 +145,7 @@ module Dependabot
145
145
  ForceUpdater.new(
146
146
  dependency: dependency,
147
147
  dependency_files: dependency_files,
148
+ repo_contents_path: repo_contents_path,
148
149
  credentials: credentials,
149
150
  target_version: version,
150
151
  requirements_update_strategy: requirements_update_strategy,
@@ -165,6 +166,7 @@ module Dependabot
165
166
  VersionResolver.new(
166
167
  dependency: dependency,
167
168
  unprepared_dependency_files: dependency_files,
169
+ repo_contents_path: repo_contents_path,
168
170
  credentials: credentials,
169
171
  ignored_versions: ignored_versions,
170
172
  raise_on_ignored: raise_on_ignored,
@@ -325,6 +327,7 @@ module Dependabot
325
327
  ForceUpdater.new(
326
328
  dependency: dependency,
327
329
  dependency_files: dependency_files,
330
+ repo_contents_path: repo_contents_path,
328
331
  credentials: credentials,
329
332
  target_version: latest_version,
330
333
  requirements_update_strategy: requirements_update_strategy
@@ -347,6 +350,7 @@ module Dependabot
347
350
  VersionResolver.new(
348
351
  dependency: dependency,
349
352
  unprepared_dependency_files: dependency_files,
353
+ repo_contents_path: repo_contents_path,
350
354
  credentials: credentials,
351
355
  ignored_versions: ignored_versions,
352
356
  raise_on_ignored: raise_on_ignored,
@@ -369,6 +373,7 @@ module Dependabot
369
373
  LatestVersionFinder.new(
370
374
  dependency: dependency,
371
375
  dependency_files: prepared_dependency_files,
376
+ repo_contents_path: repo_contents_path,
372
377
  credentials: credentials,
373
378
  ignored_versions: ignored_versions,
374
379
  raise_on_ignored: raise_on_ignored,
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.118.16
4
+ version: 0.119.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-08-20 00:00:00.000000000 Z
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.118.16
19
+ version: 0.119.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.118.16
26
+ version: 0.119.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +179,7 @@ homepage: https://github.com/dependabot/dependabot-core
179
179
  licenses:
180
180
  - Nonstandard
181
181
  metadata: {}
182
- post_install_message:
182
+ post_install_message:
183
183
  rdoc_options: []
184
184
  require_paths:
185
185
  - lib
@@ -194,8 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - !ruby/object:Gem::Version
195
195
  version: 2.5.0
196
196
  requirements: []
197
- rubygems_version: 3.1.2
198
- signing_key:
197
+ rubygems_version: 3.1.4
198
+ signing_key:
199
199
  specification_version: 4
200
200
  summary: Ruby (bundler) support for dependabot
201
201
  test_files: []