dependabot-common 0.211.0 → 0.213.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dependabot/clients/azure.rb +1 -1
- data/lib/dependabot/clients/bitbucket.rb +10 -3
- data/lib/dependabot/config/file.rb +1 -1
- data/lib/dependabot/config/ignore_condition.rb +1 -1
- data/lib/dependabot/dependency.rb +27 -12
- data/lib/dependabot/errors.rb +10 -10
- data/lib/dependabot/experiments.rb +19 -0
- data/lib/dependabot/file_fetchers/base.rb +146 -83
- data/lib/dependabot/file_parsers/base/dependency_set.rb +107 -42
- data/lib/dependabot/file_updaters/vendor_updater.rb +2 -0
- data/lib/dependabot/git_commit_checker.rb +29 -13
- data/lib/dependabot/git_metadata_fetcher.rb +3 -3
- data/lib/dependabot/metadata_finders/base/changelog_finder.rb +5 -5
- data/lib/dependabot/metadata_finders/base/changelog_pruner.rb +4 -4
- data/lib/dependabot/metadata_finders/base/commits_finder.rb +4 -4
- data/lib/dependabot/metadata_finders/base/release_finder.rb +4 -4
- data/lib/dependabot/pull_request_creator/branch_namer.rb +25 -16
- data/lib/dependabot/pull_request_creator/github.rb +5 -5
- data/lib/dependabot/pull_request_creator/labeler.rb +8 -6
- data/lib/dependabot/pull_request_creator/message_builder/issue_linker.rb +5 -5
- data/lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb +34 -6
- data/lib/dependabot/pull_request_creator/message_builder/metadata_presenter.rb +11 -13
- data/lib/dependabot/pull_request_creator/message_builder.rb +117 -45
- data/lib/dependabot/pull_request_creator/pr_name_prefixer.rb +8 -12
- data/lib/dependabot/pull_request_creator.rb +6 -3
- data/lib/dependabot/pull_request_updater/azure.rb +1 -1
- data/lib/dependabot/pull_request_updater/github.rb +16 -13
- data/lib/dependabot/pull_request_updater.rb +2 -1
- data/lib/dependabot/security_advisory.rb +3 -3
- data/lib/dependabot/shared_helpers.rb +12 -12
- data/lib/dependabot/source.rb +11 -11
- data/lib/dependabot/update_checkers/base.rb +2 -2
- data/lib/dependabot/version.rb +1 -1
- metadata +17 -44
@@ -10,38 +10,46 @@ module Dependabot
|
|
10
10
|
class DependencySet
|
11
11
|
def initialize(dependencies = [], case_sensitive: false)
|
12
12
|
unless dependencies.is_a?(Array) &&
|
13
|
-
dependencies.all?
|
13
|
+
dependencies.all?(Dependency)
|
14
14
|
raise ArgumentError, "must be an array of Dependency objects"
|
15
15
|
end
|
16
16
|
|
17
|
-
@dependencies = dependencies
|
18
17
|
@case_sensitive = case_sensitive
|
18
|
+
@dependencies = Hash.new { |hsh, key| hsh[key] = DependencySlot.new }
|
19
|
+
dependencies.each { |dep| self << dep }
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
+
def dependencies
|
23
|
+
@dependencies.values.filter_map(&:combined)
|
24
|
+
end
|
22
25
|
|
23
26
|
def <<(dep)
|
24
27
|
raise ArgumentError, "must be a Dependency object" unless dep.is_a?(Dependency)
|
25
28
|
|
26
|
-
|
29
|
+
@dependencies[key_for_dependency(dep)] << dep
|
30
|
+
self
|
31
|
+
end
|
27
32
|
|
28
|
-
|
33
|
+
def +(other)
|
34
|
+
raise ArgumentError, "must be a DependencySet" unless other.is_a?(DependencySet)
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
dependencies << dep
|
36
|
+
other_names = other.dependencies.map(&:name)
|
37
|
+
other_names.each do |name|
|
38
|
+
all_versions = other.all_versions_for_name(name)
|
39
|
+
all_versions.each { |dep| self << dep }
|
35
40
|
end
|
36
41
|
|
37
42
|
self
|
38
43
|
end
|
39
44
|
|
40
|
-
def
|
41
|
-
|
45
|
+
def all_versions_for_name(name)
|
46
|
+
key = key_for_name(name)
|
47
|
+
@dependencies.key?(key) ? @dependencies[key].all_versions : []
|
48
|
+
end
|
42
49
|
|
43
|
-
|
44
|
-
|
50
|
+
def dependency_for_name(name)
|
51
|
+
key = key_for_name(name)
|
52
|
+
@dependencies.key?(key) ? @dependencies[key].combined : nil
|
45
53
|
end
|
46
54
|
|
47
55
|
private
|
@@ -50,41 +58,98 @@ module Dependabot
|
|
50
58
|
@case_sensitive
|
51
59
|
end
|
52
60
|
|
53
|
-
def
|
54
|
-
|
61
|
+
def key_for_name(name)
|
62
|
+
case_sensitive? ? name : name.downcase
|
63
|
+
end
|
55
64
|
|
56
|
-
|
65
|
+
def key_for_dependency(dep)
|
66
|
+
key_for_name(dep.name)
|
57
67
|
end
|
58
68
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
# There can only be one entry per dependency name in a `DependencySet`. Each entry
|
70
|
+
# is assigned a `DependencySlot`.
|
71
|
+
#
|
72
|
+
# In some ecosystems (like `npm_and_yarn`), however, multiple versions of a
|
73
|
+
# dependency may be encountered and added to the set. The `DependencySlot` retains
|
74
|
+
# all added versions and presents a single unified dependency for the entry
|
75
|
+
# that combines the attributes of these versions.
|
76
|
+
#
|
77
|
+
# The combined dependency is accessible via `DependencySet#dependencies` or
|
78
|
+
# `DependencySet#dependency_for_name`. The list of individual versions of the
|
79
|
+
# dependency is accessible via `DependencySet#all_versions_for_name`.
|
80
|
+
class DependencySlot
|
81
|
+
attr_reader :all_versions, :combined
|
82
|
+
|
83
|
+
def initialize
|
84
|
+
@all_versions = []
|
85
|
+
@combined = nil
|
86
|
+
end
|
87
|
+
|
88
|
+
def <<(dep)
|
89
|
+
return self if @all_versions.include?(dep)
|
90
|
+
|
91
|
+
@combined = if @combined
|
92
|
+
combined_dependency(@combined, dep)
|
93
|
+
else
|
94
|
+
Dependency.new(
|
95
|
+
name: dep.name,
|
96
|
+
version: dep.version,
|
97
|
+
requirements: dep.requirements,
|
98
|
+
package_manager: dep.package_manager,
|
99
|
+
subdependency_metadata: dep.subdependency_metadata
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
index_of_same_version =
|
104
|
+
@all_versions.find_index { |other| other.version == dep.version }
|
105
|
+
|
106
|
+
if index_of_same_version.nil?
|
107
|
+
@all_versions << dep
|
71
108
|
else
|
72
|
-
|
109
|
+
same_version = @all_versions[index_of_same_version]
|
110
|
+
@all_versions[index_of_same_version] = combined_dependency(same_version, dep)
|
73
111
|
end
|
74
112
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
# Produces a new dependency by merging the attributes of `old_dep` with those of
|
119
|
+
# `new_dep`. Requirements and subdependency metadata will be combined and deduped.
|
120
|
+
# The version of the combined dependency is determined by the logic below.
|
121
|
+
def combined_dependency(old_dep, new_dep)
|
122
|
+
version = if old_dep.top_level? # Prefer a direct dependency over a transitive one
|
123
|
+
old_dep.version || new_dep.version
|
124
|
+
elsif !version_class.correct?(new_dep.version)
|
125
|
+
old_dep.version
|
126
|
+
elsif !version_class.correct?(old_dep.version)
|
127
|
+
new_dep.version
|
128
|
+
elsif version_class.new(new_dep.version) > version_class.new(old_dep.version)
|
129
|
+
old_dep.version
|
130
|
+
else
|
131
|
+
new_dep.version
|
132
|
+
end
|
133
|
+
requirements = (old_dep.requirements + new_dep.requirements).uniq
|
134
|
+
subdependency_metadata = (
|
135
|
+
(old_dep.subdependency_metadata || []) +
|
136
|
+
(new_dep.subdependency_metadata || [])
|
137
|
+
).uniq
|
138
|
+
|
139
|
+
Dependency.new(
|
140
|
+
name: old_dep.name,
|
141
|
+
version: version,
|
142
|
+
requirements: requirements,
|
143
|
+
package_manager: old_dep.package_manager,
|
144
|
+
subdependency_metadata: subdependency_metadata
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
def version_class
|
149
|
+
@version_class ||= Utils.version_class_for_package_manager(@combined.package_manager)
|
150
|
+
end
|
87
151
|
end
|
152
|
+
private_constant :DependencySlot
|
88
153
|
end
|
89
154
|
end
|
90
155
|
end
|
@@ -18,7 +18,9 @@ module Dependabot
|
|
18
18
|
return [] unless repo_contents_path && vendor_dir
|
19
19
|
|
20
20
|
Dir.chdir(repo_contents_path) do
|
21
|
+
# rubocop:disable Performance/DeletePrefix
|
21
22
|
relative_dir = Pathname.new(base_directory).sub(%r{\A/}, "").join(vendor_dir)
|
23
|
+
# rubocop:enable Performance/DeletePrefix
|
22
24
|
|
23
25
|
status = SharedHelpers.run_shell_command(
|
24
26
|
"git status --untracked-files all --porcelain v1 #{relative_dir}"
|
@@ -19,7 +19,7 @@ module Dependabot
|
|
19
19
|
|
|
20
20
|
[0-9]+\.[0-9]+(?:\.[a-z0-9\-]+)*
|
21
21
|
)$
|
22
|
-
/ix
|
22
|
+
/ix
|
23
23
|
|
24
24
|
def initialize(dependency:, credentials:,
|
25
25
|
ignored_versions: [], raise_on_ignored: false,
|
@@ -49,8 +49,14 @@ module Dependabot
|
|
49
49
|
return true if branch
|
50
50
|
return true if dependency.version&.start_with?(ref)
|
51
51
|
|
52
|
-
#
|
53
|
-
|
52
|
+
# If the specified `ref` is actually a tag, we're pinned
|
53
|
+
return true if local_upload_pack.match?(%r{ refs/tags/#{ref}$})
|
54
|
+
|
55
|
+
# If the specified `ref` is actually a branch, we're NOT pinned
|
56
|
+
return false if local_upload_pack.match?(%r{ refs/heads/#{ref}$})
|
57
|
+
|
58
|
+
# Otherwise, assume we're pinned
|
59
|
+
true
|
54
60
|
end
|
55
61
|
|
56
62
|
def pinned_ref_looks_like_version?
|
@@ -61,6 +67,10 @@ module Dependabot
|
|
61
67
|
|
62
68
|
def pinned_ref_looks_like_commit_sha?
|
63
69
|
ref = dependency_source_details.fetch(:ref)
|
70
|
+
ref_looks_like_commit_sha?(ref)
|
71
|
+
end
|
72
|
+
|
73
|
+
def ref_looks_like_commit_sha?(ref)
|
64
74
|
return false unless ref&.match?(/^[0-9a-f]{6,40}$/)
|
65
75
|
|
66
76
|
return false unless pinned?
|
@@ -86,6 +96,10 @@ module Dependabot
|
|
86
96
|
raise Dependabot::GitDependencyReferenceNotFound, dependency.name
|
87
97
|
end
|
88
98
|
|
99
|
+
def head_commit_for_local_branch(name)
|
100
|
+
local_repo_git_metadata_fetcher.head_commit_for_ref(name)
|
101
|
+
end
|
102
|
+
|
89
103
|
def local_tags_for_latest_version_commit_sha
|
90
104
|
tags = allowed_version_tags
|
91
105
|
max_tag = max_version_tag(tags)
|
@@ -274,8 +288,8 @@ module Dependabot
|
|
274
288
|
end
|
275
289
|
|
276
290
|
def bitbucket_commit_comparison_status(ref1, ref2)
|
277
|
-
url = "https://api.bitbucket.org/2.0/repositories/"\
|
278
|
-
"#{listing_source_repo}/commits/?"\
|
291
|
+
url = "https://api.bitbucket.org/2.0/repositories/" \
|
292
|
+
"#{listing_source_repo}/commits/?" \
|
279
293
|
"include=#{ref2}&exclude=#{ref1}"
|
280
294
|
|
281
295
|
client = Clients::BitbucketWithRetries.
|
@@ -361,17 +375,19 @@ module Dependabot
|
|
361
375
|
def listing_tags
|
362
376
|
return [] unless listing_source_url
|
363
377
|
|
364
|
-
|
378
|
+
@listing_tags ||= begin
|
379
|
+
tags = listing_repo_git_metadata_fetcher.tags
|
365
380
|
|
366
|
-
|
367
|
-
|
368
|
-
|
381
|
+
if dependency_source_details&.fetch(:ref, nil)&.start_with?("tags/")
|
382
|
+
tags = tags.map do |tag|
|
383
|
+
tag.dup.tap { |t| t.name = "tags/#{tag.name}" }
|
384
|
+
end
|
369
385
|
end
|
370
|
-
end
|
371
386
|
|
372
|
-
|
373
|
-
|
374
|
-
|
387
|
+
tags
|
388
|
+
rescue GitDependenciesNotReachable
|
389
|
+
[]
|
390
|
+
end
|
375
391
|
end
|
376
392
|
|
377
393
|
def listing_upload_pack
|
@@ -6,7 +6,7 @@ require "dependabot/errors"
|
|
6
6
|
|
7
7
|
module Dependabot
|
8
8
|
class GitMetadataFetcher
|
9
|
-
KNOWN_HOSTS = /github\.com|bitbucket\.org|gitlab.com/i
|
9
|
+
KNOWN_HOSTS = /github\.com|bitbucket\.org|gitlab.com/i
|
10
10
|
|
11
11
|
def initialize(url:, credentials:)
|
12
12
|
@url = url
|
@@ -88,7 +88,7 @@ module Dependabot
|
|
88
88
|
service_pack_uri = uri
|
89
89
|
service_pack_uri += ".git" unless service_pack_uri.end_with?(".git")
|
90
90
|
|
91
|
-
env = { "PATH" => ENV
|
91
|
+
env = { "PATH" => ENV.fetch("PATH", nil) }
|
92
92
|
command = "git ls-remote #{service_pack_uri}"
|
93
93
|
command = SharedHelpers.escape_command(command)
|
94
94
|
|
@@ -125,7 +125,7 @@ module Dependabot
|
|
125
125
|
full_ref_name = line.split.last
|
126
126
|
next unless full_ref_name.start_with?("refs/tags", "refs/heads")
|
127
127
|
|
128
|
-
peeled_lines << line && next if line.strip.end_with?("^{}")
|
128
|
+
(peeled_lines << line) && next if line.strip.end_with?("^{}")
|
129
129
|
|
130
130
|
ref_name = full_ref_name.sub(%r{^refs/(tags|heads)/}, "").strip
|
131
131
|
sha = sha_for_update_pack_line(line)
|
@@ -239,7 +239,7 @@ module Dependabot
|
|
239
239
|
files += github_client.contents(source.repo, opts)
|
240
240
|
|
241
241
|
files.uniq.each do |f|
|
242
|
-
next unless
|
242
|
+
next unless f.type == "dir" && f.name.match?(/docs?/o)
|
243
243
|
|
244
244
|
opts = { path: f.path, ref: ref }.compact
|
245
245
|
files += github_client.contents(source.repo, opts)
|
@@ -300,16 +300,16 @@ module Dependabot
|
|
300
300
|
end
|
301
301
|
|
302
302
|
def previous_ref
|
303
|
-
previous_refs = dependency.previous_requirements.
|
303
|
+
previous_refs = dependency.previous_requirements.filter_map do |r|
|
304
304
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
305
|
-
end.
|
305
|
+
end.uniq
|
306
306
|
return previous_refs.first if previous_refs.count == 1
|
307
307
|
end
|
308
308
|
|
309
309
|
def new_ref
|
310
|
-
new_refs = dependency.requirements.
|
310
|
+
new_refs = dependency.requirements.filter_map do |r|
|
311
311
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
312
|
-
end.
|
312
|
+
end.uniq
|
313
313
|
return new_refs.first if new_refs.count == 1
|
314
314
|
end
|
315
315
|
|
@@ -137,16 +137,16 @@ module Dependabot
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def previous_ref
|
140
|
-
previous_refs = dependency.previous_requirements.
|
140
|
+
previous_refs = dependency.previous_requirements.filter_map do |r|
|
141
141
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
142
|
-
end.
|
142
|
+
end.uniq
|
143
143
|
return previous_refs.first if previous_refs.count == 1
|
144
144
|
end
|
145
145
|
|
146
146
|
def new_ref
|
147
|
-
new_refs = dependency.requirements.
|
147
|
+
new_refs = dependency.requirements.filter_map do |r|
|
148
148
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
149
|
-
end.
|
149
|
+
end.uniq
|
150
150
|
return new_refs.first if new_refs.count == 1
|
151
151
|
end
|
152
152
|
|
@@ -136,18 +136,18 @@ module Dependabot
|
|
136
136
|
def previous_ref
|
137
137
|
return unless git_source?(dependency.previous_requirements)
|
138
138
|
|
139
|
-
previous_refs = dependency.previous_requirements.
|
139
|
+
previous_refs = dependency.previous_requirements.filter_map do |r|
|
140
140
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
141
|
-
end.
|
141
|
+
end.uniq
|
142
142
|
return previous_refs.first if previous_refs.count == 1
|
143
143
|
end
|
144
144
|
|
145
145
|
def new_ref
|
146
146
|
return unless git_source?(dependency.previous_requirements)
|
147
147
|
|
148
|
-
new_refs = dependency.requirements.
|
148
|
+
new_refs = dependency.requirements.filter_map do |r|
|
149
149
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
150
|
-
end.
|
150
|
+
end.uniq
|
151
151
|
return new_refs.first if new_refs.count == 1
|
152
152
|
end
|
153
153
|
|
@@ -275,16 +275,16 @@ module Dependabot
|
|
275
275
|
end
|
276
276
|
|
277
277
|
def previous_ref
|
278
|
-
previous_refs = dependency.previous_requirements.
|
278
|
+
previous_refs = dependency.previous_requirements.filter_map do |r|
|
279
279
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
280
|
-
end.
|
280
|
+
end.uniq
|
281
281
|
return previous_refs.first if previous_refs.count == 1
|
282
282
|
end
|
283
283
|
|
284
284
|
def new_ref
|
285
|
-
new_refs = dependency.requirements.
|
285
|
+
new_refs = dependency.requirements.filter_map do |r|
|
286
286
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
287
|
-
end.
|
287
|
+
end.uniq
|
288
288
|
return new_refs.first if new_refs.count == 1
|
289
289
|
end
|
290
290
|
|
@@ -1,20 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "digest"
|
4
|
+
|
3
5
|
require "dependabot/metadata_finders"
|
4
6
|
require "dependabot/pull_request_creator"
|
5
7
|
|
6
8
|
module Dependabot
|
7
9
|
class PullRequestCreator
|
8
10
|
class BranchNamer
|
9
|
-
attr_reader :dependencies, :files, :target_branch, :separator, :prefix
|
11
|
+
attr_reader :dependencies, :files, :target_branch, :separator, :prefix, :max_length
|
10
12
|
|
11
13
|
def initialize(dependencies:, files:, target_branch:, separator: "/",
|
12
|
-
prefix: "dependabot")
|
14
|
+
prefix: "dependabot", max_length: nil)
|
13
15
|
@dependencies = dependencies
|
14
16
|
@files = files
|
15
17
|
@target_branch = target_branch
|
16
18
|
@separator = separator
|
17
19
|
@prefix = prefix
|
20
|
+
@max_length = max_length
|
18
21
|
end
|
19
22
|
|
20
23
|
def new_branch_name
|
@@ -37,7 +40,15 @@ module Dependabot
|
|
37
40
|
end
|
38
41
|
|
39
42
|
# Some users need branch names without slashes
|
40
|
-
sanitize_ref(File.join(prefixes, @name).gsub("/", separator))
|
43
|
+
sanitized_name = sanitize_ref(File.join(prefixes, @name).gsub("/", separator))
|
44
|
+
|
45
|
+
# Shorten the ref in case users refs have length limits
|
46
|
+
if @max_length && (sanitized_name.length > @max_length)
|
47
|
+
sha = Digest::SHA1.hexdigest(sanitized_name)[0, @max_length]
|
48
|
+
sanitized_name[[@max_length - sha.size, 0].max..] = sha
|
49
|
+
end
|
50
|
+
|
51
|
+
sanitized_name
|
41
52
|
end
|
42
53
|
|
43
54
|
private
|
@@ -90,7 +101,9 @@ module Dependabot
|
|
90
101
|
def branch_version_suffix
|
91
102
|
dep = dependencies.first
|
92
103
|
|
93
|
-
if
|
104
|
+
if dep.removed?
|
105
|
+
"-removed"
|
106
|
+
elsif library? && ref_changed?(dep) && new_ref(dep)
|
94
107
|
new_ref(dep)
|
95
108
|
elsif library?
|
96
109
|
sanitized_requirement(dep)
|
@@ -127,24 +140,24 @@ module Dependabot
|
|
127
140
|
elsif dependency.version == dependency.previous_version &&
|
128
141
|
package_manager == "docker"
|
129
142
|
dependency.requirements.
|
130
|
-
|
131
|
-
|
143
|
+
filter_map { |r| r.dig(:source, "digest") || r.dig(:source, :digest) }.
|
144
|
+
first.split(":").last[0..6]
|
132
145
|
else
|
133
146
|
dependency.version
|
134
147
|
end
|
135
148
|
end
|
136
149
|
|
137
150
|
def previous_ref(dependency)
|
138
|
-
previous_refs = dependency.previous_requirements.
|
151
|
+
previous_refs = dependency.previous_requirements.filter_map do |r|
|
139
152
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
140
|
-
end.
|
153
|
+
end.uniq
|
141
154
|
return previous_refs.first if previous_refs.count == 1
|
142
155
|
end
|
143
156
|
|
144
157
|
def new_ref(dependency)
|
145
|
-
new_refs = dependency.requirements.
|
158
|
+
new_refs = dependency.requirements.filter_map do |r|
|
146
159
|
r.dig(:source, "ref") || r.dig(:source, :ref)
|
147
|
-
end.
|
160
|
+
end.uniq
|
148
161
|
return new_refs.first if new_refs.count == 1
|
149
162
|
end
|
150
163
|
|
@@ -179,17 +192,13 @@ module Dependabot
|
|
179
192
|
|
180
193
|
def sanitize_ref(ref)
|
181
194
|
# This isn't a complete implementation of git's ref validation, but it
|
182
|
-
# covers most cases that crop up. Its list of allowed
|
195
|
+
# covers most cases that crop up. Its list of allowed characters is a
|
183
196
|
# bit stricter than git's, but that's for cosmetic reasons.
|
184
197
|
ref.
|
185
198
|
# Remove forbidden characters (those not already replaced elsewhere)
|
186
199
|
gsub(%r{[^A-Za-z0-9/\-_.(){}]}, "").
|
187
200
|
# Slashes can't be followed by periods
|
188
|
-
gsub(%r{/\.}, "/dot-").
|
189
|
-
# Two or more sequential periods are forbidden
|
190
|
-
gsub(/\.+/, ".").
|
191
|
-
# Two or more sequential slashes are forbidden
|
192
|
-
gsub(%r{/+}, "/").
|
201
|
+
gsub(%r{/\.}, "/dot-").squeeze(".").squeeze("/").
|
193
202
|
# Trailing periods are forbidden
|
194
203
|
sub(/\.$/, "")
|
195
204
|
end
|
@@ -219,7 +219,7 @@ module Dependabot
|
|
219
219
|
retry_count ||= 0
|
220
220
|
retry_count += 1
|
221
221
|
if retry_count > 10
|
222
|
-
raise "Repeatedly failed to create or update branch #{branch_name} "\
|
222
|
+
raise "Repeatedly failed to create or update branch #{branch_name} " \
|
223
223
|
"with commit #{commit.sha}."
|
224
224
|
end
|
225
225
|
|
@@ -269,7 +269,7 @@ module Dependabot
|
|
269
269
|
|
270
270
|
def add_reviewers_to_pull_request(pull_request)
|
271
271
|
reviewers_hash =
|
272
|
-
reviewers.keys.
|
272
|
+
reviewers.keys.to_h { |k| [k.to_sym, reviewers[k]] }
|
273
273
|
|
274
274
|
github_client_for_source.request_pull_request_review(
|
275
275
|
source.repo,
|
@@ -299,7 +299,7 @@ module Dependabot
|
|
299
299
|
|
300
300
|
def comment_with_invalid_reviewer(pull_request, message)
|
301
301
|
reviewers_hash =
|
302
|
-
reviewers.keys.
|
302
|
+
reviewers.keys.to_h { |k| [k.to_sym, reviewers[k]] }
|
303
303
|
reviewers = []
|
304
304
|
reviewers += reviewers_hash[:reviewers] || []
|
305
305
|
reviewers += (reviewers_hash[:team_reviewers] || []).
|
@@ -315,9 +315,9 @@ module Dependabot
|
|
315
315
|
|
316
316
|
msg = "Dependabot tried to add #{reviewers_string} as "
|
317
317
|
msg += reviewers.count > 1 ? "reviewers" : "a reviewer"
|
318
|
-
msg += " to this PR, but received the following error from GitHub:\n\n"\
|
318
|
+
msg += " to this PR, but received the following error from GitHub:\n\n" \
|
319
319
|
"```\n" \
|
320
|
-
"#{message}\n"\
|
320
|
+
"#{message}\n" \
|
321
321
|
"```"
|
322
322
|
|
323
323
|
github_client_for_source.add_comment(
|
@@ -5,7 +5,7 @@ require "dependabot/pull_request_creator"
|
|
5
5
|
module Dependabot
|
6
6
|
class PullRequestCreator
|
7
7
|
class Labeler
|
8
|
-
DEPENDENCIES_LABEL_REGEX = %r{^[^/]*dependenc[^/]+$}i
|
8
|
+
DEPENDENCIES_LABEL_REGEX = %r{^[^/]*dependenc[^/]+$}i
|
9
9
|
DEFAULT_DEPENDENCIES_LABEL = "dependencies"
|
10
10
|
DEFAULT_SECURITY_LABEL = "security"
|
11
11
|
|
@@ -105,7 +105,9 @@ module Dependabot
|
|
105
105
|
new_version_parts = version(dep).split(/[.+]/)
|
106
106
|
old_version_parts = previous_version(dep)&.split(/[.+]/) || []
|
107
107
|
all_parts = new_version_parts.first(3) + old_version_parts.first(3)
|
108
|
+
# rubocop:disable Performance/RedundantEqualityComparisonBlock
|
108
109
|
next 0 unless all_parts.all? { |part| part.to_i.to_s == part }
|
110
|
+
# rubocop:enable Performance/RedundantEqualityComparisonBlock
|
109
111
|
next 1 if new_version_parts[0] != old_version_parts[0]
|
110
112
|
next 2 if new_version_parts[1] != old_version_parts[1]
|
111
113
|
|
@@ -269,7 +271,7 @@ module Dependabot
|
|
269
271
|
end
|
270
272
|
|
271
273
|
def fetch_azure_labels
|
272
|
-
|
274
|
+
language_name =
|
273
275
|
self.class.label_details_for_package_manager(package_manager).
|
274
276
|
fetch(:name)
|
275
277
|
|
@@ -277,7 +279,7 @@ module Dependabot
|
|
277
279
|
*@labels,
|
278
280
|
DEFAULT_DEPENDENCIES_LABEL,
|
279
281
|
DEFAULT_SECURITY_LABEL,
|
280
|
-
|
282
|
+
language_name
|
281
283
|
].uniq
|
282
284
|
end
|
283
285
|
|
@@ -372,16 +374,16 @@ module Dependabot
|
|
372
374
|
end
|
373
375
|
|
374
376
|
def create_gitlab_language_label
|
375
|
-
|
377
|
+
language_name =
|
376
378
|
self.class.label_details_for_package_manager(package_manager).
|
377
379
|
fetch(:name)
|
378
380
|
gitlab_client_for_source.create_label(
|
379
381
|
source.repo,
|
380
|
-
|
382
|
+
language_name,
|
381
383
|
"#" + self.class.label_details_for_package_manager(package_manager).
|
382
384
|
fetch(:colour)
|
383
385
|
)
|
384
|
-
@labels = [*@labels,
|
386
|
+
@labels = [*@labels, language_name].uniq
|
385
387
|
end
|
386
388
|
|
387
389
|
def github_client_for_source
|
@@ -6,15 +6,15 @@ module Dependabot
|
|
6
6
|
class PullRequestCreator
|
7
7
|
class MessageBuilder
|
8
8
|
class IssueLinker
|
9
|
-
REPO_REGEX = %r{(?<repo>[\w.-]+/(?:(?!\.git|\.\s)[\w.-])+)}
|
10
|
-
TAG_REGEX = /(?<tag>(?:\#|GH-)\d+)/i
|
9
|
+
REPO_REGEX = %r{(?<repo>[\w.-]+/(?:(?!\.git|\.\s)[\w.-])+)}
|
10
|
+
TAG_REGEX = /(?<tag>(?:\#|GH-)\d+)/i
|
11
11
|
ISSUE_LINK_REGEXS = [
|
12
12
|
/
|
13
13
|
(?:(?<=[^A-Za-z0-9\[\\]|^)\\*#{TAG_REGEX}(?=[^A-Za-z0-9\-]|$))|
|
14
14
|
(?:(?<=\s|^)#{REPO_REGEX}#{TAG_REGEX}(?=[^A-Za-z0-9\-]|$))
|
15
|
-
/x
|
16
|
-
/\[#{TAG_REGEX}\](?=[^A-Za-z0-9\-\(])
|
17
|
-
/\[(?<tag>(?:\#|GH-)?\d+)\]\(\)/i
|
15
|
+
/x,
|
16
|
+
/\[#{TAG_REGEX}\](?=[^A-Za-z0-9\-\(])/,
|
17
|
+
/\[(?<tag>(?:\#|GH-)?\d+)\]\(\)/i
|
18
18
|
].freeze
|
19
19
|
|
20
20
|
attr_reader :source_url
|