dependabot-common 0.244.0 → 0.246.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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dependabot/clients/bitbucket.rb +113 -5
  3. data/lib/dependabot/clients/bitbucket_with_retries.rb +34 -10
  4. data/lib/dependabot/clients/codecommit.rb +107 -12
  5. data/lib/dependabot/clients/github_with_retries.rb +61 -19
  6. data/lib/dependabot/clients/gitlab_with_retries.rb +60 -7
  7. data/lib/dependabot/dependency.rb +1 -1
  8. data/lib/dependabot/errors.rb +8 -2
  9. data/lib/dependabot/git_commit_checker.rb +4 -3
  10. data/lib/dependabot/metadata_finders/base/changelog_finder.rb +1 -1
  11. data/lib/dependabot/metadata_finders/base/commits_finder.rb +1 -1
  12. data/lib/dependabot/metadata_finders/base/release_finder.rb +1 -1
  13. data/lib/dependabot/pull_request_creator/azure.rb +80 -9
  14. data/lib/dependabot/pull_request_creator/bitbucket.rb +73 -9
  15. data/lib/dependabot/pull_request_creator/codecommit.rb +96 -25
  16. data/lib/dependabot/pull_request_creator/github.rb +162 -49
  17. data/lib/dependabot/pull_request_creator/gitlab.rb +109 -21
  18. data/lib/dependabot/pull_request_creator/message_builder.rb +239 -89
  19. data/lib/dependabot/pull_request_creator/pr_name_prefixer.rb +11 -9
  20. data/lib/dependabot/pull_request_creator.rb +32 -27
  21. data/lib/dependabot/pull_request_updater/azure.rb +75 -11
  22. data/lib/dependabot/pull_request_updater/github.rb +89 -28
  23. data/lib/dependabot/pull_request_updater/gitlab.rb +61 -12
  24. data/lib/dependabot/pull_request_updater.rb +1 -1
  25. data/lib/dependabot/shared_helpers.rb +19 -1
  26. data/lib/dependabot/update_checkers/base.rb +121 -31
  27. data/lib/dependabot.rb +1 -1
  28. metadata +3 -3
@@ -1,19 +1,70 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  require "dependabot/clients/bitbucket"
7
+ require "dependabot/credential"
8
+ require "dependabot/dependency_file"
5
9
  require "dependabot/pull_request_creator"
6
10
 
7
11
  module Dependabot
8
12
  class PullRequestCreator
9
13
  class Bitbucket
10
- attr_reader :source, :branch_name, :base_commit, :credentials,
11
- :files, :commit_message, :pr_description, :pr_name,
12
- :author_details, :labeler, :work_item
14
+ extend T::Sig
15
+
16
+ sig { returns(Dependabot::Source) }
17
+ attr_reader :source
18
+
19
+ sig { returns(String) }
20
+ attr_reader :branch_name
21
+
22
+ sig { returns(String) }
23
+ attr_reader :base_commit
24
+
25
+ sig { returns(T::Array[Dependabot::Credential]) }
26
+ attr_reader :credentials
27
+
28
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
29
+ attr_reader :files
30
+
31
+ sig { returns(String) }
32
+ attr_reader :commit_message
33
+
34
+ sig { returns(String) }
35
+ attr_reader :pr_description
36
+
37
+ sig { returns(String) }
38
+ attr_reader :pr_name
39
+
40
+ sig { returns(T.nilable(T::Hash[Symbol, String])) }
41
+ attr_reader :author_details
42
+
43
+ sig { returns(T.nilable(Dependabot::PullRequestCreator::Labeler)) }
44
+ attr_reader :labeler
45
+
46
+ sig { returns(T.nilable(Integer)) }
47
+ attr_reader :work_item
13
48
 
14
49
  # BitBucket Cloud accepts > 1MB characters, but they display poorly in the UI, so limiting to 4x 65,536
15
50
  PR_DESCRIPTION_MAX_LENGTH = 262_143 # 0 based count
16
51
 
52
+ sig do
53
+ params(
54
+ source: Dependabot::Source,
55
+ branch_name: String,
56
+ base_commit: String,
57
+ credentials: T::Array[Dependabot::Credential],
58
+ files: T::Array[Dependabot::DependencyFile],
59
+ commit_message: String,
60
+ pr_description: String,
61
+ pr_name: String,
62
+ author_details: T.nilable(T::Hash[Symbol, String]),
63
+ labeler: T.nilable(Dependabot::PullRequestCreator::Labeler),
64
+ work_item: T.nilable(Integer)
65
+ )
66
+ .void
67
+ end
17
68
  def initialize(source:, branch_name:, base_commit:, credentials:,
18
69
  files:, commit_message:, pr_description:, pr_name:,
19
70
  author_details:, labeler: nil, work_item: nil)
@@ -30,6 +81,7 @@ module Dependabot
30
81
  @work_item = work_item
31
82
  end
32
83
 
84
+ sig { void }
33
85
  def create
34
86
  return if branch_exists? && pull_request_exists?
35
87
 
@@ -43,20 +95,26 @@ module Dependabot
43
95
 
44
96
  private
45
97
 
98
+ sig { returns(Dependabot::Clients::Bitbucket) }
46
99
  def bitbucket_client_for_source
47
100
  @bitbucket_client_for_source ||=
48
- Dependabot::Clients::Bitbucket.for_source(
49
- source: source,
50
- credentials: credentials
101
+ T.let(
102
+ Dependabot::Clients::Bitbucket.for_source(
103
+ source: source,
104
+ credentials: credentials
105
+ ),
106
+ T.nilable(Dependabot::Clients::Bitbucket)
51
107
  )
52
108
  end
53
109
 
110
+ sig { returns(T::Boolean) }
54
111
  def branch_exists?
55
- bitbucket_client_for_source.branch(source.repo, branch_name)
112
+ !bitbucket_client_for_source.branch(source.repo, branch_name).nil?
56
113
  rescue Clients::Bitbucket::NotFound
57
114
  false
58
115
  end
59
116
 
117
+ sig { returns(T::Boolean) }
60
118
  def pull_request_exists?
61
119
  bitbucket_client_for_source.pull_requests(
62
120
  source.repo,
@@ -65,6 +123,7 @@ module Dependabot
65
123
  ).any?
66
124
  end
67
125
 
126
+ sig { void }
68
127
  def create_commit
69
128
  author = author_details&.slice(:name, :email)
70
129
  author = nil unless author&.any?
@@ -79,6 +138,7 @@ module Dependabot
79
138
  )
80
139
  end
81
140
 
141
+ sig { void }
82
142
  def create_pull_request
83
143
  bitbucket_client_for_source.create_pull_request(
84
144
  source.repo,
@@ -91,9 +151,13 @@ module Dependabot
91
151
  )
92
152
  end
93
153
 
154
+ sig { returns(String) }
94
155
  def default_branch
95
156
  @default_branch ||=
96
- bitbucket_client_for_source.fetch_default_branch(source.repo)
157
+ T.let(
158
+ bitbucket_client_for_source.fetch_default_branch(source.repo),
159
+ T.nilable(String)
160
+ )
97
161
  end
98
162
  end
99
163
  end
@@ -1,20 +1,66 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  require "dependabot/clients/codecommit"
5
7
  require "dependabot/pull_request_creator"
6
8
 
7
9
  module Dependabot
8
10
  class PullRequestCreator
9
11
  class Codecommit
10
- attr_reader :source, :branch_name, :base_commit, :credentials,
11
- :files, :commit_message, :pr_description, :pr_name,
12
- :author_details, :labeler
12
+ extend T::Sig
13
+
14
+ sig { returns(Dependabot::Source) }
15
+ attr_reader :source
16
+
17
+ sig { returns(String) }
18
+ attr_reader :branch_name
19
+
20
+ sig { returns(String) }
21
+ attr_reader :base_commit
22
+
23
+ sig { returns(T::Array[Dependabot::Credential]) }
24
+ attr_reader :credentials
25
+
26
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
27
+ attr_reader :files
28
+
29
+ sig { returns(String) }
30
+ attr_reader :commit_message
31
+
32
+ sig { returns(String) }
33
+ attr_reader :pr_description
34
+
35
+ sig { returns(String) }
36
+ attr_reader :pr_name
37
+
38
+ sig { returns(T.nilable(T::Hash[Symbol, String])) }
39
+ attr_reader :author_details
40
+
41
+ sig { returns(T.nilable(Dependabot::PullRequestCreator::Labeler)) }
42
+ attr_reader :labeler
13
43
 
14
44
  # CodeCommit limits PR descriptions to a max length of 10,240 characters:
15
45
  # https://docs.aws.amazon.com/codecommit/latest/APIReference/API_PullRequest.html
16
46
  PR_DESCRIPTION_MAX_LENGTH = 10_239 # 0 based count
17
47
 
48
+ sig do
49
+ params(
50
+ source: Dependabot::Source,
51
+ branch_name: String,
52
+ base_commit: String,
53
+ credentials: T::Array[Dependabot::Credential],
54
+ files: T::Array[Dependabot::DependencyFile],
55
+ commit_message: String,
56
+ pr_description: String,
57
+ pr_name: String,
58
+ author_details: T.nilable(T::Hash[Symbol, String]),
59
+ labeler: T.nilable(Dependabot::PullRequestCreator::Labeler),
60
+ require_up_to_date_base: T::Boolean
61
+ )
62
+ .void
63
+ end
18
64
  def initialize(source:, branch_name:, base_commit:, credentials:,
19
65
  files:, commit_message:, pr_description:, pr_name:,
20
66
  author_details:, labeler:, require_up_to_date_base:)
@@ -31,6 +77,7 @@ module Dependabot
31
77
  @require_up_to_date_base = require_up_to_date_base
32
78
  end
33
79
 
80
+ sig { void }
34
81
  def create
35
82
  return if branch_exists?(branch_name) && unmerged_pull_request_exists?
36
83
  return if require_up_to_date_base? && !base_commit_is_up_to_date?
@@ -40,10 +87,12 @@ module Dependabot
40
87
 
41
88
  private
42
89
 
90
+ sig { returns(T::Boolean) }
43
91
  def require_up_to_date_base?
44
92
  @require_up_to_date_base
45
93
  end
46
94
 
95
+ sig { returns(T::Boolean) }
47
96
  def base_commit_is_up_to_date?
48
97
  codecommit_client_for_source.fetch_commit(
49
98
  source.repo,
@@ -51,6 +100,7 @@ module Dependabot
51
100
  ) == base_commit
52
101
  end
53
102
 
103
+ sig { returns(T.nilable(Aws::CodeCommit::Types::CreatePullRequestOutput)) }
54
104
  def create_pull_request
55
105
  branch = create_or_get_branch(base_commit)
56
106
  return unless branch
@@ -69,6 +119,7 @@ module Dependabot
69
119
  pull_request
70
120
  end
71
121
 
122
+ sig { params(commit: String).returns(T.nilable(String)) }
72
123
  def create_or_get_branch(commit)
73
124
  # returns the branch name
74
125
  if branch_exists?(branch_name)
@@ -78,6 +129,7 @@ module Dependabot
78
129
  end
79
130
  end
80
131
 
132
+ sig { params(commit: String).returns(String) }
81
133
  def create_branch(commit)
82
134
  # codecommit returns an empty response on create branch success
83
135
  codecommit_client_for_source.create_branch(source.repo, branch_name,
@@ -86,49 +138,64 @@ module Dependabot
86
138
  branch_name
87
139
  end
88
140
 
141
+ sig { returns(Dependabot::Clients::CodeCommit) }
89
142
  def codecommit_client_for_source
90
143
  @codecommit_client_for_source ||=
91
- Dependabot::Clients::CodeCommit.for_source(
92
- source: source,
93
- credentials: credentials
144
+ T.let(
145
+ Dependabot::Clients::CodeCommit.for_source(
146
+ source: source,
147
+ credentials: credentials
148
+ ),
149
+ T.nilable(Dependabot::Clients::CodeCommit)
94
150
  )
95
151
  end
96
152
 
153
+ sig { params(branch_name: String).returns(T::Boolean) }
97
154
  def branch_exists?(branch_name)
98
- @branch_ref ||= codecommit_client_for_source.branch(branch_name)
155
+ @branch_ref ||= T.let(
156
+ codecommit_client_for_source.branch(branch_name),
157
+ T.nilable(String)
158
+ )
159
+ !@branch_ref.nil?
99
160
  rescue Aws::CodeCommit::Errors::BranchDoesNotExistException
100
161
  false
101
162
  end
102
163
 
164
+ sig { returns(T::Boolean) }
103
165
  def unmerged_pull_request_exists?
104
166
  unmerged_prs = []
105
167
  pull_requests_for_branch.each do |pr|
106
- unless pr.pull_request
107
- .pull_request_targets[0].merge_metadata.is_merged
168
+ unless T.unsafe(pr).pull_request
169
+ .pull_request_targets[0].merge_metadata.is_merged
108
170
  unmerged_prs << pr
109
171
  end
110
172
  end
111
173
  unmerged_prs.any?
112
174
  end
113
175
 
176
+ sig { returns(T::Array[Aws::CodeCommit::Types::PullRequest]) }
114
177
  def pull_requests_for_branch
115
178
  @pull_requests_for_branch ||=
116
- begin
117
- open_prs = codecommit_client_for_source.pull_requests(
118
- source.repo,
119
- "open",
120
- source.branch || default_branch
121
- )
122
- closed_prs = codecommit_client_for_source.pull_requests(
123
- source.repo,
124
- "closed",
125
- source.branch || default_branch
126
- )
127
-
128
- [*open_prs, *closed_prs]
129
- end
179
+ T.let(
180
+ begin
181
+ open_prs = codecommit_client_for_source.pull_requests(
182
+ source.repo,
183
+ "open",
184
+ source.branch || default_branch
185
+ )
186
+ closed_prs = codecommit_client_for_source.pull_requests(
187
+ source.repo,
188
+ "closed",
189
+ source.branch || default_branch
190
+ )
191
+
192
+ [*open_prs, *closed_prs]
193
+ end,
194
+ T.nilable(T::Array[Aws::CodeCommit::Types::PullRequest])
195
+ )
130
196
  end
131
197
 
198
+ sig { void }
132
199
  def create_commit
133
200
  author = author_details&.slice(:name, :email, :date)
134
201
  author = nil unless author&.any?
@@ -142,9 +209,13 @@ module Dependabot
142
209
  )
143
210
  end
144
211
 
212
+ sig { returns(String) }
145
213
  def default_branch
146
214
  @default_branch ||=
147
- codecommit_client_for_source.fetch_default_branch(source.repo)
215
+ T.let(
216
+ codecommit_client_for_source.fetch_default_branch(source.repo),
217
+ T.nilable(String)
218
+ )
148
219
  end
149
220
  end
150
221
  end