dependabot-common 0.141.1 → 0.143.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 125bcfa28ff5774ae8ebcf4dfdd228a5fb7324e746e98701892f27bd481a18f3
4
- data.tar.gz: 1b3653a868e6619ae74976b5cfec7b1ff8d185514399c8b8a08e4e5593ce3d4c
3
+ metadata.gz: 82f605b43ae5d4332b84cd8bca628b5621e518f26dfab590b680401b17fb2282
4
+ data.tar.gz: 6913eb7ddb27d985b3aa28ad9e40f239f0efbfeb4f22400a45d9755a9b566287
5
5
  SHA512:
6
- metadata.gz: 16bb56c69370cf3ca755c858c7ce34f104e04990052d6f7a48d2c0119188aefa61dc6845cbff5a22a6db49b394ea644f491b568c29c0f2c9e8cb35158de62a00
7
- data.tar.gz: 328a0ba98d46967993375283c789de522ec0d2347c8833b50206033bc330f238ef57f7f398e749213c49f96dd4bc234dd123604355a0f3dd9e837909a6b08e08
6
+ metadata.gz: 1114b083a13b2416c8be267f37bc0c2f3ac21cabf97613c879419d21cd506271972efb3d7519b1af54b092ca7b46542e53f2b6edaae3ebd342ed51c885d065cc
7
+ data.tar.gz: 26f6b95978c3d8492486687cf275285eee383a9b12328e06d8477ddb2707affeacd498abfa7436bfe1f5226e7d485ac84e391a1797408386c2d75ab28ec2184d
@@ -201,9 +201,11 @@ module Dependabot
201
201
  }
202
202
  ]
203
203
 
204
- post(source.api_endpoint + source.organization + "/" + source.project +
205
- "/_apis/git/repositories/" + source.unscoped_repo +
206
- "/refs?api-version=5.0", content.to_json)
204
+ response = post(source.api_endpoint + source.organization + "/" + source.project +
205
+ "/_apis/git/repositories/" + source.unscoped_repo +
206
+ "/refs?api-version=5.0", content.to_json)
207
+
208
+ JSON.parse(response.body).fetch("value").first
207
209
  end
208
210
  # rubocop:enable Metrics/ParameterLists
209
211
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ module Config
5
+ class InvalidConfigError < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dependabot/config/update_config"
4
+
5
+ module Dependabot
6
+ module Config
7
+ # Configuration for the repository, a parsed dependabot.yaml.
8
+ class File
9
+ attr_reader :updates, :registries
10
+
11
+ def initialize(updates:, registries: nil)
12
+ @updates = updates || []
13
+ @registries = registries || []
14
+ end
15
+
16
+ def update_config(package_manager, directory: nil, target_branch: nil)
17
+ dir = directory || "/"
18
+ package_ecosystem = PACKAGE_MANAGER_LOOKUP.invert.fetch(package_manager)
19
+ cfg = updates.find do |u|
20
+ u[:"package-ecosystem"] == package_ecosystem && u[:directory] == dir &&
21
+ (target_branch.nil? || u[:"target-branch"] == target_branch)
22
+ end
23
+ Dependabot::Config::UpdateConfig.new(
24
+ ignore_conditions: ignore_conditions(cfg),
25
+ commit_message_options: commit_message_options(cfg)
26
+ )
27
+ end
28
+
29
+ # Parse the YAML config file
30
+ def self.parse(config)
31
+ parsed = YAML.safe_load(config, symbolize_names: true)
32
+ version = parsed[:version]
33
+ raise InvalidConfigError, "invalid version #{version}" if version && version != 2
34
+
35
+ File.new(updates: parsed[:updates], registries: parsed[:registries])
36
+ end
37
+
38
+ private
39
+
40
+ PACKAGE_MANAGER_LOOKUP = {
41
+ "bundler" => "bundler",
42
+ "cargo" => "cargo",
43
+ "composer" => "composer",
44
+ "docker" => "docker",
45
+ "elm" => "elm",
46
+ "github-actions" => "github_actions",
47
+ "gitsubmodule" => "submodules",
48
+ "gomod" => "go_modules",
49
+ "gradle" => "gradle",
50
+ "maven" => "maven",
51
+ "mix" => "hex",
52
+ "nuget" => "nuget",
53
+ "npm" => "npm_and_yarn",
54
+ "pip" => "pip",
55
+ "terraform" => "terraform"
56
+ }.freeze
57
+
58
+ UPDATE_TYPE_LOOKUP = {
59
+ "version-update:semver-patch" => :ignore_patch_versions,
60
+ "version-update:semver-minor" => :ignore_minor_versions,
61
+ "version-update:semver-major" => :ignore_major_versions
62
+ }.freeze
63
+
64
+ def ignore_conditions(cfg)
65
+ ignores = cfg&.dig(:ignore) || []
66
+ ignores.map do |ic|
67
+ update_types = ic[:"update-types"]&.
68
+ map { |t| UPDATE_TYPE_LOOKUP[t.downcase.strip] }&.
69
+ compact
70
+ Dependabot::Config::IgnoreCondition.new(
71
+ dependency_name: ic[:"dependency-name"],
72
+ versions: ic[:versions],
73
+ update_types: update_types
74
+ )
75
+ end
76
+ end
77
+
78
+ def commit_message_options(cfg)
79
+ commit_message = cfg&.dig(:"commit-message") || {}
80
+ Dependabot::Config::UpdateConfig::CommitMessageOptions.new(
81
+ prefix: commit_message[:prefix],
82
+ prefix_development: commit_message[:"prefix-development"],
83
+ include: commit_message[:include]
84
+ )
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dependabot/file_fetchers/base"
4
+ require "dependabot/config/file"
5
+
6
+ module Dependabot
7
+ module Config
8
+ class FileFetcher < Dependabot::FileFetchers::Base
9
+ CONFIG_FILE_PATHS = %w(.github/dependabot.yml .github/dependabot.yaml).freeze
10
+
11
+ def self.required_files_in?(filenames)
12
+ CONFIG_FILE_PATHS.any? { |file| filenames.include?(file) }
13
+ end
14
+
15
+ def self.required_files_message
16
+ "Repo must contain either a #{CONFIG_FILE_PATHS.join(' or a ')} file"
17
+ end
18
+
19
+ def config_file
20
+ @config_file ||= files.first
21
+ end
22
+
23
+ private
24
+
25
+ def fetch_files
26
+ fetched_files = []
27
+
28
+ CONFIG_FILE_PATHS.each do |file|
29
+ fn = Pathname.new("/#{file}").relative_path_from(directory)
30
+
31
+ begin
32
+ config_file = fetch_file_from_host(fn)
33
+ if config_file
34
+ fetched_files << config_file
35
+ break
36
+ end
37
+ rescue Dependabot::DependencyFileNotFound
38
+ next
39
+ end
40
+ end
41
+
42
+ unless self.class.required_files_in?(fetched_files.map(&:name))
43
+ raise Dependabot::DependencyFileNotFound, self.class.required_files_message
44
+ end
45
+
46
+ fetched_files
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dependabot
4
+ module Config
5
+ # Filters versions that should not be considered for dependency updates
6
+ class IgnoreCondition
7
+ UPDATE_TYPES = %i(
8
+ ignore_major_versions
9
+ ignore_minor_versions
10
+ ignore_patch_versions
11
+ ).freeze
12
+
13
+ ALL_VERSIONS = ">= 0"
14
+
15
+ attr_reader :dependency_name, :versions, :update_types
16
+ def initialize(dependency_name:, versions: nil, update_types: nil)
17
+ @dependency_name = dependency_name
18
+ @versions = versions || []
19
+ @update_types = update_types || []
20
+ end
21
+
22
+ def ignored_versions(dependency)
23
+ return [ALL_VERSIONS] if @versions.empty? && @update_types.empty?
24
+
25
+ versions_by_type(dependency) + @versions
26
+ end
27
+
28
+ private
29
+
30
+ def versions_by_type(dependency)
31
+ @update_types.flat_map do |t|
32
+ case t
33
+ when :ignore_patch_versions
34
+ ignore_patch(dependency.version)
35
+ when :ignore_minor_versions
36
+ ignore_minor(dependency.version)
37
+ when :ignore_major_versions
38
+ ignore_major(dependency.version)
39
+ else
40
+ []
41
+ end
42
+ end.compact
43
+ end
44
+
45
+ def ignore_patch(version)
46
+ parts = version.split(".")
47
+ return [] unless parts.size > 2
48
+
49
+ lower_parts = parts.first(2) + ["a"]
50
+ upper_parts = parts.first(2)
51
+ upper_parts[1] = upper_parts[1].to_i + 1
52
+ lower_bound = ">= #{lower_parts.join('.')}"
53
+ upper_bound = "< #{upper_parts.join('.')}"
54
+ ["#{lower_bound}, #{upper_bound}"]
55
+ end
56
+
57
+ def ignore_minor(version)
58
+ parts = version.split(".")
59
+ return [] if parts.size < 2
60
+
61
+ if Gem::Version.correct?(version)
62
+ lower_parts = parts.first(2) + ["a"]
63
+ upper_parts = parts.first(1)
64
+ lower_parts[1] = lower_parts[1].to_i + 1
65
+ upper_parts[0] = upper_parts[0].to_i + 1
66
+ else
67
+ lower_parts = parts.first(1) + ["a"]
68
+ upper_parts = parts.first(1)
69
+ begin
70
+ upper_parts[0] = Integer(upper_parts[0]) + 1
71
+ rescue ArgumentError
72
+ upper_parts.push(999_999)
73
+ end
74
+ end
75
+
76
+ lower_bound = ">= #{lower_parts.join('.')}"
77
+ upper_bound = "< #{upper_parts.join('.')}"
78
+ ["#{lower_bound}, #{upper_bound}"]
79
+ end
80
+
81
+ def ignore_major(version)
82
+ parts = version.split(".")
83
+ return [] unless parts.size > 1
84
+
85
+ lower_parts = parts.first(1) + ["a"]
86
+ upper_parts = parts.first(1)
87
+ lower_parts[0] = lower_parts[0].to_i + 1
88
+ upper_parts[0] = upper_parts[0].to_i + 2
89
+ lower_bound = ">= #{lower_parts.join('.')}"
90
+ upper_bound = "< #{upper_parts.join('.')}"
91
+
92
+ ["#{lower_bound}, #{upper_bound}"]
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dependabot/config/ignore_condition"
4
+
5
+ module Dependabot
6
+ module Config
7
+ # Configuration for a single ecosystem
8
+ class UpdateConfig
9
+ attr_reader :commit_message_options, :ignore_conditions
10
+ def initialize(ignore_conditions: nil, commit_message_options: nil)
11
+ @ignore_conditions = ignore_conditions || []
12
+ @commit_message_options = commit_message_options
13
+ end
14
+
15
+ def ignored_versions_for(dependency)
16
+ normalizer = name_normaliser_for(dependency)
17
+ dep_name = name_normaliser_for(dependency).call(dependency.name)
18
+ @ignore_conditions.
19
+ select { |ic| self.class.wildcard_match?(normalizer.call(ic.dependency_name), dep_name) }.
20
+ map { |ic| ic.ignored_versions(dependency) }.
21
+ flatten.
22
+ compact.
23
+ uniq
24
+ end
25
+
26
+ def self.wildcard_match?(wildcard_string, candidate_string)
27
+ return false unless wildcard_string && candidate_string
28
+
29
+ regex_string = "a#{wildcard_string.downcase}a".split("*").
30
+ map { |p| Regexp.quote(p) }.
31
+ join(".*").gsub(/^a|a$/, "")
32
+ regex = /^#{regex_string}$/
33
+ regex.match?(candidate_string.downcase)
34
+ end
35
+
36
+ private
37
+
38
+ def name_normaliser_for(dep)
39
+ name_normaliser ||= {}
40
+ name_normaliser[dep] ||= Dependency.name_normaliser_for_package_manager(dep.package_manager)
41
+ end
42
+
43
+ class CommitMessageOptions
44
+ attr_reader :prefix, :prefix_development, :include
45
+
46
+ def initialize(prefix:, prefix_development:, include:)
47
+ @prefix = prefix
48
+ @prefix_development = prefix_development
49
+ @include = include
50
+ end
51
+
52
+ def include_scope?
53
+ @include == "scope"
54
+ end
55
+
56
+ def to_h
57
+ {
58
+ prefix: @prefix,
59
+ prefix_development: @prefix_development,
60
+ include_scope: include_scope?
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dependabot/config"
3
4
  require "dependabot/dependency_file"
4
5
  require "dependabot/source"
5
6
  require "dependabot/errors"
@@ -92,7 +92,7 @@ module Dependabot
92
92
  local_tags.
93
93
  select { |t| version_tag?(t.name) && matches_existing_prefix?(t.name) }
94
94
  filtered = tags.
95
- reject { |t| tag_included_in_ignore_reqs?(t) }
95
+ reject { |t| tag_included_in_ignore_requirements?(t) }
96
96
  raise Dependabot::AllVersionsIgnored if @raise_on_ignored && tags.any? && filtered.empty?
97
97
 
98
98
  tag = filtered.
@@ -317,8 +317,8 @@ module Dependabot
317
317
  listing_repo_git_metadata_fetcher.upload_pack
318
318
  end
319
319
 
320
- def ignore_reqs
321
- ignored_versions.map { |req| requirement_class.new(req.split(",")) }
320
+ def ignore_requirements
321
+ ignored_versions.flat_map { |req| requirement_class.requirements_array(req) }
322
322
  end
323
323
 
324
324
  def wants_prerelease?
@@ -330,9 +330,9 @@ module Dependabot
330
330
  version_class.new(version).prerelease?
331
331
  end
332
332
 
333
- def tag_included_in_ignore_reqs?(tag)
333
+ def tag_included_in_ignore_requirements?(tag)
334
334
  version = tag.name.match(VERSION_REGEX).named_captures.fetch("version")
335
- ignore_reqs.any? { |r| r.satisfied_by?(version_class.new(version)) }
335
+ ignore_requirements.any? { |r| r.satisfied_by?(version_class.new(version)) }
336
336
  end
337
337
 
338
338
  def tag_is_prerelease?(tag)
@@ -17,7 +17,6 @@ module Dependabot
17
17
  @prefix = prefix
18
18
  end
19
19
 
20
- # rubocop:disable Metrics/PerceivedComplexity
21
20
  def new_branch_name
22
21
  @name ||=
23
22
  begin
@@ -34,23 +33,13 @@ module Dependabot
34
33
  tr("@", "")
35
34
  end
36
35
 
37
- dep = dependencies.first
38
-
39
- if library? && ref_changed?(dep) && new_ref(dep)
40
- "#{dependency_name_part}-#{new_ref(dep)}"
41
- elsif library?
42
- "#{dependency_name_part}-#{sanitized_requirement(dep)}"
43
- else
44
- "#{dependency_name_part}-#{new_version(dep)}"
45
- end
36
+ "#{dependency_name_part}-#{branch_version_suffix}"
46
37
  end
47
38
 
48
39
  # Some users need branch names without slashes
49
40
  sanitize_ref(File.join(prefixes, @name).gsub("/", separator))
50
41
  end
51
42
 
52
- # rubocop:enable Metrics/PerceivedComplexity
53
-
54
43
  private
55
44
 
56
45
  def prefixes
@@ -98,6 +87,18 @@ module Dependabot
98
87
  @dependency_set
99
88
  end
100
89
 
90
+ def branch_version_suffix
91
+ dep = dependencies.first
92
+
93
+ if library? && ref_changed?(dep) && new_ref(dep)
94
+ new_ref(dep)
95
+ elsif library?
96
+ sanitized_requirement(dep)
97
+ else
98
+ new_version(dep)
99
+ end
100
+ end
101
+
101
102
  def sanitized_requirement(dependency)
102
103
  new_library_requirement(dependency).
103
104
  delete(" ").
@@ -6,6 +6,8 @@ require "securerandom"
6
6
  module Dependabot
7
7
  class PullRequestUpdater
8
8
  class Azure
9
+ class PullRequestUpdateFailed < Dependabot::DependabotError; end
10
+
9
11
  OBJECT_ID_FOR_BRANCH_DELETE = "0000000000000000000000000000000000000000"
10
12
 
11
13
  attr_reader :source, :files, :base_commit, :old_commit, :credentials,
@@ -55,9 +57,11 @@ module Dependabot
55
57
  # 1) Push the file changes to a newly created temporary branch (from base commit)
56
58
  new_commit = create_temp_branch
57
59
  # 2) Update PR source branch to point to the temp branch head commit.
58
- update_branch(source_branch_name, old_source_branch_commit, new_commit)
60
+ response = update_branch(source_branch_name, old_source_branch_commit, new_commit)
59
61
  # 3) Delete temp branch
60
62
  update_branch(temp_branch_name, new_commit, OBJECT_ID_FOR_BRANCH_DELETE)
63
+
64
+ raise PullRequestUpdateFailed, response.fetch("customMessage", nil) unless response.fetch("success", false)
61
65
  end
62
66
 
63
67
  def pull_request
@@ -38,7 +38,7 @@ module Dependabot
38
38
 
39
39
  def can_update?(requirements_to_unlock:)
40
40
  # Can't update if all versions are being ignored
41
- return false if ignore_reqs.include?(requirement_class.new(">= 0"))
41
+ return false if ignore_requirements.include?(requirement_class.new(">= 0"))
42
42
 
43
43
  if dependency.version
44
44
  version_can_update?(requirements_to_unlock: requirements_to_unlock)
@@ -141,6 +141,10 @@ module Dependabot
141
141
  security_advisories.any? { |a| a.vulnerable?(version) }
142
142
  end
143
143
 
144
+ def ignore_requirements
145
+ ignored_versions.flat_map { |req| requirement_class.requirements_array(req) }
146
+ end
147
+
144
148
  private
145
149
 
146
150
  def latest_version_resolvable_with_full_unlock?
@@ -296,10 +300,6 @@ module Dependabot
296
300
 
297
301
  changed_requirements.none? { |r| r[:requirement] == :unfixable }
298
302
  end
299
-
300
- def ignore_reqs
301
- ignored_versions.map { |req| requirement_class.new(req.split(",")) }
302
- end
303
303
  end
304
304
  end
305
305
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.141.1"
4
+ VERSION = "0.143.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.141.1
4
+ version: 0.143.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-13 00:00:00.000000000 Z
11
+ date: 2021-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -298,14 +298,14 @@ dependencies:
298
298
  requirements:
299
299
  - - "~>"
300
300
  - !ruby/object:Gem::Version
301
- version: 1.12.0
301
+ version: 1.13.0
302
302
  type: :development
303
303
  prerelease: false
304
304
  version_requirements: !ruby/object:Gem::Requirement
305
305
  requirements:
306
306
  - - "~>"
307
307
  - !ruby/object:Gem::Version
308
- version: 1.12.0
308
+ version: 1.13.0
309
309
  - !ruby/object:Gem::Dependency
310
310
  name: simplecov
311
311
  requirement: !ruby/object:Gem::Requirement
@@ -391,6 +391,11 @@ files:
391
391
  - lib/dependabot/clients/codecommit.rb
392
392
  - lib/dependabot/clients/github_with_retries.rb
393
393
  - lib/dependabot/clients/gitlab_with_retries.rb
394
+ - lib/dependabot/config.rb
395
+ - lib/dependabot/config/file.rb
396
+ - lib/dependabot/config/file_fetcher.rb
397
+ - lib/dependabot/config/ignore_condition.rb
398
+ - lib/dependabot/config/update_config.rb
394
399
  - lib/dependabot/dependency.rb
395
400
  - lib/dependabot/dependency_file.rb
396
401
  - lib/dependabot/errors.rb
@@ -463,7 +468,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
463
468
  - !ruby/object:Gem::Version
464
469
  version: 2.7.3
465
470
  requirements: []
466
- rubygems_version: 3.2.3
471
+ rubygems_version: 3.2.15
467
472
  signing_key:
468
473
  specification_version: 4
469
474
  summary: Shared code used between Dependabot package managers