dependabot-common 0.211.0 → 0.213.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.
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23fa5c7ea872ca0849f22018af9b0811ad9044f03a4e7d59aa023b3dd80bd4e6
|
|
4
|
+
data.tar.gz: cea778ebef75ccec5afcd3e5932af78d9711c51c4c864ea02d65930fce8ca4dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b14ad55cbabd2a49bd35c7f8012f95972515eead80a71363353a8978286e9d756fd97da5442cb3013acdebfb1a77c7f8f7c450bac553a2d6f52b12687fcf2d43
|
|
7
|
+
data.tar.gz: 86cbba3afb724d1ee0b6c1fd0bb357a33c288263b3032e0ef029e099b5d7f7d8d5104526a8890d6233fdb8850b56ecd05cb0746bd8e6fe8fd84338db8caa28dd
|
|
@@ -310,7 +310,7 @@ module Dependabot
|
|
|
310
310
|
# https://developercommunity.visualstudio.com/content/problem/608770/remove-4000-character-limit-on-pull-request-descri.html
|
|
311
311
|
pr_description = pr_description.dup.force_encoding(Encoding::UTF_16)
|
|
312
312
|
if pr_description.length > MAX_PR_DESCRIPTION_LENGTH
|
|
313
|
-
truncated_msg = "...\n\n_Description has been truncated_".
|
|
313
|
+
truncated_msg = (+"...\n\n_Description has been truncated_").force_encoding(Encoding::UTF_16)
|
|
314
314
|
truncate_length = MAX_PR_DESCRIPTION_LENGTH - truncated_msg.length
|
|
315
315
|
pr_description = (pr_description[0..truncate_length] + truncated_msg)
|
|
316
316
|
end
|
|
@@ -144,7 +144,14 @@ module Dependabot
|
|
|
144
144
|
end
|
|
145
145
|
# rubocop:enable Metrics/ParameterLists
|
|
146
146
|
|
|
147
|
+
def current_user
|
|
148
|
+
base_url = "https://api.bitbucket.org/2.0/user?fields=uuid"
|
|
149
|
+
response = get(base_url)
|
|
150
|
+
JSON.parse(response.body).fetch("uuid")
|
|
151
|
+
end
|
|
152
|
+
|
|
147
153
|
def default_reviewers(repo)
|
|
154
|
+
current_uuid = current_user
|
|
148
155
|
path = "#{repo}/default-reviewers?pagelen=100&fields=values.uuid,next"
|
|
149
156
|
reviewers_url = base_url + path
|
|
150
157
|
|
|
@@ -153,7 +160,7 @@ module Dependabot
|
|
|
153
160
|
reviewer_data = []
|
|
154
161
|
|
|
155
162
|
default_reviewers.each do |reviewer|
|
|
156
|
-
reviewer_data.append({ uuid: reviewer.fetch("uuid") })
|
|
163
|
+
reviewer_data.append({ uuid: reviewer.fetch("uuid") }) unless current_uuid == reviewer.fetch("uuid")
|
|
157
164
|
end
|
|
158
165
|
|
|
159
166
|
reviewer_data
|
|
@@ -189,8 +196,8 @@ module Dependabot
|
|
|
189
196
|
raise NotFound if response.status == 404
|
|
190
197
|
|
|
191
198
|
if response.status >= 400
|
|
192
|
-
raise "Unhandled Bitbucket error!\n"\
|
|
193
|
-
"Status: #{response.status}\n"\
|
|
199
|
+
raise "Unhandled Bitbucket error!\n" \
|
|
200
|
+
"Status: #{response.status}\n" \
|
|
194
201
|
"Body: #{response.body}"
|
|
195
202
|
end
|
|
196
203
|
|
|
@@ -71,7 +71,7 @@ module Dependabot
|
|
|
71
71
|
commit_message = cfg&.dig(:"commit-message") || {}
|
|
72
72
|
Dependabot::Config::UpdateConfig::CommitMessageOptions.new(
|
|
73
73
|
prefix: commit_message[:prefix],
|
|
74
|
-
prefix_development: commit_message[:"prefix-development"],
|
|
74
|
+
prefix_development: commit_message[:"prefix-development"] || commit_message[:prefix],
|
|
75
75
|
include: commit_message[:include]
|
|
76
76
|
)
|
|
77
77
|
end
|
|
@@ -37,11 +37,11 @@ module Dependabot
|
|
|
37
37
|
|
|
38
38
|
attr_reader :name, :version, :requirements, :package_manager,
|
|
39
39
|
:previous_version, :previous_requirements,
|
|
40
|
-
:subdependency_metadata
|
|
40
|
+
:subdependency_metadata, :metadata
|
|
41
41
|
|
|
42
42
|
def initialize(name:, requirements:, package_manager:, version: nil,
|
|
43
43
|
previous_version: nil, previous_requirements: nil,
|
|
44
|
-
subdependency_metadata: [], removed: false)
|
|
44
|
+
subdependency_metadata: [], removed: false, metadata: {})
|
|
45
45
|
@name = name
|
|
46
46
|
@version = version
|
|
47
47
|
@requirements = requirements.map { |req| symbolize_keys(req) }
|
|
@@ -54,6 +54,7 @@ module Dependabot
|
|
|
54
54
|
map { |h| symbolize_keys(h) }
|
|
55
55
|
end
|
|
56
56
|
@removed = removed
|
|
57
|
+
@metadata = symbolize_keys(metadata || {})
|
|
57
58
|
|
|
58
59
|
check_values
|
|
59
60
|
end
|
|
@@ -105,6 +106,22 @@ module Dependabot
|
|
|
105
106
|
display_name_builder.call(name)
|
|
106
107
|
end
|
|
107
108
|
|
|
109
|
+
# Returns all detected versions of the dependency. Only ecosystems that
|
|
110
|
+
# support this feature will return more than the current version.
|
|
111
|
+
def all_versions
|
|
112
|
+
all_versions = metadata[:all_versions]
|
|
113
|
+
return [version].compact unless all_versions
|
|
114
|
+
|
|
115
|
+
all_versions.filter_map(&:version)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# This dependency is being indirectly updated by an update to another
|
|
119
|
+
# dependency. We don't need to try and update it ourselves but want to
|
|
120
|
+
# surface it to the user in the PR.
|
|
121
|
+
def informational_only?
|
|
122
|
+
metadata[:information_only]
|
|
123
|
+
end
|
|
124
|
+
|
|
108
125
|
def ==(other)
|
|
109
126
|
other.instance_of?(self.class) && to_h == other.to_h
|
|
110
127
|
end
|
|
@@ -120,9 +137,7 @@ module Dependabot
|
|
|
120
137
|
private
|
|
121
138
|
|
|
122
139
|
def check_values
|
|
123
|
-
if [version, previous_version].any?
|
|
124
|
-
raise ArgumentError, "blank strings must not be provided as versions"
|
|
125
|
-
end
|
|
140
|
+
raise ArgumentError, "blank strings must not be provided as versions" if [version, previous_version].any?("")
|
|
126
141
|
|
|
127
142
|
check_requirement_fields
|
|
128
143
|
check_subdependency_metadata
|
|
@@ -130,8 +145,8 @@ module Dependabot
|
|
|
130
145
|
|
|
131
146
|
def check_requirement_fields
|
|
132
147
|
requirement_fields = [requirements, previous_requirements].compact
|
|
133
|
-
unless requirement_fields.all?
|
|
134
|
-
requirement_fields.flatten.all?
|
|
148
|
+
unless requirement_fields.all?(Array) &&
|
|
149
|
+
requirement_fields.flatten.all?(Hash)
|
|
135
150
|
raise ArgumentError, "requirements must be an array of hashes"
|
|
136
151
|
end
|
|
137
152
|
|
|
@@ -139,9 +154,9 @@ module Dependabot
|
|
|
139
154
|
optional_keys = %i(metadata)
|
|
140
155
|
unless requirement_fields.flatten.
|
|
141
156
|
all? { |r| required_keys.sort == (r.keys - optional_keys).sort }
|
|
142
|
-
raise ArgumentError, "each requirement must have the following "\
|
|
143
|
-
"required keys: #{required_keys.join(', ')}."\
|
|
144
|
-
"Optionally, it may have the following keys: "\
|
|
157
|
+
raise ArgumentError, "each requirement must have the following " \
|
|
158
|
+
"required keys: #{required_keys.join(', ')}." \
|
|
159
|
+
"Optionally, it may have the following keys: " \
|
|
145
160
|
"#{optional_keys.join(', ')}."
|
|
146
161
|
end
|
|
147
162
|
|
|
@@ -154,13 +169,13 @@ module Dependabot
|
|
|
154
169
|
return unless subdependency_metadata
|
|
155
170
|
|
|
156
171
|
unless subdependency_metadata.is_a?(Array) &&
|
|
157
|
-
subdependency_metadata.all?
|
|
172
|
+
subdependency_metadata.all?(Hash)
|
|
158
173
|
raise ArgumentError, "subdependency_metadata must be an array of hashes"
|
|
159
174
|
end
|
|
160
175
|
end
|
|
161
176
|
|
|
162
177
|
def symbolize_keys(hash)
|
|
163
|
-
hash.keys.
|
|
178
|
+
hash.keys.to_h { |k| [k.to_sym, hash[k]] }
|
|
164
179
|
end
|
|
165
180
|
end
|
|
166
181
|
end
|
data/lib/dependabot/errors.rb
CHANGED
|
@@ -4,9 +4,9 @@ require "dependabot/utils"
|
|
|
4
4
|
|
|
5
5
|
module Dependabot
|
|
6
6
|
class DependabotError < StandardError
|
|
7
|
-
BASIC_AUTH_REGEX = %r{://(?<auth>[^:]*:[^@%\s]+(@|%40))}
|
|
7
|
+
BASIC_AUTH_REGEX = %r{://(?<auth>[^:]*:[^@%\s]+(@|%40))}
|
|
8
8
|
# Remove any path segment from fury.io sources
|
|
9
|
-
FURY_IO_PATH_REGEX = %r{fury\.io/(?<path>.+)}
|
|
9
|
+
FURY_IO_PATH_REGEX = %r{fury\.io/(?<path>.+)}
|
|
10
10
|
|
|
11
11
|
def initialize(message = nil)
|
|
12
12
|
super(sanitize_message(message))
|
|
@@ -18,7 +18,7 @@ module Dependabot
|
|
|
18
18
|
return message unless message.is_a?(String)
|
|
19
19
|
|
|
20
20
|
path_regex =
|
|
21
|
-
Regexp.escape(Utils::BUMP_TMP_DIR_PATH) + "
|
|
21
|
+
Regexp.escape(Utils::BUMP_TMP_DIR_PATH) + "\\/" +
|
|
22
22
|
Regexp.escape(Utils::BUMP_TMP_FILE_PREFIX) + "[a-zA-Z0-9-]*"
|
|
23
23
|
|
|
24
24
|
message = message.gsub(/#{path_regex}/, "dependabot_tmp_dir").strip
|
|
@@ -124,8 +124,8 @@ module Dependabot
|
|
|
124
124
|
|
|
125
125
|
def initialize(source)
|
|
126
126
|
@source = sanitize_source(source)
|
|
127
|
-
msg = "The following source could not be reached as it requires "\
|
|
128
|
-
"authentication (and any provided details were invalid or lacked "\
|
|
127
|
+
msg = "The following source could not be reached as it requires " \
|
|
128
|
+
"authentication (and any provided details were invalid or lacked " \
|
|
129
129
|
"the required permissions): #{@source}"
|
|
130
130
|
super(msg)
|
|
131
131
|
end
|
|
@@ -173,7 +173,7 @@ module Dependabot
|
|
|
173
173
|
@dependency_urls =
|
|
174
174
|
dependency_urls.flatten.map { |uri| filter_sensitive_data(uri) }
|
|
175
175
|
|
|
176
|
-
msg = "The following git URLs could not be retrieved: "\
|
|
176
|
+
msg = "The following git URLs could not be retrieved: " \
|
|
177
177
|
"#{@dependency_urls.join(', ')}"
|
|
178
178
|
super(msg)
|
|
179
179
|
end
|
|
@@ -185,7 +185,7 @@ module Dependabot
|
|
|
185
185
|
def initialize(dependency)
|
|
186
186
|
@dependency = dependency
|
|
187
187
|
|
|
188
|
-
msg = "The branch or reference specified for #{@dependency} could not "\
|
|
188
|
+
msg = "The branch or reference specified for #{@dependency} could not " \
|
|
189
189
|
"be retrieved"
|
|
190
190
|
super(msg)
|
|
191
191
|
end
|
|
@@ -196,7 +196,7 @@ module Dependabot
|
|
|
196
196
|
|
|
197
197
|
def initialize(*dependencies)
|
|
198
198
|
@dependencies = dependencies.flatten
|
|
199
|
-
msg = "The following path based dependencies could not be retrieved: "\
|
|
199
|
+
msg = "The following path based dependencies could not be retrieved: " \
|
|
200
200
|
"#{@dependencies.join(', ')}"
|
|
201
201
|
super(msg)
|
|
202
202
|
end
|
|
@@ -210,8 +210,8 @@ module Dependabot
|
|
|
210
210
|
@declared_path = declared_path
|
|
211
211
|
@discovered_path = discovered_path
|
|
212
212
|
|
|
213
|
-
msg = "The module path '#{@declared_path}' found in #{@go_mod} doesn't "\
|
|
214
|
-
"match the actual path '#{@discovered_path}' in the dependency's "\
|
|
213
|
+
msg = "The module path '#{@declared_path}' found in #{@go_mod} doesn't " \
|
|
214
|
+
"match the actual path '#{@discovered_path}' in the dependency's " \
|
|
215
215
|
"go.mod"
|
|
216
216
|
super(msg)
|
|
217
217
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dependabot
|
|
4
|
+
module Experiments
|
|
5
|
+
@experiments = {}
|
|
6
|
+
|
|
7
|
+
def self.reset!
|
|
8
|
+
@experiments = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.register(name, value)
|
|
12
|
+
@experiments[name.to_sym] = value
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.enabled?(name)
|
|
16
|
+
!!@experiments[name.to_sym]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "stringio"
|
|
3
4
|
require "dependabot/config"
|
|
4
5
|
require "dependabot/dependency_file"
|
|
5
6
|
require "dependabot/source"
|
|
@@ -69,6 +70,7 @@ module Dependabot
|
|
|
69
70
|
end
|
|
70
71
|
|
|
71
72
|
def commit
|
|
73
|
+
return cloned_commit if cloned_commit
|
|
72
74
|
return source.commit if source.commit
|
|
73
75
|
|
|
74
76
|
branch = target_branch || default_branch_for_repo
|
|
@@ -84,7 +86,11 @@ module Dependabot
|
|
|
84
86
|
def clone_repo_contents
|
|
85
87
|
@clone_repo_contents ||=
|
|
86
88
|
_clone_repo_contents(target_directory: repo_contents_path)
|
|
87
|
-
rescue Dependabot::SharedHelpers::HelperSubprocessFailed
|
|
89
|
+
rescue Dependabot::SharedHelpers::HelperSubprocessFailed => e
|
|
90
|
+
if e.message.include?("fatal: Remote branch #{target_branch} not found in upstream origin")
|
|
91
|
+
raise Dependabot::BranchNotFound, target_branch
|
|
92
|
+
end
|
|
93
|
+
|
|
88
94
|
raise Dependabot::RepoNotFound, source
|
|
89
95
|
end
|
|
90
96
|
|
|
@@ -141,7 +147,7 @@ module Dependabot
|
|
|
141
147
|
|
|
142
148
|
path = Pathname.new(File.join(directory, filename)).cleanpath.to_path
|
|
143
149
|
content = _fetch_file_content(path, fetch_submodules: fetch_submodules)
|
|
144
|
-
type = @linked_paths.key?(path.gsub(%r{^/}, ""))
|
|
150
|
+
type = "symlink" if @linked_paths.key?(path.gsub(%r{^/}, ""))
|
|
145
151
|
|
|
146
152
|
DependencyFile.new(
|
|
147
153
|
name: Pathname.new(filename).cleanpath.to_path,
|
|
@@ -168,6 +174,97 @@ module Dependabot
|
|
|
168
174
|
end
|
|
169
175
|
end
|
|
170
176
|
|
|
177
|
+
def cloned_commit
|
|
178
|
+
return if repo_contents_path.nil? || !File.directory?(File.join(repo_contents_path, ".git"))
|
|
179
|
+
|
|
180
|
+
SharedHelpers.with_git_configured(credentials: credentials) do
|
|
181
|
+
Dir.chdir(repo_contents_path) do
|
|
182
|
+
return SharedHelpers.run_shell_command("git rev-parse HEAD")&.strip
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def default_branch_for_repo
|
|
188
|
+
@default_branch_for_repo ||= client_for_provider.
|
|
189
|
+
fetch_default_branch(repo)
|
|
190
|
+
rescue *CLIENT_NOT_FOUND_ERRORS
|
|
191
|
+
raise Dependabot::RepoNotFound, source
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def update_linked_paths(repo, path, commit, github_response)
|
|
195
|
+
case github_response.type
|
|
196
|
+
when "submodule"
|
|
197
|
+
sub_source = Source.from_url(github_response.submodule_git_url)
|
|
198
|
+
return unless sub_source
|
|
199
|
+
|
|
200
|
+
@linked_paths[path] = {
|
|
201
|
+
repo: sub_source.repo,
|
|
202
|
+
provider: sub_source.provider,
|
|
203
|
+
commit: github_response.sha,
|
|
204
|
+
path: "/"
|
|
205
|
+
}
|
|
206
|
+
when "symlink"
|
|
207
|
+
updated_path = File.join(File.dirname(path), github_response.target)
|
|
208
|
+
@linked_paths[path] = {
|
|
209
|
+
repo: repo,
|
|
210
|
+
provider: "github",
|
|
211
|
+
commit: commit,
|
|
212
|
+
path: Pathname.new(updated_path).cleanpath.to_path
|
|
213
|
+
}
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def recurse_submodules_when_cloning?
|
|
218
|
+
false
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def client_for_provider
|
|
222
|
+
case source.provider
|
|
223
|
+
when "github" then github_client
|
|
224
|
+
when "gitlab" then gitlab_client
|
|
225
|
+
when "azure" then azure_client
|
|
226
|
+
when "bitbucket" then bitbucket_client
|
|
227
|
+
when "codecommit" then codecommit_client
|
|
228
|
+
else raise "Unsupported provider '#{source.provider}'."
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def github_client
|
|
233
|
+
@github_client ||=
|
|
234
|
+
Dependabot::Clients::GithubWithRetries.for_source(
|
|
235
|
+
source: source,
|
|
236
|
+
credentials: credentials
|
|
237
|
+
)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def gitlab_client
|
|
241
|
+
@gitlab_client ||=
|
|
242
|
+
Dependabot::Clients::GitlabWithRetries.for_source(
|
|
243
|
+
source: source,
|
|
244
|
+
credentials: credentials
|
|
245
|
+
)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def azure_client
|
|
249
|
+
@azure_client ||=
|
|
250
|
+
Dependabot::Clients::Azure.
|
|
251
|
+
for_source(source: source, credentials: credentials)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def bitbucket_client
|
|
255
|
+
# TODO: When self-hosted Bitbucket is supported this should use
|
|
256
|
+
# `Bitbucket.for_source`
|
|
257
|
+
@bitbucket_client ||=
|
|
258
|
+
Dependabot::Clients::BitbucketWithRetries.
|
|
259
|
+
for_bitbucket_dot_org(credentials: credentials)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def codecommit_client
|
|
263
|
+
@codecommit_client ||=
|
|
264
|
+
Dependabot::Clients::CodeCommit.
|
|
265
|
+
for_source(source: source, credentials: credentials)
|
|
266
|
+
end
|
|
267
|
+
|
|
171
268
|
#################################################
|
|
172
269
|
# INTERNAL METHODS (not for use by sub-classes) #
|
|
173
270
|
#################################################
|
|
@@ -233,8 +330,8 @@ module Dependabot
|
|
|
233
330
|
repo_path = File.join(clone_repo_contents, relative_path)
|
|
234
331
|
return [] unless Dir.exist?(repo_path)
|
|
235
332
|
|
|
236
|
-
Dir.entries(repo_path).
|
|
237
|
-
next if
|
|
333
|
+
Dir.entries(repo_path).filter_map do |name|
|
|
334
|
+
next if name == "." || name == ".."
|
|
238
335
|
|
|
239
336
|
absolute_path = File.join(repo_path, name)
|
|
240
337
|
type = if File.symlink?(absolute_path)
|
|
@@ -251,29 +348,6 @@ module Dependabot
|
|
|
251
348
|
type: type,
|
|
252
349
|
size: 0 # NOTE: added for parity with github contents API
|
|
253
350
|
)
|
|
254
|
-
end.compact
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def update_linked_paths(repo, path, commit, github_response)
|
|
258
|
-
case github_response.type
|
|
259
|
-
when "submodule"
|
|
260
|
-
sub_source = Source.from_url(github_response.submodule_git_url)
|
|
261
|
-
return unless sub_source
|
|
262
|
-
|
|
263
|
-
@linked_paths[path] = {
|
|
264
|
-
repo: sub_source.repo,
|
|
265
|
-
provider: sub_source.provider,
|
|
266
|
-
commit: github_response.sha,
|
|
267
|
-
path: "/"
|
|
268
|
-
}
|
|
269
|
-
when "symlink"
|
|
270
|
-
updated_path = File.join(File.dirname(path), github_response.target)
|
|
271
|
-
@linked_paths[path] = {
|
|
272
|
-
repo: repo,
|
|
273
|
-
provider: "github",
|
|
274
|
-
commit: commit,
|
|
275
|
-
path: Pathname.new(updated_path).cleanpath.to_path
|
|
276
|
-
}
|
|
277
351
|
end
|
|
278
352
|
end
|
|
279
353
|
|
|
@@ -473,13 +547,6 @@ module Dependabot
|
|
|
473
547
|
end
|
|
474
548
|
# rubocop:enable Metrics/AbcSize
|
|
475
549
|
|
|
476
|
-
def default_branch_for_repo
|
|
477
|
-
@default_branch_for_repo ||= client_for_provider.
|
|
478
|
-
fetch_default_branch(repo)
|
|
479
|
-
rescue *CLIENT_NOT_FOUND_ERRORS
|
|
480
|
-
raise Dependabot::RepoNotFound, source
|
|
481
|
-
end
|
|
482
|
-
|
|
483
550
|
# Update the @linked_paths hash by exploiting a side-effect of
|
|
484
551
|
# recursively calling `repo_contents` for each directory up the tree
|
|
485
552
|
# until a submodule or symlink is found
|
|
@@ -504,6 +571,10 @@ module Dependabot
|
|
|
504
571
|
max_by(&:length)
|
|
505
572
|
end
|
|
506
573
|
|
|
574
|
+
# rubocop:disable Metrics/AbcSize
|
|
575
|
+
# rubocop:disable Metrics/MethodLength
|
|
576
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
|
577
|
+
# rubocop:disable Metrics/BlockLength
|
|
507
578
|
def _clone_repo_contents(target_directory:)
|
|
508
579
|
SharedHelpers.with_git_configured(credentials: credentials) do
|
|
509
580
|
path = target_directory || File.join("tmp", source.repo)
|
|
@@ -512,62 +583,54 @@ module Dependabot
|
|
|
512
583
|
return path if Dir.exist?(File.join(path, ".git"))
|
|
513
584
|
|
|
514
585
|
FileUtils.mkdir_p(path)
|
|
515
|
-
|
|
586
|
+
|
|
587
|
+
clone_options = StringIO.new
|
|
588
|
+
clone_options << "--no-tags --depth 1"
|
|
589
|
+
clone_options << if recurse_submodules_when_cloning?
|
|
590
|
+
" --recurse-submodules --shallow-submodules"
|
|
591
|
+
else
|
|
592
|
+
" --no-recurse-submodules"
|
|
593
|
+
end
|
|
594
|
+
clone_options << " --branch #{source.branch} --single-branch" if source.branch
|
|
516
595
|
SharedHelpers.run_shell_command(
|
|
517
596
|
<<~CMD
|
|
518
|
-
git clone
|
|
597
|
+
git clone #{clone_options.string} #{source.url} #{path}
|
|
519
598
|
CMD
|
|
520
599
|
)
|
|
521
|
-
path
|
|
522
|
-
end
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
def client_for_provider
|
|
526
|
-
case source.provider
|
|
527
|
-
when "github" then github_client
|
|
528
|
-
when "gitlab" then gitlab_client
|
|
529
|
-
when "azure" then azure_client
|
|
530
|
-
when "bitbucket" then bitbucket_client
|
|
531
|
-
when "codecommit" then codecommit_client
|
|
532
|
-
else raise "Unsupported provider '#{source.provider}'."
|
|
533
|
-
end
|
|
534
|
-
end
|
|
535
|
-
|
|
536
|
-
def github_client
|
|
537
|
-
@github_client ||=
|
|
538
|
-
Dependabot::Clients::GithubWithRetries.for_source(
|
|
539
|
-
source: source,
|
|
540
|
-
credentials: credentials
|
|
541
|
-
)
|
|
542
|
-
end
|
|
543
|
-
|
|
544
|
-
def gitlab_client
|
|
545
|
-
@gitlab_client ||=
|
|
546
|
-
Dependabot::Clients::GitlabWithRetries.for_source(
|
|
547
|
-
source: source,
|
|
548
|
-
credentials: credentials
|
|
549
|
-
)
|
|
550
|
-
end
|
|
551
600
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
601
|
+
if source.commit
|
|
602
|
+
# This code will only be called for testing. Production will never pass a commit
|
|
603
|
+
# since Dependabot always wants to use the latest commit on a branch.
|
|
604
|
+
Dir.chdir(path) do
|
|
605
|
+
fetch_options = StringIO.new
|
|
606
|
+
fetch_options << "--depth 1"
|
|
607
|
+
fetch_options << if recurse_submodules_when_cloning?
|
|
608
|
+
" --recurse-submodules=on-demand"
|
|
609
|
+
else
|
|
610
|
+
" --no-recurse-submodules"
|
|
611
|
+
end
|
|
612
|
+
# Need to fetch the commit due to the --depth 1 above.
|
|
613
|
+
SharedHelpers.run_shell_command("git fetch #{fetch_options.string} origin #{source.commit}")
|
|
614
|
+
|
|
615
|
+
reset_options = StringIO.new
|
|
616
|
+
reset_options << "--hard"
|
|
617
|
+
reset_options << if recurse_submodules_when_cloning?
|
|
618
|
+
" --recurse-submodules"
|
|
619
|
+
else
|
|
620
|
+
" --no-recurse-submodules"
|
|
621
|
+
end
|
|
622
|
+
# Set HEAD to this commit so later calls so git reset HEAD will work.
|
|
623
|
+
SharedHelpers.run_shell_command("git reset #{reset_options.string} #{source.commit}")
|
|
624
|
+
end
|
|
625
|
+
end
|
|
565
626
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
Dependabot::Clients::CodeCommit.
|
|
569
|
-
for_source(source: source, credentials: credentials)
|
|
627
|
+
path
|
|
628
|
+
end
|
|
570
629
|
end
|
|
630
|
+
# rubocop:enable Metrics/AbcSize
|
|
631
|
+
# rubocop:enable Metrics/MethodLength
|
|
632
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
|
633
|
+
# rubocop:enable Metrics/BlockLength
|
|
571
634
|
end
|
|
572
635
|
end
|
|
573
636
|
end
|