dependabot-common 0.129.0 → 0.129.5
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 +38 -9
- data/lib/dependabot/clients/bitbucket.rb +152 -1
- data/lib/dependabot/errors.rb +42 -22
- data/lib/dependabot/pull_request_creator.rb +18 -0
- data/lib/dependabot/pull_request_creator/bitbucket.rb +96 -0
- data/lib/dependabot/pull_request_creator/pr_name_prefixer.rb +38 -0
- data/lib/dependabot/shared_helpers.rb +5 -20
- data/lib/dependabot/utils.rb +3 -0
- data/lib/dependabot/version.rb +1 -1
- metadata +15 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1d1cc2bd77777e93b8fca08afc74d928b5411d1fe7a0ecd3f49816af62a35de
|
4
|
+
data.tar.gz: 319321fda5a8194d1cd8901dff4e92ce6bf4658890b73adf4f433ad54dc8963e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '028485e8e53d49096323a661e50331ba6f5a0775117e3b89732b873d5d77c7852151c58d3a43e6ca9bf731c9ef9826a2d5fe30e68116b60a335204ab5dfc6d29'
|
7
|
+
data.tar.gz: 4af2596e05a71ac35f8b0bbe331b485a3297ecf1ea16d5c970aacc0660cf45c5a07d665d96c641089ae10619899bc815b44b523156962a8db13bf1601ea307d5
|
@@ -8,6 +8,14 @@ module Dependabot
|
|
8
8
|
class Azure
|
9
9
|
class NotFound < StandardError; end
|
10
10
|
|
11
|
+
class InternalServerError < StandardError; end
|
12
|
+
|
13
|
+
class ServiceNotAvailable < StandardError; end
|
14
|
+
|
15
|
+
class BadGateway < StandardError; end
|
16
|
+
|
17
|
+
RETRYABLE_ERRORS = [InternalServerError, BadGateway, ServiceNotAvailable].freeze
|
18
|
+
|
11
19
|
MAX_PR_DESCRIPTION_LENGTH = 3999
|
12
20
|
|
13
21
|
#######################
|
@@ -27,10 +35,11 @@ module Dependabot
|
|
27
35
|
# Client #
|
28
36
|
##########
|
29
37
|
|
30
|
-
def initialize(source, credentials)
|
38
|
+
def initialize(source, credentials, max_retries: 3)
|
31
39
|
@source = source
|
32
40
|
@credentials = credentials
|
33
41
|
@auth_header = auth_header_for(credentials&.fetch("token", nil))
|
42
|
+
@max_retries = max_retries || 3
|
34
43
|
end
|
35
44
|
|
36
45
|
def fetch_commit(_repo, branch)
|
@@ -175,15 +184,24 @@ module Dependabot
|
|
175
184
|
# rubocop:enable Metrics/ParameterLists
|
176
185
|
|
177
186
|
def get(url)
|
178
|
-
response =
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
187
|
+
response = nil
|
188
|
+
|
189
|
+
retry_connection_failures do
|
190
|
+
response = Excon.get(
|
191
|
+
url,
|
192
|
+
user: credentials&.fetch("username", nil),
|
193
|
+
password: credentials&.fetch("password", nil),
|
194
|
+
idempotent: true,
|
195
|
+
**SharedHelpers.excon_defaults(
|
196
|
+
headers: auth_header
|
197
|
+
)
|
185
198
|
)
|
186
|
-
|
199
|
+
|
200
|
+
raise InternalServerError if response.status == 500
|
201
|
+
raise BadGateway if response.status == 502
|
202
|
+
raise ServiceNotAvailable if response.status == 503
|
203
|
+
end
|
204
|
+
|
187
205
|
raise NotFound if response.status == 404
|
188
206
|
|
189
207
|
response
|
@@ -211,6 +229,17 @@ module Dependabot
|
|
211
229
|
|
212
230
|
private
|
213
231
|
|
232
|
+
def retry_connection_failures
|
233
|
+
retry_attempt = 0
|
234
|
+
|
235
|
+
begin
|
236
|
+
yield
|
237
|
+
rescue *RETRYABLE_ERRORS
|
238
|
+
retry_attempt += 1
|
239
|
+
retry_attempt <= @max_retries ? retry : raise
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
214
243
|
def auth_header_for(token)
|
215
244
|
return {} unless token
|
216
245
|
|
@@ -12,12 +12,26 @@ module Dependabot
|
|
12
12
|
|
13
13
|
class Forbidden < StandardError; end
|
14
14
|
|
15
|
+
#######################
|
16
|
+
# Constructor methods #
|
17
|
+
#######################
|
18
|
+
|
19
|
+
def self.for_source(source:, credentials:)
|
20
|
+
credential =
|
21
|
+
credentials.
|
22
|
+
select { |cred| cred["type"] == "git_source" }.
|
23
|
+
find { |cred| cred["host"] == source.hostname }
|
24
|
+
|
25
|
+
new(credentials: credential)
|
26
|
+
end
|
27
|
+
|
15
28
|
##########
|
16
29
|
# Client #
|
17
30
|
##########
|
18
31
|
|
19
32
|
def initialize(credentials:)
|
20
33
|
@credentials = credentials
|
34
|
+
@auth_header = auth_header_for(credentials&.fetch("token", nil))
|
21
35
|
end
|
22
36
|
|
23
37
|
def fetch_commit(repo, branch)
|
@@ -52,6 +66,81 @@ module Dependabot
|
|
52
66
|
response.body
|
53
67
|
end
|
54
68
|
|
69
|
+
def commits(repo, branch_name = nil)
|
70
|
+
commits_path = "#{repo}/commits/#{branch_name}?pagelen=100"
|
71
|
+
next_page_url = base_url + commits_path
|
72
|
+
paginate({ "next" => next_page_url })
|
73
|
+
end
|
74
|
+
|
75
|
+
def branch(repo, branch_name)
|
76
|
+
branch_path = "#{repo}/refs/branches/#{branch_name}"
|
77
|
+
response = get(base_url + branch_path)
|
78
|
+
|
79
|
+
JSON.parse(response.body)
|
80
|
+
end
|
81
|
+
|
82
|
+
def pull_requests(repo, source_branch, target_branch)
|
83
|
+
pr_path = "#{repo}/pullrequests"
|
84
|
+
# Get pull requests with any status
|
85
|
+
pr_path += "?status=OPEN&status=MERGED&status=DECLINED&status=SUPERSEDED"
|
86
|
+
next_page_url = base_url + pr_path
|
87
|
+
pull_requests = paginate({ "next" => next_page_url })
|
88
|
+
|
89
|
+
pull_requests unless source_branch && target_branch
|
90
|
+
|
91
|
+
pull_requests.select do |pr|
|
92
|
+
pr_source_branch = pr.fetch("source").fetch("branch").fetch("name")
|
93
|
+
pr_target_branch = pr.fetch("destination").fetch("branch").fetch("name")
|
94
|
+
pr_source_branch == source_branch && pr_target_branch == target_branch
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# rubocop:disable Metrics/ParameterLists
|
99
|
+
def create_commit(repo, branch_name, base_commit, commit_message, files,
|
100
|
+
author_details)
|
101
|
+
parameters = {
|
102
|
+
message: commit_message, # TODO: Format markup in commit message
|
103
|
+
author: "#{author_details.fetch(:name)} <#{author_details.fetch(:email)}>",
|
104
|
+
parents: base_commit,
|
105
|
+
branch: branch_name
|
106
|
+
}
|
107
|
+
|
108
|
+
files.each do |file|
|
109
|
+
absolute_path = file.name.start_with?("/") ? file.name : "/" + file.name
|
110
|
+
parameters[absolute_path] = file.content
|
111
|
+
end
|
112
|
+
|
113
|
+
body = encode_form_parameters(parameters)
|
114
|
+
|
115
|
+
commit_path = "#{repo}/src"
|
116
|
+
post(base_url + commit_path, body, "application/x-www-form-urlencoded")
|
117
|
+
end
|
118
|
+
# rubocop:enable Metrics/ParameterLists
|
119
|
+
|
120
|
+
# rubocop:disable Metrics/ParameterLists
|
121
|
+
def create_pull_request(repo, pr_name, source_branch, target_branch,
|
122
|
+
pr_description, _labels, _work_item = nil)
|
123
|
+
content = {
|
124
|
+
title: pr_name,
|
125
|
+
source: {
|
126
|
+
branch: {
|
127
|
+
name: source_branch
|
128
|
+
}
|
129
|
+
},
|
130
|
+
destination: {
|
131
|
+
branch: {
|
132
|
+
name: target_branch
|
133
|
+
}
|
134
|
+
},
|
135
|
+
description: pr_description,
|
136
|
+
close_source_branch: true
|
137
|
+
}
|
138
|
+
|
139
|
+
pr_path = "#{repo}/pullrequests"
|
140
|
+
post(base_url + pr_path, content.to_json)
|
141
|
+
end
|
142
|
+
# rubocop:enable Metrics/ParameterLists
|
143
|
+
|
55
144
|
def tags(repo)
|
56
145
|
path = "#{repo}/refs/tags?pagelen=100"
|
57
146
|
response = get(base_url + path)
|
@@ -72,7 +161,9 @@ module Dependabot
|
|
72
161
|
user: credentials&.fetch("username", nil),
|
73
162
|
password: credentials&.fetch("password", nil),
|
74
163
|
idempotent: true,
|
75
|
-
**Dependabot::SharedHelpers.excon_defaults
|
164
|
+
**Dependabot::SharedHelpers.excon_defaults(
|
165
|
+
headers: auth_header
|
166
|
+
)
|
76
167
|
)
|
77
168
|
raise Unauthorized if response.status == 401
|
78
169
|
raise Forbidden if response.status == 403
|
@@ -87,8 +178,68 @@ module Dependabot
|
|
87
178
|
response
|
88
179
|
end
|
89
180
|
|
181
|
+
def post(url, body, content_type = "application/json")
|
182
|
+
response = Excon.post(
|
183
|
+
url,
|
184
|
+
body: body,
|
185
|
+
user: credentials&.fetch("username", nil),
|
186
|
+
password: credentials&.fetch("password", nil),
|
187
|
+
idempotent: false,
|
188
|
+
**SharedHelpers.excon_defaults(
|
189
|
+
headers: auth_header.merge(
|
190
|
+
{
|
191
|
+
"Content-Type" => content_type
|
192
|
+
}
|
193
|
+
)
|
194
|
+
)
|
195
|
+
)
|
196
|
+
raise Unauthorized if response.status == 401
|
197
|
+
raise Forbidden if response.status == 403
|
198
|
+
raise NotFound if response.status == 404
|
199
|
+
|
200
|
+
response
|
201
|
+
end
|
202
|
+
|
90
203
|
private
|
91
204
|
|
205
|
+
def auth_header_for(token)
|
206
|
+
return {} unless token
|
207
|
+
|
208
|
+
{ "Authorization" => "Bearer #{token}" }
|
209
|
+
end
|
210
|
+
|
211
|
+
def encode_form_parameters(parameters)
|
212
|
+
parameters.map do |key, value|
|
213
|
+
URI.encode_www_form_component(key.to_s) + "=" + URI.encode_www_form_component(value.to_s)
|
214
|
+
end.join("&")
|
215
|
+
end
|
216
|
+
|
217
|
+
# Takes a hash with optional `values` and `next` fields
|
218
|
+
# Returns an enumerator.
|
219
|
+
#
|
220
|
+
# Can be used a few ways:
|
221
|
+
# With GET:
|
222
|
+
# paginate ({"next" => url})
|
223
|
+
# or
|
224
|
+
# paginate(JSON.parse(get(url).body))
|
225
|
+
#
|
226
|
+
# With POST (for endpoints that provide POST methods for long query parameters)
|
227
|
+
# response = post(url, body)
|
228
|
+
# first_page = JSON.parse(repsonse.body)
|
229
|
+
# paginate(first_page)
|
230
|
+
def paginate(page)
|
231
|
+
Enumerator.new do |yielder|
|
232
|
+
loop do
|
233
|
+
page.fetch("values", []).each { |value| yielder << value }
|
234
|
+
break unless page.key?("next")
|
235
|
+
|
236
|
+
next_page_url = page.fetch("next")
|
237
|
+
page = JSON.parse(get(next_page_url).body)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
attr_reader :auth_header
|
92
243
|
attr_reader :credentials
|
93
244
|
|
94
245
|
def base_url
|
data/lib/dependabot/errors.rb
CHANGED
@@ -1,24 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dependabot/
|
3
|
+
require "dependabot/utils"
|
4
4
|
|
5
5
|
module Dependabot
|
6
6
|
class DependabotError < StandardError
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
BASIC_AUTH_REGEX = %r{://(?<auth>[^:]*:[^@%\s]+(@|%40))}.freeze
|
8
|
+
# Remove any path segment from fury.io sources
|
9
|
+
FURY_IO_PATH_REGEX = %r{fury\.io/(?<path>.+)}.freeze
|
10
|
+
|
11
|
+
def initialize(message = nil)
|
12
|
+
super(sanitize_message(message))
|
10
13
|
end
|
11
14
|
|
12
15
|
private
|
13
16
|
|
14
17
|
def sanitize_message(message)
|
15
|
-
return unless message
|
18
|
+
return message unless message.is_a?(String)
|
16
19
|
|
17
20
|
path_regex =
|
18
|
-
Regexp.escape(
|
19
|
-
Regexp.escape(
|
21
|
+
Regexp.escape(Utils::BUMP_TMP_DIR_PATH) + "\/" +
|
22
|
+
Regexp.escape(Utils::BUMP_TMP_FILE_PREFIX) + "[a-zA-Z0-9-]*"
|
23
|
+
|
24
|
+
message = message.gsub(/#{path_regex}/, "dependabot_tmp_dir").strip
|
25
|
+
filter_sensitive_data(message)
|
26
|
+
end
|
27
|
+
|
28
|
+
def filter_sensitive_data(message)
|
29
|
+
replace_capture_groups(message, BASIC_AUTH_REGEX, "")
|
30
|
+
end
|
31
|
+
|
32
|
+
def sanitize_source(source)
|
33
|
+
source = filter_sensitive_data(source)
|
34
|
+
replace_capture_groups(source, FURY_IO_PATH_REGEX, "<redacted>")
|
35
|
+
end
|
36
|
+
|
37
|
+
def replace_capture_groups(string, regex, replacement)
|
38
|
+
return string unless string.is_a?(String)
|
20
39
|
|
21
|
-
|
40
|
+
string.scan(regex).flatten.compact.reduce(string) do |original_msg, match|
|
41
|
+
original_msg.gsub(match, replacement)
|
42
|
+
end
|
22
43
|
end
|
23
44
|
end
|
24
45
|
|
@@ -35,7 +56,6 @@ module Dependabot
|
|
35
56
|
|
36
57
|
def initialize(branch_name, msg = nil)
|
37
58
|
@branch_name = branch_name
|
38
|
-
msg = sanitize_message(msg)
|
39
59
|
super(msg)
|
40
60
|
end
|
41
61
|
end
|
@@ -101,10 +121,10 @@ module Dependabot
|
|
101
121
|
attr_reader :source
|
102
122
|
|
103
123
|
def initialize(source)
|
104
|
-
@source = source
|
124
|
+
@source = sanitize_source(source)
|
105
125
|
msg = "The following source could not be reached as it requires "\
|
106
126
|
"authentication (and any provided details were invalid or lacked "\
|
107
|
-
"the required permissions): #{source}"
|
127
|
+
"the required permissions): #{@source}"
|
108
128
|
super(msg)
|
109
129
|
end
|
110
130
|
end
|
@@ -113,8 +133,8 @@ module Dependabot
|
|
113
133
|
attr_reader :source
|
114
134
|
|
115
135
|
def initialize(source)
|
116
|
-
@source = source
|
117
|
-
super("The following source timed out: #{source}")
|
136
|
+
@source = sanitize_source(source)
|
137
|
+
super("The following source timed out: #{@source}")
|
118
138
|
end
|
119
139
|
end
|
120
140
|
|
@@ -122,8 +142,8 @@ module Dependabot
|
|
122
142
|
attr_reader :source
|
123
143
|
|
124
144
|
def initialize(source)
|
125
|
-
@source = source
|
126
|
-
super("Could not verify the SSL certificate for #{source}")
|
145
|
+
@source = sanitize_source(source)
|
146
|
+
super("Could not verify the SSL certificate for #{@source}")
|
127
147
|
end
|
128
148
|
end
|
129
149
|
|
@@ -132,7 +152,7 @@ module Dependabot
|
|
132
152
|
|
133
153
|
def initialize(environment_variable)
|
134
154
|
@environment_variable = environment_variable
|
135
|
-
super("Missing environment variable #{environment_variable}")
|
155
|
+
super("Missing environment variable #{@environment_variable}")
|
136
156
|
end
|
137
157
|
end
|
138
158
|
|
@@ -149,10 +169,10 @@ module Dependabot
|
|
149
169
|
|
150
170
|
def initialize(*dependency_urls)
|
151
171
|
@dependency_urls =
|
152
|
-
dependency_urls.flatten.map { |uri| uri
|
172
|
+
dependency_urls.flatten.map { |uri| filter_sensitive_data(uri) }
|
153
173
|
|
154
174
|
msg = "The following git URLs could not be retrieved: "\
|
155
|
-
"#{dependency_urls.join(', ')}"
|
175
|
+
"#{@dependency_urls.join(', ')}"
|
156
176
|
super(msg)
|
157
177
|
end
|
158
178
|
end
|
@@ -163,7 +183,7 @@ module Dependabot
|
|
163
183
|
def initialize(dependency)
|
164
184
|
@dependency = dependency
|
165
185
|
|
166
|
-
msg = "The branch or reference specified for #{dependency} could not "\
|
186
|
+
msg = "The branch or reference specified for #{@dependency} could not "\
|
167
187
|
"be retrieved"
|
168
188
|
super(msg)
|
169
189
|
end
|
@@ -175,7 +195,7 @@ module Dependabot
|
|
175
195
|
def initialize(*dependencies)
|
176
196
|
@dependencies = dependencies.flatten
|
177
197
|
msg = "The following path based dependencies could not be retrieved: "\
|
178
|
-
"#{dependencies.join(', ')}"
|
198
|
+
"#{@dependencies.join(', ')}"
|
179
199
|
super(msg)
|
180
200
|
end
|
181
201
|
end
|
@@ -188,8 +208,8 @@ module Dependabot
|
|
188
208
|
@declared_path = declared_path
|
189
209
|
@discovered_path = discovered_path
|
190
210
|
|
191
|
-
msg = "The module path '#{declared_path}' found in #{go_mod} doesn't "\
|
192
|
-
"match the actual path '#{discovered_path}' in the dependency's "\
|
211
|
+
msg = "The module path '#{@declared_path}' found in #{@go_mod} doesn't "\
|
212
|
+
"match the actual path '#{@discovered_path}' in the dependency's "\
|
193
213
|
"go.mod"
|
194
214
|
super(msg)
|
195
215
|
end
|
@@ -5,6 +5,7 @@ require "dependabot/metadata_finders"
|
|
5
5
|
module Dependabot
|
6
6
|
class PullRequestCreator
|
7
7
|
require "dependabot/pull_request_creator/azure"
|
8
|
+
require "dependabot/pull_request_creator/bitbucket"
|
8
9
|
require "dependabot/pull_request_creator/codecommit"
|
9
10
|
require "dependabot/pull_request_creator/github"
|
10
11
|
require "dependabot/pull_request_creator/gitlab"
|
@@ -88,6 +89,7 @@ module Dependabot
|
|
88
89
|
when "github" then github_creator.create
|
89
90
|
when "gitlab" then gitlab_creator.create
|
90
91
|
when "azure" then azure_creator.create
|
92
|
+
when "bitbucket" then bitbucket_creator.create
|
91
93
|
when "codecommit" then codecommit_creator.create
|
92
94
|
else raise "Unsupported provider #{source.provider}"
|
93
95
|
end
|
@@ -162,6 +164,22 @@ module Dependabot
|
|
162
164
|
)
|
163
165
|
end
|
164
166
|
|
167
|
+
def bitbucket_creator
|
168
|
+
Bitbucket.new(
|
169
|
+
source: source,
|
170
|
+
branch_name: branch_namer.new_branch_name,
|
171
|
+
base_commit: base_commit,
|
172
|
+
credentials: credentials,
|
173
|
+
files: files,
|
174
|
+
commit_message: message_builder.commit_message,
|
175
|
+
pr_description: message_builder.pr_message,
|
176
|
+
pr_name: message_builder.pr_name,
|
177
|
+
author_details: author_details,
|
178
|
+
labeler: labeler,
|
179
|
+
work_item: provider_metadata&.fetch(:work_item, nil)
|
180
|
+
)
|
181
|
+
end
|
182
|
+
|
165
183
|
def codecommit_creator
|
166
184
|
Codecommit.new(
|
167
185
|
source: source,
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dependabot/clients/bitbucket"
|
4
|
+
require "dependabot/pull_request_creator"
|
5
|
+
|
6
|
+
module Dependabot
|
7
|
+
class PullRequestCreator
|
8
|
+
class Bitbucket
|
9
|
+
attr_reader :source, :branch_name, :base_commit, :credentials,
|
10
|
+
:files, :commit_message, :pr_description, :pr_name,
|
11
|
+
:author_details, :labeler, :work_item
|
12
|
+
|
13
|
+
def initialize(source:, branch_name:, base_commit:, credentials:,
|
14
|
+
files:, commit_message:, pr_description:, pr_name:,
|
15
|
+
author_details:, labeler: nil, work_item: nil)
|
16
|
+
@source = source
|
17
|
+
@branch_name = branch_name
|
18
|
+
@base_commit = base_commit
|
19
|
+
@credentials = credentials
|
20
|
+
@files = files
|
21
|
+
@commit_message = commit_message
|
22
|
+
@pr_description = pr_description
|
23
|
+
@pr_name = pr_name
|
24
|
+
@author_details = author_details
|
25
|
+
@labeler = labeler
|
26
|
+
@work_item = work_item
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
return if branch_exists? && pull_request_exists?
|
31
|
+
|
32
|
+
# FIXME: Copied from Azure, but not verified whether this is true
|
33
|
+
# For Bitbucket we create or update a branch in the same request as creating
|
34
|
+
# a commit (so we don't need create or update branch logic here)
|
35
|
+
create_commit
|
36
|
+
|
37
|
+
create_pull_request
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def bitbucket_client_for_source
|
43
|
+
@bitbucket_client_for_source ||=
|
44
|
+
Dependabot::Clients::Bitbucket.for_source(
|
45
|
+
source: source,
|
46
|
+
credentials: credentials
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def branch_exists?
|
51
|
+
bitbucket_client_for_source.branch(source.repo, branch_name)
|
52
|
+
rescue Clients::Bitbucket::NotFound
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def pull_request_exists?
|
57
|
+
bitbucket_client_for_source.pull_requests(
|
58
|
+
source.repo,
|
59
|
+
branch_name,
|
60
|
+
source.branch || default_branch
|
61
|
+
).any?
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_commit
|
65
|
+
author = author_details&.slice(:name, :email)
|
66
|
+
author = nil unless author&.any?
|
67
|
+
|
68
|
+
bitbucket_client_for_source.create_commit(
|
69
|
+
source.repo,
|
70
|
+
branch_name,
|
71
|
+
base_commit,
|
72
|
+
commit_message,
|
73
|
+
files,
|
74
|
+
author
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_pull_request
|
79
|
+
bitbucket_client_for_source.create_pull_request(
|
80
|
+
source.repo,
|
81
|
+
pr_name,
|
82
|
+
branch_name,
|
83
|
+
source.branch || default_branch,
|
84
|
+
pr_description,
|
85
|
+
labeler&.labels_for_pr,
|
86
|
+
work_item
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
def default_branch
|
91
|
+
@default_branch ||=
|
92
|
+
bitbucket_client_for_source.fetch_default_branch(source.repo)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "dependabot/clients/azure"
|
4
|
+
require "dependabot/clients/bitbucket"
|
4
5
|
require "dependabot/clients/codecommit"
|
5
6
|
require "dependabot/clients/github_with_retries"
|
6
7
|
require "dependabot/clients/gitlab_with_retries"
|
@@ -264,6 +265,7 @@ module Dependabot
|
|
264
265
|
when "github" then recent_github_commit_messages
|
265
266
|
when "gitlab" then recent_gitlab_commit_messages
|
266
267
|
when "azure" then recent_azure_commit_messages
|
268
|
+
when "bitbucket" then recent_bitbucket_commit_messages
|
267
269
|
when "codecommit" then recent_codecommit_commit_messages
|
268
270
|
else raise "Unsupported provider: #{source.provider}"
|
269
271
|
end
|
@@ -307,6 +309,18 @@ module Dependabot
|
|
307
309
|
map(&:strip)
|
308
310
|
end
|
309
311
|
|
312
|
+
def recent_bitbucket_commit_messages
|
313
|
+
@recent_bitbucket_commit_messages ||=
|
314
|
+
bitbucket_client_for_source.commits(source.repo)
|
315
|
+
|
316
|
+
@recent_bitbucket_commit_messages.
|
317
|
+
reject { |c| bitbucket_commit_author_email(c) == dependabot_email }.
|
318
|
+
map { |c| c.fetch("message", nil) }.
|
319
|
+
compact.
|
320
|
+
reject { |m| m.start_with?("Merge") }.
|
321
|
+
map(&:strip)
|
322
|
+
end
|
323
|
+
|
310
324
|
def recent_codecommit_commit_messages
|
311
325
|
@recent_codecommit_commit_messages ||=
|
312
326
|
codecommit_client_for_source.commits
|
@@ -324,6 +338,7 @@ module Dependabot
|
|
324
338
|
when "github" then last_github_dependabot_commit_message
|
325
339
|
when "gitlab" then last_gitlab_dependabot_commit_message
|
326
340
|
when "azure" then last_azure_dependabot_commit_message
|
341
|
+
when "bitbucket" then last_bitbucket_dependabot_commit_message
|
327
342
|
when "codecommit" then last_codecommit_dependabot_commit_message
|
328
343
|
else raise "Unsupported provider: #{source.provider}"
|
329
344
|
end
|
@@ -365,6 +380,16 @@ module Dependabot
|
|
365
380
|
strip
|
366
381
|
end
|
367
382
|
|
383
|
+
def last_bitbucket_dependabot_commit_message
|
384
|
+
@recent_bitbucket_commit_messages ||=
|
385
|
+
bitbucket_client_for_source.commits(source.repo)
|
386
|
+
|
387
|
+
@recent_bitbucket_commit_messages.
|
388
|
+
find { |c| bitbucket_commit_author_email(c) == dependabot_email }&.
|
389
|
+
fetch("message", nil)&.
|
390
|
+
strip
|
391
|
+
end
|
392
|
+
|
368
393
|
def last_codecommit_dependabot_commit_message
|
369
394
|
@recent_codecommit_commit_messages ||=
|
370
395
|
codecommit_client_for_source.commits(source.repo)
|
@@ -379,6 +404,11 @@ module Dependabot
|
|
379
404
|
commit.fetch("author").fetch("email", "")
|
380
405
|
end
|
381
406
|
|
407
|
+
def bitbucket_commit_author_email(commit)
|
408
|
+
matches = commit.fetch("author").fetch("raw").match(/<(.*)>/)
|
409
|
+
matches ? matches[1] : ""
|
410
|
+
end
|
411
|
+
|
382
412
|
def github_client_for_source
|
383
413
|
@github_client_for_source ||=
|
384
414
|
Dependabot::Clients::GithubWithRetries.for_source(
|
@@ -403,6 +433,14 @@ module Dependabot
|
|
403
433
|
)
|
404
434
|
end
|
405
435
|
|
436
|
+
def bitbucket_client_for_source
|
437
|
+
@bitbucket_client_for_source ||=
|
438
|
+
Dependabot::Clients::Bitbucket.for_source(
|
439
|
+
source: source,
|
440
|
+
credentials: credentials
|
441
|
+
)
|
442
|
+
end
|
443
|
+
|
406
444
|
def codecommit_client_for_source
|
407
445
|
@codecommit_client_for_source ||=
|
408
446
|
Dependabot::Clients::CodeCommit.for_source(
|
@@ -8,12 +8,12 @@ require "digest"
|
|
8
8
|
require "open3"
|
9
9
|
require "shellwords"
|
10
10
|
|
11
|
+
require "dependabot/utils"
|
12
|
+
require "dependabot/errors"
|
11
13
|
require "dependabot/version"
|
12
14
|
|
13
15
|
module Dependabot
|
14
16
|
module SharedHelpers
|
15
|
-
BUMP_TMP_FILE_PREFIX = "dependabot_"
|
16
|
-
BUMP_TMP_DIR_PATH = "tmp"
|
17
17
|
GIT_CONFIG_GLOBAL_PATH = File.expand_path("~/.gitconfig")
|
18
18
|
USER_AGENT = "dependabot-core/#{Dependabot::VERSION} "\
|
19
19
|
"#{Excon::USER_AGENT} ruby/#{RUBY_VERSION} "\
|
@@ -21,21 +21,6 @@ module Dependabot
|
|
21
21
|
"(+https://github.com/dependabot/dependabot-core)"
|
22
22
|
SIGKILL = 9
|
23
23
|
|
24
|
-
class ChildProcessFailed < StandardError
|
25
|
-
attr_reader :error_class, :error_message, :error_backtrace
|
26
|
-
|
27
|
-
def initialize(error_class:, error_message:, error_backtrace:)
|
28
|
-
@error_class = error_class
|
29
|
-
@error_message = error_message
|
30
|
-
@error_backtrace = error_backtrace
|
31
|
-
|
32
|
-
msg = "Child process raised #{error_class} with message: "\
|
33
|
-
"#{error_message}"
|
34
|
-
super(msg)
|
35
|
-
set_backtrace(error_backtrace)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
24
|
def self.in_a_temporary_repo_directory(directory = "/",
|
40
25
|
repo_contents_path = nil,
|
41
26
|
&block)
|
@@ -53,15 +38,15 @@ module Dependabot
|
|
53
38
|
end
|
54
39
|
|
55
40
|
def self.in_a_temporary_directory(directory = "/")
|
56
|
-
Dir.mkdir(BUMP_TMP_DIR_PATH) unless Dir.exist?(BUMP_TMP_DIR_PATH)
|
57
|
-
Dir.mktmpdir(BUMP_TMP_FILE_PREFIX, BUMP_TMP_DIR_PATH) do |dir|
|
41
|
+
Dir.mkdir(Utils::BUMP_TMP_DIR_PATH) unless Dir.exist?(Utils::BUMP_TMP_DIR_PATH)
|
42
|
+
Dir.mktmpdir(Utils::BUMP_TMP_FILE_PREFIX, Utils::BUMP_TMP_DIR_PATH) do |dir|
|
58
43
|
path = Pathname.new(File.join(dir, directory)).expand_path
|
59
44
|
FileUtils.mkpath(path)
|
60
45
|
Dir.chdir(path) { yield(path) }
|
61
46
|
end
|
62
47
|
end
|
63
48
|
|
64
|
-
class HelperSubprocessFailed <
|
49
|
+
class HelperSubprocessFailed < Dependabot::DependabotError
|
65
50
|
attr_reader :error_class, :error_context, :trace
|
66
51
|
|
67
52
|
def initialize(message:, error_context:, error_class: nil, trace: nil)
|
data/lib/dependabot/utils.rb
CHANGED
data/lib/dependabot/version.rb
CHANGED
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.129.
|
4
|
+
version: 0.129.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dependabot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-codecommit
|
@@ -168,34 +168,26 @@ dependencies:
|
|
168
168
|
- - "~>"
|
169
169
|
- !ruby/object:Gem::Version
|
170
170
|
version: '2.0'
|
171
|
-
- !ruby/object:Gem::Dependency
|
172
|
-
name: parseconfig
|
173
|
-
requirement: !ruby/object:Gem::Requirement
|
174
|
-
requirements:
|
175
|
-
- - "~>"
|
176
|
-
- !ruby/object:Gem::Version
|
177
|
-
version: '1.0'
|
178
|
-
type: :runtime
|
179
|
-
prerelease: false
|
180
|
-
version_requirements: !ruby/object:Gem::Requirement
|
181
|
-
requirements:
|
182
|
-
- - "~>"
|
183
|
-
- !ruby/object:Gem::Version
|
184
|
-
version: '1.0'
|
185
171
|
- !ruby/object:Gem::Dependency
|
186
172
|
name: parser
|
187
173
|
requirement: !ruby/object:Gem::Requirement
|
188
174
|
requirements:
|
189
|
-
- - "
|
175
|
+
- - ">="
|
190
176
|
- !ruby/object:Gem::Version
|
191
177
|
version: '2.5'
|
178
|
+
- - "<"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '4.0'
|
192
181
|
type: :runtime
|
193
182
|
prerelease: false
|
194
183
|
version_requirements: !ruby/object:Gem::Requirement
|
195
184
|
requirements:
|
196
|
-
- - "
|
185
|
+
- - ">="
|
197
186
|
- !ruby/object:Gem::Version
|
198
187
|
version: '2.5'
|
188
|
+
- - "<"
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '4.0'
|
199
191
|
- !ruby/object:Gem::Dependency
|
200
192
|
name: toml-rb
|
201
193
|
requirement: !ruby/object:Gem::Requirement
|
@@ -292,28 +284,28 @@ dependencies:
|
|
292
284
|
requirements:
|
293
285
|
- - "~>"
|
294
286
|
- !ruby/object:Gem::Version
|
295
|
-
version: 1.
|
287
|
+
version: 1.7.0
|
296
288
|
type: :development
|
297
289
|
prerelease: false
|
298
290
|
version_requirements: !ruby/object:Gem::Requirement
|
299
291
|
requirements:
|
300
292
|
- - "~>"
|
301
293
|
- !ruby/object:Gem::Version
|
302
|
-
version: 1.
|
294
|
+
version: 1.7.0
|
303
295
|
- !ruby/object:Gem::Dependency
|
304
296
|
name: simplecov
|
305
297
|
requirement: !ruby/object:Gem::Requirement
|
306
298
|
requirements:
|
307
299
|
- - "~>"
|
308
300
|
- !ruby/object:Gem::Version
|
309
|
-
version: 0.
|
301
|
+
version: 0.21.0
|
310
302
|
type: :development
|
311
303
|
prerelease: false
|
312
304
|
version_requirements: !ruby/object:Gem::Requirement
|
313
305
|
requirements:
|
314
306
|
- - "~>"
|
315
307
|
- !ruby/object:Gem::Version
|
316
|
-
version: 0.
|
308
|
+
version: 0.21.0
|
317
309
|
- !ruby/object:Gem::Dependency
|
318
310
|
name: simplecov-console
|
319
311
|
requirement: !ruby/object:Gem::Requirement
|
@@ -396,6 +388,7 @@ files:
|
|
396
388
|
- lib/dependabot/metadata_finders/base/release_finder.rb
|
397
389
|
- lib/dependabot/pull_request_creator.rb
|
398
390
|
- lib/dependabot/pull_request_creator/azure.rb
|
391
|
+
- lib/dependabot/pull_request_creator/bitbucket.rb
|
399
392
|
- lib/dependabot/pull_request_creator/branch_namer.rb
|
400
393
|
- lib/dependabot/pull_request_creator/codecommit.rb
|
401
394
|
- lib/dependabot/pull_request_creator/commit_signer.rb
|