dependabot-common 0.119.6 → 0.120.4

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.

Potentially problematic release.


This version of dependabot-common might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce4dd778f67c7a4f612edfbe2f1ef0bae78566f7c50a46212f0244745cf07da1
4
- data.tar.gz: 46f644e4de54337eb399265827d754e6ba82477603e046f42c6d79924b32cb86
3
+ metadata.gz: 71c52ab937193ccc6c472643fe327544840ce8b99d27454d9f06f77435b52f88
4
+ data.tar.gz: 5fd0a5e3350466bbf47ea7658caa77c656469f1de10aafb8a8308a3bdd848d71
5
5
  SHA512:
6
- metadata.gz: 73958fe712b9b38885ec5591114943367adec8cdb77af7efd9a7069261512b2b50b77d7c578335bf87e5f89bef934102c099dd1ec4353ecd075e0924a56d74d8
7
- data.tar.gz: 54e51527b3f98b0e2b722b1c2617344d4601fde8272986b02c60edc8e9b1525ccb1ea093efb18a02c259279f75cf3e7ce41d9d6e01641ccc3b675335c930026b
6
+ metadata.gz: 4d28541943c3f27dfee7688002d4c3bd692597f5870d9db512a4dd07510d0f48db033603172c044c9b713493549878e202130bd77b1a7272c7d51d246b86bf17
7
+ data.tar.gz: 22a0c6246d7d2494614498736f94295986b29d1adfe31c8442361559d4d957ba7b0a1f419355b079247391cc2be75ad3383c580da2fb4f7de8181f8476014b91
@@ -153,8 +153,9 @@ module Dependabot
153
153
  "/pushes?api-version=5.0", content.to_json)
154
154
  end
155
155
 
156
+ # rubocop:disable Metrics/ParameterLists
156
157
  def create_pull_request(pr_name, source_branch, target_branch,
157
- pr_description, labels)
158
+ pr_description, labels, work_item = nil)
158
159
  # Azure DevOps only support descriptions up to 4000 characters
159
160
  # https://developercommunity.visualstudio.com/content/problem/608770/remove-4000-character-limit-on-pull-request-descri.html
160
161
  azure_max_length = 3999
@@ -163,13 +164,15 @@ module Dependabot
163
164
  truncate_length = azure_max_length - truncated_msg.length
164
165
  pr_description = pr_description[0..truncate_length] + truncated_msg
165
166
  end
167
+ # rubocop:enable Metrics/ParameterLists
166
168
 
167
169
  content = {
168
170
  sourceRefName: "refs/heads/" + source_branch,
169
171
  targetRefName: "refs/heads/" + target_branch,
170
172
  title: pr_name,
171
173
  description: pr_description,
172
- labels: labels.map { |label| { name: label } }
174
+ labels: labels.map { |label| { name: label } },
175
+ workItemRefs: [{ id: work_item }]
173
176
  }
174
177
 
175
178
  post(source.api_endpoint +
@@ -181,11 +184,12 @@ module Dependabot
181
184
  def get(url)
182
185
  response = Excon.get(
183
186
  url,
184
- headers: auth_header,
185
187
  user: credentials&.fetch("username", nil),
186
188
  password: credentials&.fetch("password", nil),
187
189
  idempotent: true,
188
- **SharedHelpers.excon_defaults
190
+ **SharedHelpers.excon_defaults(
191
+ headers: auth_header
192
+ )
189
193
  )
190
194
  raise NotFound if response.status == 404
191
195
 
@@ -195,16 +199,17 @@ module Dependabot
195
199
  def post(url, json)
196
200
  response = Excon.post(
197
201
  url,
198
- headers: auth_header.merge(
199
- {
200
- "Content-Type" => "application/json"
201
- }
202
- ),
203
202
  body: json,
204
203
  user: credentials&.fetch("username", nil),
205
204
  password: credentials&.fetch("password", nil),
206
205
  idempotent: true,
207
- **SharedHelpers.excon_defaults
206
+ **SharedHelpers.excon_defaults(
207
+ headers: auth_header.merge(
208
+ {
209
+ "Content-Type" => "application/json"
210
+ }
211
+ )
212
+ )
208
213
  )
209
214
  raise NotFound if response.status == 404
210
215
 
@@ -14,7 +14,7 @@ require "dependabot/shared_helpers"
14
14
  module Dependabot
15
15
  module FileFetchers
16
16
  class Base
17
- attr_reader :source, :credentials
17
+ attr_reader :source, :credentials, :repo_contents_path
18
18
 
19
19
  CLIENT_NOT_FOUND_ERRORS = [
20
20
  Octokit::NotFound,
@@ -32,10 +32,19 @@ module Dependabot
32
32
  raise NotImplementedError
33
33
  end
34
34
 
35
- def initialize(source:, credentials:)
35
+ # Creates a new FileFetcher for retrieving `DependencyFile`s.
36
+ #
37
+ # Files are typically grabbed individually via the source's API.
38
+ # repo_contents_path is an optional empty directory that will be used
39
+ # to clone the entire source repository on first read.
40
+ #
41
+ # If provided, file _data_ will be loaded from the clone.
42
+ # Submodules and directory listings are _not_ currently supported
43
+ # by repo_contents_path and still use an API trip.
44
+ def initialize(source:, credentials:, repo_contents_path: nil)
36
45
  @source = source
37
46
  @credentials = credentials
38
-
47
+ @repo_contents_path = repo_contents_path
39
48
  @linked_paths = {}
40
49
  end
41
50
 
@@ -68,14 +77,24 @@ module Dependabot
68
77
  end
69
78
 
70
79
  # Returns the path to the cloned repo
71
- def clone_repo_contents(target_directory: nil)
80
+ def clone_repo_contents
72
81
  @clone_repo_contents ||=
73
- _clone_repo_contents(target_directory: target_directory)
82
+ _clone_repo_contents(target_directory: repo_contents_path)
83
+ rescue Dependabot::SharedHelpers::HelperSubprocessFailed
84
+ raise Dependabot::RepoNotFound, source
74
85
  end
75
86
 
76
87
  private
77
88
 
78
89
  def fetch_file_if_present(filename, fetch_submodules: false)
90
+ unless repo_contents_path.nil?
91
+ begin
92
+ return load_cloned_file_if_present(filename)
93
+ rescue Dependabot::DependencyFileNotFound
94
+ return
95
+ end
96
+ end
97
+
79
98
  dir = File.dirname(filename)
80
99
  basename = File.basename(filename)
81
100
 
@@ -91,7 +110,35 @@ module Dependabot
91
110
  raise Dependabot::DependencyFileNotFound, path
92
111
  end
93
112
 
113
+ def load_cloned_file_if_present(filename)
114
+ path = Pathname.new(File.join(directory, filename)).cleanpath.to_path
115
+ repo_path = File.join(clone_repo_contents, path)
116
+ unless File.exist?(repo_path)
117
+ raise Dependabot::DependencyFileNotFound, path
118
+ end
119
+
120
+ content = File.read(repo_path)
121
+ type = if File.symlink?(repo_path)
122
+ symlink_target = File.readlink(repo_path)
123
+ "symlink"
124
+ else
125
+ "file"
126
+ end
127
+
128
+ DependencyFile.new(
129
+ name: Pathname.new(filename).cleanpath.to_path,
130
+ directory: directory,
131
+ type: type,
132
+ content: content,
133
+ symlink_target: symlink_target
134
+ )
135
+ end
136
+
94
137
  def fetch_file_from_host(filename, type: "file", fetch_submodules: false)
138
+ unless repo_contents_path.nil?
139
+ return load_cloned_file_if_present(filename)
140
+ end
141
+
95
142
  path = Pathname.new(File.join(directory, filename)).cleanpath.to_path
96
143
  content = _fetch_file_content(path, fetch_submodules: fetch_submodules)
97
144
  type = @linked_paths.key?(path.gsub(%r{^/}, "")) ? "symlink" : type
@@ -183,7 +183,7 @@ module Dependabot
183
183
 
184
184
  def excon_defaults
185
185
  # Some git hosts are slow when returning a large number of tags
186
- SharedHelpers.excon_defaults.merge(read_timeout: 20)
186
+ SharedHelpers.excon_defaults(read_timeout: 20)
187
187
  end
188
188
  end
189
189
  end
@@ -17,13 +17,23 @@ module Dependabot
17
17
  class RepoDisabled < StandardError; end
18
18
  class NoHistoryInCommon < StandardError; end
19
19
 
20
+ # AnnotationError is raised if a PR was created, but failed annotation
21
+ class AnnotationError < StandardError
22
+ attr_reader :cause, :pull_request
23
+ def initialize(cause, pull_request)
24
+ super(cause.message)
25
+ @cause = cause
26
+ @pull_request = pull_request
27
+ end
28
+ end
29
+
20
30
  attr_reader :source, :dependencies, :files, :base_commit,
21
31
  :credentials, :pr_message_header, :pr_message_footer,
22
32
  :custom_labels, :author_details, :signature_key,
23
33
  :commit_message_options, :vulnerabilities_fixed,
24
34
  :reviewers, :assignees, :milestone, :branch_name_separator,
25
35
  :branch_name_prefix, :github_redirection_service,
26
- :custom_headers
36
+ :custom_headers, :provider_metadata
27
37
 
28
38
  def initialize(source:, base_commit:, dependencies:, files:, credentials:,
29
39
  pr_message_header: nil, pr_message_footer: nil,
@@ -33,7 +43,8 @@ module Dependabot
33
43
  branch_name_separator: "/", branch_name_prefix: "dependabot",
34
44
  label_language: false, automerge_candidate: false,
35
45
  github_redirection_service: "github-redirect.dependabot.com",
36
- custom_headers: nil, require_up_to_date_base: false)
46
+ custom_headers: nil, require_up_to_date_base: false,
47
+ provider_metadata: {})
37
48
  @dependencies = dependencies
38
49
  @source = source
39
50
  @base_commit = base_commit
@@ -56,6 +67,7 @@ module Dependabot
56
67
  @github_redirection_service = github_redirection_service
57
68
  @custom_headers = custom_headers
58
69
  @require_up_to_date_base = require_up_to_date_base
70
+ @provider_metadata = provider_metadata
59
71
 
60
72
  check_dependencies_have_previous_version
61
73
  end
@@ -142,7 +154,8 @@ module Dependabot
142
154
  pr_description: message_builder.pr_message,
143
155
  pr_name: message_builder.pr_name,
144
156
  author_details: author_details,
145
- labeler: labeler
157
+ labeler: labeler,
158
+ work_item: provider_metadata&.fetch(:work_item, nil)
146
159
  )
147
160
  end
148
161
 
@@ -8,11 +8,11 @@ module Dependabot
8
8
  class Azure
9
9
  attr_reader :source, :branch_name, :base_commit, :credentials,
10
10
  :files, :commit_message, :pr_description, :pr_name,
11
- :author_details, :labeler
11
+ :author_details, :labeler, :work_item
12
12
 
13
13
  def initialize(source:, branch_name:, base_commit:, credentials:,
14
14
  files:, commit_message:, pr_description:, pr_name:,
15
- author_details:, labeler:)
15
+ author_details:, labeler:, work_item: nil)
16
16
  @source = source
17
17
  @branch_name = branch_name
18
18
  @base_commit = base_commit
@@ -23,6 +23,7 @@ module Dependabot
23
23
  @pr_name = pr_name
24
24
  @author_details = author_details
25
25
  @labeler = labeler
26
+ @work_item = work_item
26
27
  end
27
28
 
28
29
  def create
@@ -46,9 +47,7 @@ module Dependabot
46
47
  end
47
48
 
48
49
  def branch_exists?
49
- @branch_ref ||= azure_client_for_source.branch(branch_name)
50
-
51
- @branch_ref
50
+ azure_client_for_source.branch(branch_name)
52
51
  rescue ::Azure::Error::NotFound
53
52
  false
54
53
  end
@@ -79,7 +78,8 @@ module Dependabot
79
78
  branch_name,
80
79
  source.branch || default_branch,
81
80
  pr_description,
82
- labeler.labels_for_pr
81
+ labeler.labels_for_pr,
82
+ work_item
83
83
  )
84
84
  end
85
85
 
@@ -7,6 +7,7 @@ require "dependabot/pull_request_creator"
7
7
  require "dependabot/pull_request_creator/commit_signer"
8
8
  module Dependabot
9
9
  class PullRequestCreator
10
+ # rubocop:disable Metrics/ClassLength
10
11
  class Github
11
12
  attr_reader :source, :branch_name, :base_commit, :credentials,
12
13
  :files, :pr_description, :pr_name, :commit_message,
@@ -41,7 +42,7 @@ module Dependabot
41
42
  return if require_up_to_date_base? && !base_commit_is_up_to_date?
42
43
 
43
44
  create_annotated_pull_request
44
- rescue Octokit::Error => e
45
+ rescue AnnotationError, Octokit::Error => e
45
46
  handle_error(e)
46
47
  end
47
48
 
@@ -111,7 +112,11 @@ module Dependabot
111
112
  pull_request = create_pull_request
112
113
  return unless pull_request
113
114
 
114
- annotate_pull_request(pull_request)
115
+ begin
116
+ annotate_pull_request(pull_request)
117
+ rescue StandardError => e
118
+ raise AnnotationError.new(e, pull_request)
119
+ end
115
120
 
116
121
  pull_request
117
122
  end
@@ -417,24 +422,49 @@ module Dependabot
417
422
  end
418
423
 
419
424
  def handle_error(err)
420
- case err
425
+ cause = case err
426
+ when AnnotationError
427
+ err.cause
428
+ else
429
+ err
430
+ end
431
+
432
+ case cause
421
433
  when Octokit::Forbidden
422
- raise RepoDisabled, err.message if err.message.include?("disabled")
423
- raise RepoArchived, err.message if err.message.include?("archived")
434
+ if err.message.include?("disabled")
435
+ raise_custom_error err, RepoDisabled, err.message
436
+ elsif err.message.include?("archived")
437
+ raise_custom_error err, RepoArchived, err.message
438
+ end
424
439
 
425
440
  raise err
426
441
  when Octokit::NotFound
427
442
  raise err if repo_exists?
428
443
 
429
- raise RepoNotFound, err.message
444
+ raise_custom_error err, RepoNotFound, err.message
430
445
  when Octokit::UnprocessableEntity
431
- raise err unless err.message.include?("no history in common")
446
+ if err.message.include?("no history in common")
447
+ raise_custom_error err, NoHistoryInCommon, err.message
448
+ end
432
449
 
433
- raise NoHistoryInCommon, err.message
450
+ raise err
434
451
  else
435
452
  raise err
436
453
  end
437
454
  end
455
+
456
+ def raise_custom_error(base_err, type, message)
457
+ case base_err
458
+ when AnnotationError
459
+ raise AnnotationError.new(
460
+ type.new(message),
461
+ base_err.pull_request
462
+ )
463
+ else
464
+ raise type, message
465
+ end
466
+ end
438
467
  end
468
+ # rubocop:enable Metrics/ClassLength
439
469
  end
440
470
  end
@@ -8,11 +8,17 @@ require "digest"
8
8
  require "open3"
9
9
  require "shellwords"
10
10
 
11
+ require "dependabot/version"
12
+
11
13
  module Dependabot
12
14
  module SharedHelpers
13
15
  BUMP_TMP_FILE_PREFIX = "dependabot_"
14
16
  BUMP_TMP_DIR_PATH = "tmp"
15
17
  GIT_CONFIG_GLOBAL_PATH = File.expand_path("~/.gitconfig")
18
+ USER_AGENT = "dependabot-core/#{Dependabot::VERSION} "\
19
+ "#{Excon::USER_AGENT} ruby/#{RUBY_VERSION} "\
20
+ "(#{RUBY_PLATFORM}) "\
21
+ "(+https://github.com/dependabot/dependabot-core)"
16
22
 
17
23
  class ChildProcessFailed < StandardError
18
24
  attr_reader :error_class, :error_message, :error_backtrace
@@ -138,14 +144,24 @@ module Dependabot
138
144
  [Excon::Middleware::RedirectFollower]
139
145
  end
140
146
 
141
- def self.excon_defaults
147
+ def self.excon_headers(headers = nil)
148
+ headers ||= {}
149
+ {
150
+ "User-Agent" => USER_AGENT
151
+ }.merge(headers)
152
+ end
153
+
154
+ def self.excon_defaults(options = nil)
155
+ options ||= {}
156
+ headers = options.delete(:headers)
142
157
  {
143
158
  connect_timeout: 5,
144
159
  write_timeout: 5,
145
160
  read_timeout: 20,
146
161
  omit_default_port: true,
147
- middlewares: excon_middleware
148
- }
162
+ middlewares: excon_middleware,
163
+ headers: excon_headers(headers)
164
+ }.merge(options)
149
165
  end
150
166
 
151
167
  def self.with_git_configured(credentials:)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.119.6"
4
+ VERSION = "0.120.4"
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.119.6
4
+ version: 0.120.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-21 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-codecommit
@@ -292,14 +292,14 @@ dependencies:
292
292
  requirements:
293
293
  - - "~>"
294
294
  - !ruby/object:Gem::Version
295
- version: 0.90.0
295
+ version: 0.91.0
296
296
  type: :development
297
297
  prerelease: false
298
298
  version_requirements: !ruby/object:Gem::Requirement
299
299
  requirements:
300
300
  - - "~>"
301
301
  - !ruby/object:Gem::Version
302
- version: 0.90.0
302
+ version: 0.91.0
303
303
  - !ruby/object:Gem::Dependency
304
304
  name: vcr
305
305
  requirement: !ruby/object:Gem::Requirement