dependabot-common 0.235.0 → 0.237.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dependabot/clients/azure.rb +3 -3
  3. data/lib/dependabot/config/file.rb +32 -9
  4. data/lib/dependabot/config/file_fetcher.rb +3 -3
  5. data/lib/dependabot/config/ignore_condition.rb +34 -8
  6. data/lib/dependabot/config/update_config.rb +42 -6
  7. data/lib/dependabot/config.rb +1 -1
  8. data/lib/dependabot/dependency_file.rb +89 -14
  9. data/lib/dependabot/dependency_group.rb +29 -5
  10. data/lib/dependabot/errors.rb +101 -13
  11. data/lib/dependabot/file_fetchers/base.rb +250 -93
  12. data/lib/dependabot/file_updaters/artifact_updater.rb +37 -10
  13. data/lib/dependabot/file_updaters/vendor_updater.rb +13 -3
  14. data/lib/dependabot/logger.rb +7 -2
  15. data/lib/dependabot/metadata_finders/base/changelog_finder.rb +13 -6
  16. data/lib/dependabot/pull_request_creator/commit_signer.rb +33 -7
  17. data/lib/dependabot/pull_request_creator/github.rb +13 -10
  18. data/lib/dependabot/pull_request_creator/message.rb +21 -2
  19. data/lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb +37 -16
  20. data/lib/dependabot/pull_request_creator/message_builder/metadata_presenter.rb +5 -3
  21. data/lib/dependabot/pull_request_creator/message_builder.rb +5 -18
  22. data/lib/dependabot/pull_request_creator/pr_name_prefixer.rb +10 -4
  23. data/lib/dependabot/pull_request_updater/github.rb +2 -2
  24. data/lib/dependabot/shared_helpers.rb +117 -33
  25. data/lib/dependabot/simple_instrumentor.rb +22 -3
  26. data/lib/dependabot/source.rb +65 -17
  27. data/lib/dependabot/update_checkers/version_filters.rb +12 -1
  28. data/lib/dependabot/utils.rb +21 -2
  29. data/lib/dependabot/workspace/base.rb +42 -7
  30. data/lib/dependabot/workspace/change_attempt.rb +31 -3
  31. data/lib/dependabot/workspace/git.rb +34 -4
  32. data/lib/dependabot/workspace.rb +16 -2
  33. data/lib/dependabot.rb +1 -1
  34. metadata +37 -9
@@ -5,6 +5,7 @@ require "tmpdir"
5
5
  require "set"
6
6
  require "sorbet-runtime"
7
7
  require "dependabot/version"
8
+ require "dependabot/config/file"
8
9
 
9
10
  # TODO: in due course, these "registries" should live in a wrapper gem, not
10
11
  # dependabot-core.
@@ -22,11 +23,13 @@ module Dependabot
22
23
  version_class = @version_classes[package_manager]
23
24
  return version_class if version_class
24
25
 
25
- raise "Unsupported package_manager #{package_manager}"
26
+ raise "Unregistered package_manager #{package_manager}"
26
27
  end
27
28
 
28
29
  sig { params(package_manager: String, version_class: T.class_of(Dependabot::Version)).void }
29
30
  def self.register_version_class(package_manager, version_class)
31
+ validate_package_manager!(package_manager)
32
+
30
33
  @version_classes[package_manager] = version_class
31
34
  end
32
35
 
@@ -37,11 +40,13 @@ module Dependabot
37
40
  requirement_class = @requirement_classes[package_manager]
38
41
  return requirement_class if requirement_class
39
42
 
40
- raise "Unsupported package_manager #{package_manager}"
43
+ raise "Unregistered package_manager #{package_manager}"
41
44
  end
42
45
 
43
46
  sig { params(package_manager: String, requirement_class: T.class_of(Gem::Requirement)).void }
44
47
  def self.register_requirement_class(package_manager, requirement_class)
48
+ validate_package_manager!(package_manager)
49
+
45
50
  @requirement_classes[package_manager] = requirement_class
46
51
  end
47
52
 
@@ -54,7 +59,21 @@ module Dependabot
54
59
 
55
60
  sig { params(package_manager: String).void }
56
61
  def self.register_always_clone(package_manager)
62
+ validate_package_manager!(package_manager)
63
+
57
64
  @cloning_package_managers << package_manager
58
65
  end
66
+
67
+ sig { params(package_manager: String).void }
68
+ def self.validate_package_manager!(package_manager)
69
+ # Official package manager
70
+ return if Config::File::PACKAGE_MANAGER_LOOKUP.invert.key?(package_manager)
71
+
72
+ # Used by specs
73
+ return if package_manager == "dummy"
74
+
75
+ raise "Unsupported package_manager #{package_manager}"
76
+ end
77
+ private_class_method :validate_package_manager!
59
78
  end
60
79
  end
@@ -1,29 +1,53 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  module Dependabot
5
7
  module Workspace
6
8
  class Base
7
- attr_reader :change_attempts, :path
9
+ extend T::Sig
10
+ extend T::Helpers
11
+ extend T::Generic
12
+
13
+ abstract!
14
+
15
+ sig { returns(T::Array[Dependabot::Workspace::ChangeAttempt]) }
16
+ attr_reader :change_attempts
8
17
 
18
+ sig { returns(T.any(Pathname, String)) }
19
+ attr_reader :path
20
+
21
+ sig { params(path: T.any(Pathname, String)).void }
9
22
  def initialize(path)
10
23
  @path = path
11
- @change_attempts = []
24
+ @change_attempts = T.let([], T::Array[Dependabot::Workspace::ChangeAttempt])
12
25
  end
13
26
 
27
+ sig { returns(T::Boolean) }
14
28
  def changed?
15
29
  changes.any?
16
30
  end
17
31
 
32
+ sig { returns(T::Array[Dependabot::Workspace::ChangeAttempt]) }
18
33
  def changes
19
34
  change_attempts.select(&:success?)
20
35
  end
21
36
 
37
+ sig { returns(T::Array[Dependabot::Workspace::ChangeAttempt]) }
22
38
  def failed_change_attempts
23
39
  change_attempts.select(&:error?)
24
40
  end
25
41
 
26
- def change(memo = nil)
42
+ sig do
43
+ type_parameters(:T)
44
+ .params(
45
+ memo: T.nilable(String),
46
+ _blk: T.proc.params(arg0: T.any(Pathname, String)).returns(T.type_parameter(:T))
47
+ )
48
+ .returns(T.type_parameter(:T))
49
+ end
50
+ def change(memo = nil, &_blk)
27
51
  Dir.chdir(path) { yield(path) }
28
52
  rescue StandardError => e
29
53
  capture_failed_change_attempt(memo, e)
@@ -31,17 +55,28 @@ module Dependabot
31
55
  raise e
32
56
  end
33
57
 
58
+ sig do
59
+ abstract.params(memo: T.nilable(String)).returns(T.nilable(T::Array[Dependabot::Workspace::ChangeAttempt]))
60
+ end
34
61
  def store_change(memo = nil); end
35
62
 
36
- def to_patch
37
- ""
38
- end
63
+ sig { abstract.returns(String) }
64
+ def to_patch; end
39
65
 
66
+ sig { abstract.returns(NilClass) }
40
67
  def reset!; end
41
68
 
42
69
  protected
43
70
 
71
+ sig do
72
+ abstract
73
+ .params(memo: T.nilable(String), error: T.nilable(StandardError))
74
+ .returns(T.nilable(T::Array[Dependabot::Workspace::ChangeAttempt]))
75
+ end
44
76
  def capture_failed_change_attempt(memo = nil, error = nil); end
77
+
78
+ sig { abstract.returns(String) }
79
+ def clean; end
45
80
  end
46
81
  end
47
82
  end
@@ -1,11 +1,37 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  module Dependabot
5
7
  module Workspace
6
8
  class ChangeAttempt
7
- attr_reader :diff, :error, :id, :memo, :workspace
9
+ extend T::Sig
10
+
11
+ sig { returns(T.nilable(String)) }
12
+ attr_reader :diff
13
+
14
+ sig { returns(T.nilable(StandardError)) }
15
+ attr_reader :error
16
+
17
+ sig { returns(String) }
18
+ attr_reader :id
8
19
 
20
+ sig { returns(T.nilable(String)) }
21
+ attr_reader :memo
22
+
23
+ sig { returns(Dependabot::Workspace::Base) }
24
+ attr_reader :workspace
25
+
26
+ sig do
27
+ params(
28
+ workspace: Dependabot::Workspace::Base,
29
+ id: String,
30
+ memo: T.nilable(String),
31
+ diff: T.nilable(String),
32
+ error: T.nilable(StandardError)
33
+ ).void
34
+ end
9
35
  def initialize(workspace, id:, memo:, diff: nil, error: nil)
10
36
  @workspace = workspace
11
37
  @id = id
@@ -14,12 +40,14 @@ module Dependabot
14
40
  @error = error
15
41
  end
16
42
 
43
+ sig { returns(T::Boolean) }
17
44
  def success?
18
45
  error.nil?
19
46
  end
20
47
 
48
+ sig { returns(T::Boolean) }
21
49
  def error?
22
- error
50
+ !error.nil?
23
51
  end
24
52
  end
25
53
  end
@@ -1,31 +1,40 @@
1
- # typed: false
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
4
5
  require "dependabot/workspace/base"
5
6
  require "dependabot/workspace/change_attempt"
6
7
 
7
8
  module Dependabot
8
9
  module Workspace
9
10
  class Git < Base
11
+ extend T::Sig
12
+ extend T::Helpers
13
+
10
14
  USER = "dependabot[bot]"
11
- EMAIL = "#{USER}@users.noreply.github.com".freeze
15
+ EMAIL = T.let("#{USER}@users.noreply.github.com".freeze, String)
12
16
 
17
+ sig { returns(String) }
13
18
  attr_reader :initial_head_sha
14
19
 
20
+ sig { params(path: T.any(Pathname, String)).void }
15
21
  def initialize(path)
16
22
  super(path)
17
- @initial_head_sha = head_sha
23
+ @initial_head_sha = T.let(head_sha, String)
18
24
  configure_git
19
25
  end
20
26
 
27
+ sig { returns(T::Boolean) }
21
28
  def changed?
22
29
  changes.any? || !changed_files.empty?
23
30
  end
24
31
 
32
+ sig { override.returns(String) }
25
33
  def to_patch
26
34
  run_shell_command("git diff --patch #{@initial_head_sha}.. .")
27
35
  end
28
36
 
37
+ sig { override.returns(NilClass) }
29
38
  def reset!
30
39
  reset(initial_head_sha)
31
40
  clean
@@ -35,6 +44,11 @@ module Dependabot
35
44
  nil
36
45
  end
37
46
 
47
+ sig do
48
+ override
49
+ .params(memo: T.nilable(String))
50
+ .returns(T.nilable(T::Array[Dependabot::Workspace::ChangeAttempt]))
51
+ end
38
52
  def store_change(memo = nil)
39
53
  return nil if changed_files.empty?
40
54
 
@@ -48,6 +62,11 @@ module Dependabot
48
62
 
49
63
  protected
50
64
 
65
+ sig do
66
+ override
67
+ .params(memo: T.nilable(String), error: T.nilable(StandardError))
68
+ .returns(T.nilable(T::Array[Dependabot::Workspace::ChangeAttempt]))
69
+ end
51
70
  def capture_failed_change_attempt(memo = nil, error = nil)
52
71
  return nil if changed_files(ignored_mode: "matching").empty? && error.nil?
53
72
 
@@ -57,19 +76,23 @@ module Dependabot
57
76
 
58
77
  private
59
78
 
79
+ sig { returns(String) }
60
80
  def configure_git
61
81
  run_shell_command(%(git config user.name "#{USER}"), allow_unsafe_shell_command: true)
62
82
  run_shell_command(%(git config user.email "#{EMAIL}"), allow_unsafe_shell_command: true)
63
83
  end
64
84
 
85
+ sig { returns(String) }
65
86
  def head_sha
66
87
  run_shell_command("git rev-parse HEAD").strip
67
88
  end
68
89
 
90
+ sig { returns(String) }
69
91
  def last_stash_sha
70
92
  run_shell_command("git rev-parse refs/stash").strip
71
93
  end
72
94
 
95
+ sig { returns(String) }
73
96
  def current_commit
74
97
  # Avoid emiting the user's commit message to logs if Dependabot hasn't made any changes
75
98
  return "Initial SHA: #{initial_head_sha}" if changes.empty?
@@ -78,10 +101,12 @@ module Dependabot
78
101
  run_shell_command(%(git log -1 --pretty="%h% B"), allow_unsafe_shell_command: true).strip
79
102
  end
80
103
 
104
+ sig { params(ignored_mode: String).returns(String) }
81
105
  def changed_files(ignored_mode: "traditional")
82
106
  run_shell_command("git status --untracked-files=all --ignored=#{ignored_mode} --short .").strip
83
107
  end
84
108
 
109
+ sig { params(memo: T.nilable(String)).returns([String, String]) }
85
110
  def stash(memo = nil)
86
111
  msg = memo || "workspace change attempt"
87
112
  run_shell_command("git add --all --force .")
@@ -93,6 +118,7 @@ module Dependabot
93
118
  [sha, diff]
94
119
  end
95
120
 
121
+ sig { params(memo: T.nilable(String)).returns([String, String]) }
96
122
  def commit(memo = nil)
97
123
  run_shell_command("git add #{path}")
98
124
  diff = run_shell_command("git diff --cached .")
@@ -103,18 +129,22 @@ module Dependabot
103
129
  [head_sha, diff]
104
130
  end
105
131
 
132
+ sig { params(sha: String).returns(String) }
106
133
  def reset(sha)
107
134
  run_shell_command("git reset --hard #{sha}")
108
135
  end
109
136
 
137
+ sig { override.returns(String) }
110
138
  def clean
111
139
  run_shell_command("git clean -fx .")
112
140
  end
113
141
 
142
+ sig { params(args: String, kwargs: T::Boolean).returns(String) }
114
143
  def run_shell_command(*args, **kwargs)
115
- Dir.chdir(path) { SharedHelpers.run_shell_command(*args, **kwargs) }
144
+ Dir.chdir(path) { T.unsafe(SharedHelpers).run_shell_command(*args, **kwargs) }
116
145
  end
117
146
 
147
+ sig { params(message: String).void }
118
148
  def debug(message)
119
149
  Dependabot.logger.debug("[workspace] #{message}")
120
150
  end
@@ -1,16 +1,28 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
4
5
  require "dependabot/workspace/git"
5
6
 
6
7
  module Dependabot
7
8
  module Workspace
8
- @active_workspace = nil
9
+ extend T::Sig
10
+
11
+ @active_workspace = T.let(nil, T.nilable(Dependabot::Workspace::Git))
9
12
 
10
13
  class << self
14
+ extend T::Sig
15
+
16
+ sig { returns(T.nilable(Dependabot::Workspace::Git)) }
11
17
  attr_accessor :active_workspace
12
18
  end
13
19
 
20
+ sig do
21
+ params(
22
+ repo_contents_path: String,
23
+ directory: T.any(Pathname, String)
24
+ ).void
25
+ end
14
26
  def self.setup(repo_contents_path:, directory:)
15
27
  Dependabot.logger.debug("Setting up workspace in #{repo_contents_path}")
16
28
 
@@ -22,6 +34,7 @@ module Dependabot
22
34
  @active_workspace = Dependabot::Workspace::Git.new(full_path)
23
35
  end
24
36
 
37
+ sig { params(memo: T.nilable(String)).returns(T.nilable(T::Array[Dependabot::Workspace::ChangeAttempt])) }
25
38
  def self.store_change(memo:)
26
39
  return unless @active_workspace
27
40
 
@@ -30,6 +43,7 @@ module Dependabot
30
43
  @active_workspace.store_change(memo)
31
44
  end
32
45
 
46
+ sig { void }
33
47
  def self.cleanup!
34
48
  return unless @active_workspace
35
49
 
data/lib/dependabot.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Dependabot
5
- VERSION = "0.235.0"
5
+ VERSION = "0.237.0"
6
6
  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.235.0
4
+ version: 0.237.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-19 00:00:00.000000000 Z
11
+ date: 2023-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-codecommit
@@ -101,7 +101,7 @@ dependencies:
101
101
  version: '0.96'
102
102
  - - "<"
103
103
  - !ruby/object:Gem::Version
104
- version: '0.103'
104
+ version: '0.105'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
@@ -111,21 +111,21 @@ dependencies:
111
111
  version: '0.96'
112
112
  - - "<"
113
113
  - !ruby/object:Gem::Version
114
- version: '0.103'
114
+ version: '0.105'
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: faraday
117
117
  requirement: !ruby/object:Gem::Requirement
118
118
  requirements:
119
119
  - - '='
120
120
  - !ruby/object:Gem::Version
121
- version: 2.7.10
121
+ version: 2.7.11
122
122
  type: :runtime
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - '='
127
127
  - !ruby/object:Gem::Version
128
- version: 2.7.10
128
+ version: 2.7.11
129
129
  - !ruby/object:Gem::Dependency
130
130
  name: faraday-retry
131
131
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +188,20 @@ dependencies:
188
188
  - - "<"
189
189
  - !ruby/object:Gem::Version
190
190
  version: '7.0'
191
+ - !ruby/object:Gem::Dependency
192
+ name: opentelemetry-sdk
193
+ requirement: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - "~>"
196
+ - !ruby/object:Gem::Version
197
+ version: '1.3'
198
+ type: :runtime
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - "~>"
203
+ - !ruby/object:Gem::Version
204
+ version: '1.3'
191
205
  - !ruby/object:Gem::Dependency
192
206
  name: parser
193
207
  requirement: !ruby/object:Gem::Requirement
@@ -326,20 +340,34 @@ dependencies:
326
340
  - - "~>"
327
341
  - !ruby/object:Gem::Version
328
342
  version: '1.3'
343
+ - !ruby/object:Gem::Dependency
344
+ name: rspec-sorbet
345
+ requirement: !ruby/object:Gem::Requirement
346
+ requirements:
347
+ - - "~>"
348
+ - !ruby/object:Gem::Version
349
+ version: 1.9.2
350
+ type: :development
351
+ prerelease: false
352
+ version_requirements: !ruby/object:Gem::Requirement
353
+ requirements:
354
+ - - "~>"
355
+ - !ruby/object:Gem::Version
356
+ version: 1.9.2
329
357
  - !ruby/object:Gem::Dependency
330
358
  name: rubocop
331
359
  requirement: !ruby/object:Gem::Requirement
332
360
  requirements:
333
361
  - - "~>"
334
362
  - !ruby/object:Gem::Version
335
- version: 1.56.0
363
+ version: 1.57.2
336
364
  type: :development
337
365
  prerelease: false
338
366
  version_requirements: !ruby/object:Gem::Requirement
339
367
  requirements:
340
368
  - - "~>"
341
369
  - !ruby/object:Gem::Version
342
- version: 1.56.0
370
+ version: 1.57.2
343
371
  - !ruby/object:Gem::Dependency
344
372
  name: rubocop-performance
345
373
  requirement: !ruby/object:Gem::Requirement
@@ -514,7 +542,7 @@ licenses:
514
542
  - Nonstandard
515
543
  metadata:
516
544
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
517
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.235.0
545
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.237.0
518
546
  post_install_message:
519
547
  rdoc_options: []
520
548
  require_paths: