dependabot-core 0.88.3 → 0.89.0

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/helpers/test/run.rb +3 -0
  4. data/lib/dependabot/file_fetchers.rb +0 -2
  5. data/lib/dependabot/file_parsers.rb +0 -2
  6. data/lib/dependabot/file_updaters.rb +0 -2
  7. data/lib/dependabot/file_updaters/go/dep/lockfile_updater.rb +11 -8
  8. data/lib/dependabot/metadata_finders.rb +0 -2
  9. data/lib/dependabot/shared_helpers.rb +47 -24
  10. data/lib/dependabot/update_checkers.rb +0 -2
  11. data/lib/dependabot/update_checkers/go/dep/version_resolver.rb +11 -7
  12. data/lib/dependabot/utils.rb +0 -4
  13. data/lib/dependabot/version.rb +1 -1
  14. metadata +2 -25
  15. data/helpers/php/.php_cs +0 -34
  16. data/helpers/php/bin/run.php +0 -84
  17. data/helpers/php/composer.json +0 -14
  18. data/helpers/php/composer.lock +0 -1528
  19. data/helpers/php/composer.phar +0 -0
  20. data/helpers/php/setup.sh +0 -4
  21. data/helpers/php/src/DependabotInstallationManager.php +0 -61
  22. data/helpers/php/src/DependabotPluginManager.php +0 -23
  23. data/helpers/php/src/ExceptionIO.php +0 -25
  24. data/helpers/php/src/Hasher.php +0 -21
  25. data/helpers/php/src/UpdateChecker.php +0 -123
  26. data/helpers/php/src/Updater.php +0 -97
  27. data/lib/dependabot/file_fetchers/php/composer.rb +0 -131
  28. data/lib/dependabot/file_parsers/php/composer.rb +0 -177
  29. data/lib/dependabot/file_updaters/php/composer.rb +0 -78
  30. data/lib/dependabot/file_updaters/php/composer/lockfile_updater.rb +0 -269
  31. data/lib/dependabot/file_updaters/php/composer/manifest_updater.rb +0 -70
  32. data/lib/dependabot/metadata_finders/php/composer.rb +0 -66
  33. data/lib/dependabot/update_checkers/php/composer.rb +0 -175
  34. data/lib/dependabot/update_checkers/php/composer/requirements_updater.rb +0 -258
  35. data/lib/dependabot/update_checkers/php/composer/version_resolver.rb +0 -216
  36. data/lib/dependabot/utils/php/requirement.rb +0 -97
  37. data/lib/dependabot/utils/php/version.rb +0 -24
@@ -1,216 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dependabot/shared_helpers"
4
- require "dependabot/update_checkers/php/composer"
5
- require "dependabot/utils/php/version"
6
-
7
- module Dependabot
8
- module UpdateCheckers
9
- module Php
10
- class Composer
11
- class VersionResolver
12
- VERSION_REGEX = /[0-9]+(?:\.[A-Za-z0-9\-_]+)*/.freeze
13
- SOURCE_TIMED_OUT_REGEX =
14
- /The "(?<url>[^"]+packages\.json)".*timed out/.freeze
15
-
16
- def initialize(credentials:, dependency:, dependency_files:,
17
- requirements_to_unlock:, latest_allowable_version:)
18
- @credentials = credentials
19
- @dependency = dependency
20
- @dependency_files = dependency_files
21
- @requirements_to_unlock = requirements_to_unlock
22
- @latest_allowable_version = latest_allowable_version
23
- end
24
-
25
- def latest_resolvable_version
26
- @latest_resolvable_version ||= fetch_latest_resolvable_version
27
- end
28
-
29
- private
30
-
31
- attr_reader :credentials, :dependency, :dependency_files,
32
- :requirements_to_unlock, :latest_allowable_version
33
-
34
- def fetch_latest_resolvable_version
35
- version = fetch_latest_resolvable_version_string
36
- return if version.nil?
37
- return unless Utils::Php::Version.correct?(version)
38
-
39
- Utils::Php::Version.new(version)
40
- end
41
-
42
- def fetch_latest_resolvable_version_string
43
- base_directory = dependency_files.first.directory
44
- SharedHelpers.in_a_temporary_directory(base_directory) do
45
- File.write("composer.json", prepared_composer_json_content)
46
- File.write("composer.lock", lockfile.content) if lockfile
47
-
48
- run_update_checker
49
- end
50
- rescue SharedHelpers::HelperSubprocessFailed => error
51
- retry_count ||= 0
52
- retry_count += 1
53
- retry if retry_count < 2 && error.message.include?("404 Not Found")
54
- retry if retry_count < 2 && error.message.include?("timed out")
55
- handle_composer_errors(error)
56
- end
57
-
58
- def run_update_checker
59
- SharedHelpers.with_git_configured(credentials: credentials) do
60
- SharedHelpers.run_helper_subprocess(
61
- command: "php -d memory_limit=-1 #{php_helper_path}",
62
- function: "get_latest_resolvable_version",
63
- args: [
64
- Dir.pwd,
65
- dependency.name.downcase,
66
- git_credentials,
67
- registry_credentials
68
- ]
69
- )
70
- end
71
- end
72
-
73
- def prepared_composer_json_content
74
- content = composer_file.content
75
-
76
- content.gsub(
77
- /"#{Regexp.escape(dependency.name)}"\s*:\s*".*"/,
78
- %("#{dependency.name}": "#{updated_version_requirement_string}")
79
- )
80
- end
81
-
82
- def updated_version_requirement_string
83
- lower_bound =
84
- if requirements_to_unlock == :none
85
- dependency.requirements.first&.fetch(:requirement) || ">= 0"
86
- elsif dependency.version
87
- ">= #{dependency.version}"
88
- else
89
- version_for_requirement =
90
- dependency.requirements.map { |r| r[:requirement] }.compact.
91
- reject { |req_string| req_string.start_with?("<") }.
92
- select { |req_string| req_string.match?(VERSION_REGEX) }.
93
- map { |req_string| req_string.match(VERSION_REGEX) }.
94
- select { |version| Gem::Version.correct?(version) }.
95
- max_by { |version| Gem::Version.new(version) }
96
-
97
- ">= #{version_for_requirement || 0}"
98
- end
99
-
100
- # Add the latest_allowable_version as an upper bound. This means
101
- # ignore conditions are considered when checking for the latest
102
- # resolvable version.
103
- #
104
- # NOTE: This isn't perfect. If v2.x is ignored and v3 is out but
105
- # unresolvable then the `latest_allowable_version` will be v3, and
106
- # we won't be ignoring v2.x releases like we should be.
107
- return lower_bound unless latest_allowable_version
108
-
109
- lower_bound + ", <= #{latest_allowable_version}"
110
- end
111
-
112
- # rubocop:disable Metrics/PerceivedComplexity
113
- # rubocop:disable Metrics/AbcSize
114
- # rubocop:disable Metrics/CyclomaticComplexity
115
- # rubocop:disable Metrics/MethodLength
116
- def handle_composer_errors(error)
117
- if error.message.start_with?("Failed to execute git clone")
118
- dependency_url =
119
- error.message.match(/--mirror '(?<url>.*?)'/).
120
- named_captures.fetch("url")
121
- raise Dependabot::GitDependenciesNotReachable, dependency_url
122
- elsif error.message.start_with?("Failed to clone")
123
- dependency_url =
124
- error.message.match(/Failed to clone (?<url>.*?) via/).
125
- named_captures.fetch("url")
126
- raise Dependabot::GitDependenciesNotReachable, dependency_url
127
- elsif error.message.start_with?("Could not parse version")
128
- raise Dependabot::DependencyFileNotResolvable, error.message
129
- elsif error.message.include?("requested PHP extension")
130
- extensions = error.message.scan(/\sext\-.*?\s/).map(&:strip).uniq
131
- msg = "Dependabot's installed extensions didn't match those "\
132
- "required by your application.\n\n"\
133
- "Please add the following extensions to the platform "\
134
- "config in your composer.json to allow Dependabot to run: "\
135
- "#{extensions.join(', ')}.\n\n"\
136
- "The full error raised was:\n\n#{error.message}"
137
- raise Dependabot::DependencyFileNotResolvable, msg
138
- elsif error.message.include?("package requires php") ||
139
- error.message.include?("cannot require itself")
140
- raise Dependabot::DependencyFileNotResolvable, error.message
141
- elsif error.message.include?("No driver found to handle VCS") &&
142
- !error.message.include?("@") && !error.message.include?("://")
143
- msg = "Dependabot detected a VCS requirement with a local path, "\
144
- "rather than a URL. Dependabot does not support this "\
145
- "setup.\n\nThe underlying error was:\n\n#{error.message}"
146
- raise Dependabot::DependencyFileNotResolvable, msg
147
- elsif error.message.include?("requirements could not be resolved")
148
- # We should raise a Dependabot::DependencyFileNotResolvable error
149
- # here, but can't confidently distinguish between cases where we
150
- # can't install and cases where we can't update. For now, we
151
- # therefore just ignore the dependency.
152
- nil
153
- elsif error.message.include?("URL required authentication") ||
154
- error.message.include?("403 Forbidden")
155
- source =
156
- error.message.match(%r{https?://(?<source>[^/]+)/}).
157
- named_captures.fetch("source")
158
- raise Dependabot::PrivateSourceAuthenticationFailure, source
159
- elsif error.message.match?(SOURCE_TIMED_OUT_REGEX)
160
- url = error.message.match(SOURCE_TIMED_OUT_REGEX).
161
- named_captures.fetch("url")
162
- raise if url.include?("packagist.org")
163
-
164
- source = url.gsub(%r{/packages.json$}, "")
165
- raise Dependabot::PrivateSourceTimedOut, source
166
- elsif error.message.start_with?("Allowed memory size")
167
- raise Dependabot::OutOfMemory
168
- elsif error.message.start_with?("Package not found in updated") &&
169
- !dependency.top_level?
170
- # If we can't find the dependency in the composer.lock after an
171
- # update, but it was originally a sub-dependency, it's because the
172
- # dependency is no longer required and is just cruft in the
173
- # composer.json. In this case we just ignore the dependency.
174
- nil
175
- elsif error.message.include?("stefandoorn/sitemap-plugin-1.0.0.0")
176
- # We get a recurring error when attempting to update this repo
177
- # which doesn't recur locally and we can't figure out how to fix!
178
- #
179
- # Package is not installed: stefandoorn/sitemap-plugin-1.0.0.0
180
- nil
181
- else
182
- raise error
183
- end
184
- end
185
- # rubocop:enable Metrics/PerceivedComplexity
186
- # rubocop:enable Metrics/AbcSize
187
- # rubocop:enable Metrics/CyclomaticComplexity
188
- # rubocop:enable Metrics/MethodLength
189
-
190
- def php_helper_path
191
- project_root = File.join(File.dirname(__FILE__), "../../../../..")
192
- File.join(project_root, "helpers/php/bin/run.php")
193
- end
194
-
195
- def composer_file
196
- @composer_file ||=
197
- dependency_files.find { |f| f.name == "composer.json" }
198
- end
199
-
200
- def lockfile
201
- @lockfile ||=
202
- dependency_files.find { |f| f.name == "composer.lock" }
203
- end
204
-
205
- def git_credentials
206
- credentials.select { |cred| cred["type"] == "git_source" }
207
- end
208
-
209
- def registry_credentials
210
- credentials.select { |cred| cred["type"] == "composer_repository" }
211
- end
212
- end
213
- end
214
- end
215
- end
216
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "dependabot/utils/php/version"
4
-
5
- module Dependabot
6
- module Utils
7
- module Php
8
- class Requirement < Gem::Requirement
9
- AND_SEPARATOR =
10
- /(?<=[a-zA-Z0-9*])(?<!\sas)[\s,]+(?![\s,]*[|-]|as)/.freeze
11
- OR_SEPARATOR = /(?<=[a-zA-Z0-9*])[\s,]*\|\|?\s*/.freeze
12
-
13
- def self.parse(obj)
14
- new_obj = obj.gsub(/@\w+/, "").gsub(/[a-z0-9\-_\.]*\sas\s+/i, "")
15
- super(new_obj)
16
- end
17
-
18
- # Returns an array of requirements. At least one requirement from the
19
- # returned array must be satisfied for a version to be valid.
20
- def self.requirements_array(requirement_string)
21
- requirement_string.strip.split(OR_SEPARATOR).map do |req_string|
22
- new(req_string)
23
- end
24
- end
25
-
26
- def initialize(*requirements)
27
- requirements =
28
- requirements.flatten.
29
- flat_map { |req_string| req_string.split(AND_SEPARATOR) }.
30
- flat_map { |req| convert_php_constraint_to_ruby_constraint(req) }
31
-
32
- super(requirements)
33
- end
34
-
35
- private
36
-
37
- # rubocop:disable Metrics/PerceivedComplexity
38
- def convert_php_constraint_to_ruby_constraint(req_string)
39
- req_string = req_string.gsub(/v(?=\d)/, "")
40
-
41
- # Return an unlikely version if a dev requirement is specified. This
42
- # ensures that the dev-requirement doesn't match anything.
43
- return "0-dev-branch-match" if req_string.strip.start_with?("dev-")
44
-
45
- if req_string.start_with?("*") then ">= 0"
46
- elsif req_string.include?("*") then convert_wildcard_req(req_string)
47
- elsif req_string.match?(/^~[^>]/) then convert_tilde_req(req_string)
48
- elsif req_string.start_with?("^") then convert_caret_req(req_string)
49
- elsif req_string.match?(/\s-\s/) then convert_hyphen_req(req_string)
50
- else req_string
51
- end
52
- end
53
- # rubocop:enable Metrics/PerceivedComplexity
54
-
55
- def convert_wildcard_req(req_string)
56
- version = req_string.gsub(/^~/, "").gsub(/(?:\.|^)\*/, "")
57
- "~> #{version}.0"
58
- end
59
-
60
- def convert_tilde_req(req_string)
61
- version = req_string.gsub(/^~/, "")
62
- "~> #{version}"
63
- end
64
-
65
- def convert_caret_req(req_string)
66
- version = req_string.gsub(/^\^/, "")
67
- parts = version.split(".")
68
- first_non_zero = parts.find { |d| d != "0" }
69
- first_non_zero_index =
70
- first_non_zero ? parts.index(first_non_zero) : parts.count - 1
71
- upper_bound = parts.map.with_index do |part, i|
72
- if i < first_non_zero_index then part
73
- elsif i == first_non_zero_index then (part.to_i + 1).to_s
74
- else 0
75
- end
76
- end.join(".")
77
-
78
- [">= #{version}", "< #{upper_bound}"]
79
- end
80
-
81
- def convert_hyphen_req(req_string)
82
- req_string = req_string
83
- lower_bound, upper_bound = req_string.split(/\s+-\s+/)
84
- if upper_bound.split(".").count < 3
85
- upper_bound_parts = upper_bound.split(".")
86
- upper_bound_parts[-1] = (upper_bound_parts[-1].to_i + 1).to_s
87
- upper_bound = upper_bound_parts.join(".")
88
-
89
- [">= #{lower_bound}", "< #{upper_bound}"]
90
- else
91
- [">= #{lower_bound}", "<= #{upper_bound}"]
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubygems_version_patch"
4
-
5
- # PHP pre-release versions use 1.0.1-rc1 syntax, which Gem::Version
6
- # converts into 1.0.1.pre.rc1. We override the `to_s` method to stop that
7
- # alteration.
8
-
9
- module Dependabot
10
- module Utils
11
- module Php
12
- class Version < Gem::Version
13
- def initialize(version)
14
- @version_string = version.to_s
15
- super
16
- end
17
-
18
- def to_s
19
- @version_string
20
- end
21
- end
22
- end
23
- end
24
- end