dependabot-bundler 0.137.2 → 0.138.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/v1/build +2 -1
  3. data/helpers/v1/run.rb +16 -0
  4. data/helpers/v2/.gitignore +8 -0
  5. data/helpers/v2/Gemfile +12 -0
  6. data/helpers/v2/build +25 -0
  7. data/helpers/v2/lib/functions.rb +189 -0
  8. data/helpers/v2/lib/functions/conflicting_dependency_resolver.rb +86 -0
  9. data/helpers/v2/lib/functions/dependency_source.rb +86 -0
  10. data/helpers/v2/lib/functions/file_parser.rb +106 -0
  11. data/helpers/v2/lib/functions/force_updater.rb +167 -0
  12. data/helpers/v2/lib/functions/lockfile_updater.rb +224 -0
  13. data/helpers/v2/lib/functions/version_resolver.rb +140 -0
  14. data/helpers/v2/monkey_patches/definition_bundler_version_patch.rb +15 -0
  15. data/helpers/v2/monkey_patches/definition_ruby_version_patch.rb +20 -0
  16. data/helpers/v2/monkey_patches/git_source_patch.rb +62 -0
  17. data/helpers/v2/run.rb +44 -0
  18. data/helpers/v2/spec/functions/conflicting_dependency_resolver_spec.rb +133 -0
  19. data/helpers/v2/spec/functions/dependency_source_spec.rb +185 -0
  20. data/helpers/v2/spec/functions/file_parser_spec.rb +142 -0
  21. data/helpers/v2/spec/functions/version_resolver_spec.rb +97 -0
  22. data/helpers/v2/spec/functions_spec.rb +22 -0
  23. data/helpers/v2/spec/native_spec_helper.rb +49 -0
  24. data/helpers/v2/spec/shared_contexts.rb +60 -0
  25. data/lib/dependabot/bundler/file_parser.rb +13 -1
  26. data/lib/dependabot/bundler/file_updater.rb +3 -2
  27. data/lib/dependabot/bundler/file_updater/lockfile_updater.rb +4 -3
  28. data/lib/dependabot/bundler/file_updater/requirement_replacer.rb +4 -2
  29. data/lib/dependabot/bundler/helpers.rb +15 -3
  30. data/lib/dependabot/bundler/native_helpers.rb +5 -0
  31. data/lib/dependabot/bundler/update_checker.rb +12 -6
  32. data/lib/dependabot/bundler/update_checker/conflicting_dependency_resolver.rb +5 -2
  33. data/lib/dependabot/bundler/update_checker/force_updater.rb +6 -3
  34. data/lib/dependabot/bundler/update_checker/latest_version_finder.rb +6 -3
  35. data/lib/dependabot/bundler/update_checker/latest_version_finder/dependency_source.rb +5 -3
  36. data/lib/dependabot/bundler/update_checker/requirements_updater.rb +2 -2
  37. data/lib/dependabot/bundler/update_checker/shared_bundler_helpers.rb +0 -4
  38. data/lib/dependabot/bundler/update_checker/version_resolver.rb +8 -4
  39. metadata +25 -4
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "native_spec_helper"
4
+ require "shared_contexts"
5
+
6
+ RSpec.describe Functions::FileParser do
7
+ include_context "in a temporary bundler directory"
8
+
9
+ let(:dependency_source) do
10
+ described_class.new(
11
+ lockfile_name: "Gemfile.lock"
12
+ )
13
+ end
14
+
15
+ let(:project_name) { "gemfile" }
16
+
17
+ describe "#parsed_gemfile" do
18
+ subject(:parsed_gemfile) do
19
+ in_tmp_folder do
20
+ dependency_source.parsed_gemfile(gemfile_name: "Gemfile")
21
+ end
22
+ end
23
+
24
+ it "parses gemfile" do
25
+ parsed_gemfile = [
26
+ {
27
+ groups: [:default],
28
+ name: "business",
29
+ requirement: Gem::Requirement.new("~> 1.4.0"),
30
+ source: nil,
31
+ type: :runtime
32
+ },
33
+ {
34
+ groups: [:default],
35
+ name: "statesman",
36
+ requirement: Gem::Requirement.new("~> 1.2.0"),
37
+ source: nil,
38
+ type: :runtime
39
+ }
40
+ ]
41
+ is_expected.to eq(parsed_gemfile)
42
+ end
43
+
44
+ context "with a git source" do
45
+ let(:project_name) { "git_source" }
46
+
47
+ it "parses gemfile" do
48
+ parsed_gemfile = [
49
+ {
50
+ groups: [:default],
51
+ name: "business",
52
+ requirement: Gem::Requirement.new("~> 1.6.0"),
53
+ source: {
54
+ branch: "master",
55
+ ref: "a1b78a9",
56
+ type: "git",
57
+ url: "git@github.com:gocardless/business"
58
+ },
59
+ type: :runtime
60
+ },
61
+ {
62
+ groups: [:default],
63
+ name: "statesman",
64
+ requirement: Gem::Requirement.new("~> 1.2.0"),
65
+ source: nil,
66
+ type: :runtime
67
+ },
68
+ {
69
+ groups: [:default],
70
+ name: "prius",
71
+ requirement: Gem::Requirement.new(">= 0"),
72
+ source: {
73
+ branch: "master",
74
+ ref: "master",
75
+ type: "git",
76
+ url: "https://github.com/gocardless/prius"
77
+ },
78
+ type: :runtime
79
+ },
80
+ {
81
+ groups: [:default],
82
+ name: "que",
83
+ requirement: Gem::Requirement.new(">= 0"),
84
+ source: {
85
+ branch: "master",
86
+ ref: "v0.11.6",
87
+ type: "git",
88
+ url: "git@github.com:chanks/que"
89
+ },
90
+ type: :runtime
91
+ },
92
+ {
93
+ groups: [:default],
94
+ name: "uk_phone_numbers",
95
+ requirement: Gem::Requirement.new(">= 0"),
96
+ source: {
97
+ branch: "master",
98
+ ref: "master",
99
+ type: "git",
100
+ url: "http://github.com/gocardless/uk_phone_numbers"
101
+ },
102
+ type: :runtime
103
+ }
104
+ ]
105
+ is_expected.to eq(parsed_gemfile)
106
+ end
107
+ end
108
+ end
109
+
110
+ describe "#parsed_gemspec" do
111
+ let!(:gemspec_fixture) do
112
+ fixture("ruby", "gemspecs", "exact")
113
+ end
114
+
115
+ subject(:parsed_gemspec) do
116
+ in_tmp_folder do |tmp_path|
117
+ File.write(File.join(tmp_path, "test.gemspec"), gemspec_fixture)
118
+ dependency_source.parsed_gemspec(gemspec_name: "test.gemspec")
119
+ end
120
+ end
121
+
122
+ it "parses gemspec" do
123
+ parsed_gemspec = [
124
+ {
125
+ groups: nil,
126
+ name: "business",
127
+ requirement: Gem::Requirement.new("= 1.0.0"),
128
+ source: nil,
129
+ type: :runtime
130
+ },
131
+ {
132
+ groups: nil,
133
+ name: "statesman",
134
+ requirement: Gem::Requirement.new("= 1.0.0"),
135
+ source: nil,
136
+ type: :runtime
137
+ }
138
+ ]
139
+ is_expected.to eq(parsed_gemspec)
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "native_spec_helper"
4
+ require "shared_contexts"
5
+
6
+ RSpec.describe Functions::VersionResolver do
7
+ include_context "in a temporary bundler directory"
8
+ include_context "stub rubygems compact index"
9
+
10
+ let(:version_resolver) do
11
+ described_class.new(
12
+ dependency_name: dependency_name,
13
+ dependency_requirements: dependency_requirements,
14
+ gemfile_name: "Gemfile",
15
+ lockfile_name: "Gemfile.lock"
16
+ )
17
+ end
18
+
19
+ let(:dependency_name) { "business" }
20
+ let(:dependency_requirements) do
21
+ [{
22
+ file: "Gemfile",
23
+ requirement: requirement_string,
24
+ groups: [],
25
+ source: source
26
+ }]
27
+ end
28
+ let(:source) { nil }
29
+
30
+ let(:rubygems_url) { "https://index.rubygems.org/api/v1/" }
31
+ let(:old_index_url) { rubygems_url + "dependencies" }
32
+
33
+ describe "#version_details" do
34
+ subject do
35
+ in_tmp_folder { version_resolver.version_details }
36
+ end
37
+
38
+ let(:project_name) { "gemfile" }
39
+ let(:requirement_string) { " >= 0" }
40
+
41
+ its([:version]) { is_expected.to eq(Gem::Version.new("1.4.0")) }
42
+ its([:fetcher]) { is_expected.to eq("Bundler::Fetcher::CompactIndex") }
43
+
44
+ context "with a private gemserver source" do
45
+ include_context "stub rubygems compact index"
46
+
47
+ let(:project_name) { "specified_source" }
48
+ let(:requirement_string) { ">= 0" }
49
+
50
+ before do
51
+ gemfury_url = "https://repo.fury.io/greysteil/"
52
+ gemfury_deps_url = gemfury_url + "api/v1/dependencies"
53
+
54
+ stub_request(:get, gemfury_url + "versions").
55
+ to_return(status: 200, body: fixture("ruby", "gemfury-index"))
56
+ stub_request(:get, gemfury_url + "info/business").to_return(status: 404)
57
+ stub_request(:get, gemfury_deps_url).to_return(status: 200)
58
+ stub_request(:get, gemfury_deps_url + "?gems=business,statesman").
59
+ to_return(status: 200, body: fixture("ruby", "gemfury_response"))
60
+ stub_request(:get, gemfury_deps_url + "?gems=business").
61
+ to_return(status: 200, body: fixture("ruby", "gemfury_response"))
62
+ stub_request(:get, gemfury_deps_url + "?gems=statesman").
63
+ to_return(status: 200, body: fixture("ruby", "gemfury_response"))
64
+ end
65
+
66
+ its([:version]) { is_expected.to eq(Gem::Version.new("1.9.0")) }
67
+ its([:fetcher]) { is_expected.to eq("Bundler::Fetcher::Dependency") }
68
+ end
69
+
70
+ context "with a git source" do
71
+ let(:project_name) { "git_source" }
72
+
73
+ its([:version]) { is_expected.to eq(Gem::Version.new("1.6.0")) }
74
+ its([:fetcher]) { is_expected.to be_nil }
75
+ end
76
+
77
+ context "when Bundler's compact index is down" do
78
+ before do
79
+ stub_request(:get, "https://index.rubygems.org/versions").
80
+ to_return(status: 500, body: "We'll be back soon")
81
+ stub_request(:get, "https://index.rubygems.org/info/public_suffix").
82
+ to_return(status: 500, body: "We'll be back soon")
83
+ stub_request(:get, old_index_url).to_return(status: 200)
84
+ stub_request(:get, old_index_url + "?gems=business,statesman").
85
+ to_return(
86
+ status: 200,
87
+ body: fixture("ruby",
88
+ "rubygems_responses",
89
+ "dependencies-default-gemfile")
90
+ )
91
+ end
92
+
93
+ its([:version]) { is_expected.to eq(Gem::Version.new("1.4.0")) }
94
+ its([:fetcher]) { is_expected.to eq("Bundler::Fetcher::Dependency") }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "native_spec_helper"
4
+
5
+ RSpec.describe Functions do
6
+ # Verify v1 method signatures are exist, but raise as NYI
7
+ {
8
+ jfrog_source: %i(dir gemfile_name credentials using_bundler2)
9
+ }.each do |function, kwargs|
10
+ describe "::#{function}" do
11
+ let(:args) do
12
+ kwargs.inject({}) do |args, keyword|
13
+ args.merge({ keyword => anything })
14
+ end
15
+ end
16
+
17
+ it "raises a NYI" do
18
+ expect { Functions.send(function, **args) }.to raise_error(Functions::NotImplementedError)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/its"
4
+ require "webmock/rspec"
5
+ require "byebug"
6
+
7
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
8
+ $LOAD_PATH.unshift(File.expand_path("../monkey_patches", __dir__))
9
+
10
+ # Bundler monkey patches
11
+ require "definition_ruby_version_patch"
12
+ require "definition_bundler_version_patch"
13
+ require "git_source_patch"
14
+
15
+ require "functions"
16
+
17
+ RSpec.configure do |config|
18
+ config.color = true
19
+ config.order = :rand
20
+ config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true }
21
+ config.raise_errors_for_deprecations!
22
+ end
23
+
24
+ # Duplicated in lib/dependabot/bundler/file_updater/lockfile_updater.rb
25
+ # TODO: Stop sanitizing the lockfile once we have bundler 2 installed
26
+ LOCKFILE_ENDING = /(?<ending>\s*(?:RUBY VERSION|BUNDLED WITH).*)/m.freeze
27
+
28
+ def project_dependency_files(project)
29
+ project_path = File.expand_path(File.join("../../spec/fixtures/projects/bundler1", project))
30
+ Dir.chdir(project_path) do
31
+ # NOTE: Include dotfiles (e.g. .npmrc)
32
+ files = Dir.glob("**/*", File::FNM_DOTMATCH)
33
+ files = files.select { |f| File.file?(f) }
34
+ files.map do |filename|
35
+ content = File.read(filename)
36
+ if filename == "Gemfile.lock"
37
+ content = content.gsub(LOCKFILE_ENDING, "")
38
+ end
39
+ {
40
+ name: filename,
41
+ content: content
42
+ }
43
+ end
44
+ end
45
+ end
46
+
47
+ def fixture(*name)
48
+ File.read(File.join("../../spec/fixtures", File.join(*name)))
49
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tmpdir"
4
+ require "bundler/compact_index_client"
5
+ require "bundler/compact_index_client/updater"
6
+
7
+ TMP_DIR_PATH = File.expand_path("../tmp", __dir__)
8
+
9
+ RSpec.shared_context "in a temporary bundler directory" do
10
+ let(:project_name) { "gemfile" }
11
+
12
+ let(:tmp_path) do
13
+ Dir.mkdir(TMP_DIR_PATH) unless Dir.exist?(TMP_DIR_PATH)
14
+ dir = Dir.mktmpdir("native_helper_spec_", TMP_DIR_PATH)
15
+ Pathname.new(dir).expand_path
16
+ end
17
+
18
+ before do
19
+ project_dependency_files(project_name).each do |file|
20
+ File.write(File.join(tmp_path, file[:name]), file[:content])
21
+ end
22
+ end
23
+
24
+ def in_tmp_folder(&block)
25
+ Dir.chdir(tmp_path, &block)
26
+ end
27
+ end
28
+
29
+ RSpec.shared_context "without caching rubygems" do
30
+ before do
31
+ # Stub Bundler to stop it using a cached versions of Rubygems
32
+ allow_any_instance_of(Bundler::CompactIndexClient::Updater).
33
+ to receive(:etag_for).and_return("")
34
+ end
35
+ end
36
+
37
+ RSpec.shared_context "stub rubygems compact index" do
38
+ include_context "without caching rubygems"
39
+
40
+ before do
41
+ # Stub the Rubygems index
42
+ stub_request(:get, "https://index.rubygems.org/versions").
43
+ to_return(
44
+ status: 200,
45
+ body: fixture("ruby", "rubygems_responses", "index")
46
+ )
47
+
48
+ # Stub the Rubygems response for each dependency we have a fixture for
49
+ fixtures =
50
+ Dir[File.join("../../spec", "fixtures", "ruby", "rubygems_responses", "info-*")]
51
+ fixtures.each do |path|
52
+ dep_name = path.split("/").last.gsub("info-", "")
53
+ stub_request(:get, "https://index.rubygems.org/info/#{dep_name}").
54
+ to_return(
55
+ status: 200,
56
+ body: fixture("ruby", "rubygems_responses", "info-#{dep_name}")
57
+ )
58
+ end
59
+ end
60
+ end
@@ -23,6 +23,7 @@ module Dependabot
23
23
  dependency_set += gemspec_dependencies
24
24
  dependency_set += lockfile_dependencies
25
25
  check_external_code(dependency_set.dependencies)
26
+ instrument_package_manager_version
26
27
  dependency_set.dependencies
27
28
  end
28
29
 
@@ -42,6 +43,17 @@ module Dependabot
42
43
  end
43
44
  end
44
45
 
46
+ def instrument_package_manager_version
47
+ version = Helpers.detected_bundler_version(lockfile)
48
+ Dependabot.instrument(
49
+ Notifications::FILE_PARSER_PACKAGE_MANAGER_VERSION_PARSED,
50
+ ecosystem: "bundler",
51
+ package_managers: {
52
+ "bundler" => version
53
+ }
54
+ )
55
+ end
56
+
45
57
  def gemfile_dependencies
46
58
  dependencies = DependencySet.new
47
59
 
@@ -301,7 +313,7 @@ module Dependabot
301
313
  end
302
314
 
303
315
  def bundler_version
304
- @bundler_version ||= Helpers.bundler_version(lockfile)
316
+ @bundler_version ||= Helpers.bundler_version(lockfile, options: options)
305
317
  end
306
318
  end
307
319
  end
@@ -151,7 +151,8 @@ module Dependabot
151
151
  dependencies: dependencies,
152
152
  dependency_files: dependency_files,
153
153
  repo_contents_path: repo_contents_path,
154
- credentials: credentials
154
+ credentials: credentials,
155
+ options: options
155
156
  ).updated_lockfile_content
156
157
  end
157
158
 
@@ -162,7 +163,7 @@ module Dependabot
162
163
  end
163
164
 
164
165
  def bundler_version
165
- @bundler_version ||= Helpers.bundler_version(lockfile)
166
+ @bundler_version ||= Helpers.bundler_version(lockfile, options: options)
166
167
  end
167
168
  end
168
169
  end
@@ -33,11 +33,12 @@ module Dependabot
33
33
  end
34
34
 
35
35
  def initialize(dependencies:, dependency_files:,
36
- repo_contents_path: nil, credentials:)
36
+ repo_contents_path: nil, credentials:, options:)
37
37
  @dependencies = dependencies
38
38
  @dependency_files = dependency_files
39
39
  @repo_contents_path = repo_contents_path
40
40
  @credentials = credentials
41
+ @options = options
41
42
  end
42
43
 
43
44
  def updated_lockfile_content
@@ -54,7 +55,7 @@ module Dependabot
54
55
  private
55
56
 
56
57
  attr_reader :dependencies, :dependency_files, :repo_contents_path,
57
- :credentials
58
+ :credentials, :options
58
59
 
59
60
  def build_updated_lockfile
60
61
  base_dir = dependency_files.first.directory
@@ -304,7 +305,7 @@ module Dependabot
304
305
  end
305
306
 
306
307
  def bundler_version
307
- @bundler_version ||= Helpers.bundler_version(lockfile)
308
+ @bundler_version ||= Helpers.bundler_version(lockfile, options: options)
308
309
  end
309
310
  end
310
311
  end