dependabot-common 0.245.0 → 0.247.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/bitbucket.rb +113 -5
  3. data/lib/dependabot/clients/codecommit.rb +107 -12
  4. data/lib/dependabot/clients/github_with_retries.rb +61 -19
  5. data/lib/dependabot/clients/gitlab_with_retries.rb +60 -7
  6. data/lib/dependabot/dependency.rb +1 -1
  7. data/lib/dependabot/errors.rb +20 -2
  8. data/lib/dependabot/file_fetchers/base.rb +8 -19
  9. data/lib/dependabot/file_updaters/base.rb +2 -0
  10. data/lib/dependabot/git_commit_checker.rb +3 -2
  11. data/lib/dependabot/metadata_finders/base/changelog_finder.rb +1 -1
  12. data/lib/dependabot/metadata_finders/base/commits_finder.rb +1 -1
  13. data/lib/dependabot/metadata_finders/base/release_finder.rb +1 -1
  14. data/lib/dependabot/pull_request_creator/azure.rb +80 -9
  15. data/lib/dependabot/pull_request_creator/bitbucket.rb +73 -9
  16. data/lib/dependabot/pull_request_creator/branch_namer/solo_strategy.rb +1 -1
  17. data/lib/dependabot/pull_request_creator/codecommit.rb +96 -25
  18. data/lib/dependabot/pull_request_creator/github.rb +162 -49
  19. data/lib/dependabot/pull_request_creator/gitlab.rb +109 -21
  20. data/lib/dependabot/pull_request_creator/message_builder/issue_linker.rb +13 -4
  21. data/lib/dependabot/pull_request_creator/message_builder.rb +246 -89
  22. data/lib/dependabot/pull_request_creator/pr_name_prefixer.rb +11 -9
  23. data/lib/dependabot/pull_request_creator.rb +32 -27
  24. data/lib/dependabot/pull_request_updater/azure.rb +75 -11
  25. data/lib/dependabot/pull_request_updater/github.rb +89 -28
  26. data/lib/dependabot/pull_request_updater/gitlab.rb +61 -12
  27. data/lib/dependabot/pull_request_updater.rb +1 -1
  28. data/lib/dependabot/registry_client.rb +2 -2
  29. data/lib/dependabot/requirements_update_strategy.rb +13 -0
  30. data/lib/dependabot/update_checkers/base.rb +123 -32
  31. data/lib/dependabot/update_checkers/version_filters.rb +15 -5
  32. data/lib/dependabot/version.rb +6 -43
  33. data/lib/dependabot.rb +1 -1
  34. metadata +18 -3
@@ -1,18 +1,78 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "gitlab"
5
+ require "sorbet-runtime"
6
+
4
7
  require "dependabot/clients/gitlab_with_retries"
5
8
  require "dependabot/pull_request_creator"
6
- require "gitlab"
7
9
 
8
10
  module Dependabot
9
11
  class PullRequestCreator
10
12
  class Gitlab
11
- attr_reader :source, :branch_name, :base_commit, :credentials,
12
- :files, :pr_description, :pr_name, :commit_message,
13
- :author_details, :labeler, :approvers, :assignees,
14
- :milestone, :target_project_id
13
+ extend T::Sig
14
+
15
+ sig { returns(Dependabot::Source) }
16
+ attr_reader :source
17
+
18
+ sig { returns(String) }
19
+ attr_reader :branch_name
20
+
21
+ sig { returns(String) }
22
+ attr_reader :base_commit
23
+
24
+ sig { returns(T::Array[Dependabot::Credential]) }
25
+ attr_reader :credentials
26
+
27
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
28
+ attr_reader :files
29
+
30
+ sig { returns(String) }
31
+ attr_reader :pr_description
32
+
33
+ sig { returns(String) }
34
+ attr_reader :pr_name
35
+
36
+ sig { returns(String) }
37
+ attr_reader :commit_message
38
+
39
+ sig { returns(T.nilable(T::Hash[Symbol, String])) }
40
+ attr_reader :author_details
15
41
 
42
+ sig { returns(Dependabot::PullRequestCreator::Labeler) }
43
+ attr_reader :labeler
44
+
45
+ sig { returns(T.nilable(T::Hash[Symbol, T::Array[Integer]])) }
46
+ attr_reader :approvers
47
+
48
+ sig { returns(T.nilable(T::Array[Integer])) }
49
+ attr_reader :assignees
50
+
51
+ sig { returns(T.nilable(T.any(T::Array[String], Integer))) }
52
+ attr_reader :milestone
53
+
54
+ sig { returns(T.nilable(Integer)) }
55
+ attr_reader :target_project_id
56
+
57
+ sig do
58
+ params(
59
+ source: Dependabot::Source,
60
+ branch_name: String,
61
+ base_commit: String,
62
+ credentials: T::Array[Dependabot::Credential],
63
+ files: T::Array[Dependabot::DependencyFile],
64
+ commit_message: String,
65
+ pr_description: String,
66
+ pr_name: String,
67
+ author_details: T.nilable(T::Hash[Symbol, String]),
68
+ labeler: Dependabot::PullRequestCreator::Labeler,
69
+ approvers: T.nilable(T::Hash[Symbol, T::Array[Integer]]),
70
+ assignees: T.nilable(T::Array[Integer]),
71
+ milestone: T.nilable(T.any(T::Array[String], Integer)),
72
+ target_project_id: T.nilable(Integer)
73
+ )
74
+ .void
75
+ end
16
76
  def initialize(source:, branch_name:, base_commit:, credentials:,
17
77
  files:, commit_message:, pr_description:, pr_name:,
18
78
  author_details:, labeler:, approvers:, assignees:,
@@ -33,6 +93,7 @@ module Dependabot
33
93
  @target_project_id = target_project_id
34
94
  end
35
95
 
96
+ sig { returns(T.nilable(::Gitlab::ObjectifiedHash)) }
36
97
  def create
37
98
  return if branch_exists? && merge_request_exists?
38
99
 
@@ -54,30 +115,43 @@ module Dependabot
54
115
 
55
116
  private
56
117
 
118
+ sig { returns(Dependabot::Clients::GitlabWithRetries) }
57
119
  def gitlab_client_for_source
58
120
  @gitlab_client_for_source ||=
59
- Dependabot::Clients::GitlabWithRetries.for_source(
60
- source: source,
61
- credentials: credentials
121
+ T.let(
122
+ Dependabot::Clients::GitlabWithRetries.for_source(
123
+ source: source,
124
+ credentials: credentials
125
+ ),
126
+ T.nilable(Dependabot::Clients::GitlabWithRetries)
62
127
  )
63
128
  end
64
129
 
130
+ sig { returns(T::Boolean) }
65
131
  def branch_exists?
66
132
  @branch_ref ||=
67
- gitlab_client_for_source.branch(source.repo, branch_name)
133
+ T.let(
134
+ T.unsafe(gitlab_client_for_source).branch(source.repo, branch_name),
135
+ T.nilable(::Gitlab::ObjectifiedHash)
136
+ )
68
137
  true
69
138
  rescue ::Gitlab::Error::NotFound
70
139
  false
71
140
  end
72
141
 
142
+ sig { returns(T::Boolean) }
73
143
  def commit_exists?
74
144
  @commits ||=
75
- gitlab_client_for_source.commits(source.repo, ref_name: branch_name)
145
+ T.let(
146
+ T.unsafe(gitlab_client_for_source).commits(source.repo, ref_name: branch_name),
147
+ T.nilable(::Gitlab::PaginatedResponse)
148
+ )
76
149
  @commits.first.message == commit_message
77
150
  end
78
151
 
152
+ sig { returns(T::Boolean) }
79
153
  def merge_request_exists?
80
- gitlab_client_for_source.merge_requests(
154
+ T.unsafe(gitlab_client_for_source).merge_requests(
81
155
  target_project_id || source.repo,
82
156
  source_branch: branch_name,
83
157
  target_branch: source.branch || default_branch,
@@ -85,16 +159,18 @@ module Dependabot
85
159
  ).any?
86
160
  end
87
161
 
162
+ sig { returns(::Gitlab::ObjectifiedHash) }
88
163
  def create_branch
89
- gitlab_client_for_source.create_branch(
164
+ T.unsafe(gitlab_client_for_source).create_branch(
90
165
  source.repo,
91
166
  branch_name,
92
167
  base_commit
93
168
  )
94
169
  end
95
170
 
171
+ sig { returns(::Gitlab::ObjectifiedHash) }
96
172
  def create_commit
97
- return create_submodule_update_commit if files.count == 1 && files.first.type == "submodule"
173
+ return create_submodule_update_commit if files.count == 1 && T.must(files.first).type == "submodule"
98
174
 
99
175
  gitlab_client_for_source.create_commit(
100
176
  source.repo,
@@ -104,10 +180,11 @@ module Dependabot
104
180
  )
105
181
  end
106
182
 
183
+ sig { returns(::Gitlab::ObjectifiedHash) }
107
184
  def create_submodule_update_commit
108
- file = files.first
185
+ file = T.must(files.first)
109
186
 
110
- gitlab_client_for_source.edit_submodule(
187
+ T.unsafe(gitlab_client_for_source).edit_submodule(
111
188
  source.repo,
112
189
  file.path.gsub(%r{^/}, ""),
113
190
  branch: branch_name,
@@ -116,8 +193,9 @@ module Dependabot
116
193
  )
117
194
  end
118
195
 
196
+ sig { returns(T.nilable(::Gitlab::ObjectifiedHash)) }
119
197
  def create_merge_request
120
- gitlab_client_for_source.create_merge_request(
198
+ T.unsafe(gitlab_client_for_source).create_merge_request(
121
199
  source.repo,
122
200
  pr_name,
123
201
  source_branch: branch_name,
@@ -132,16 +210,18 @@ module Dependabot
132
210
  )
133
211
  end
134
212
 
213
+ sig { params(merge_request: ::Gitlab::ObjectifiedHash).returns(T.nilable(::Gitlab::ObjectifiedHash)) }
135
214
  def annotate_merge_request(merge_request)
136
215
  add_approvers_to_merge_request(merge_request)
137
216
  end
138
217
 
218
+ sig { params(merge_request: ::Gitlab::ObjectifiedHash).returns(T.nilable(::Gitlab::ObjectifiedHash)) }
139
219
  def add_approvers_to_merge_request(merge_request)
140
220
  return unless approvers_hash[:approvers] || approvers_hash[:group_approvers]
141
221
 
142
- gitlab_client_for_source.create_merge_request_level_rule(
222
+ T.unsafe(gitlab_client_for_source).create_merge_request_level_rule(
143
223
  target_project_id || source.repo,
144
- merge_request.iid,
224
+ T.unsafe(merge_request).iid,
145
225
  name: "dependency-updates",
146
226
  approvals_required: 1,
147
227
  user_ids: approvers_hash[:approvers],
@@ -149,13 +229,21 @@ module Dependabot
149
229
  )
150
230
  end
151
231
 
232
+ sig { returns(T::Hash[Symbol, T::Array[Integer]]) }
152
233
  def approvers_hash
153
- @approvers_hash ||= approvers || {}
234
+ @approvers_hash ||= T.let(
235
+ approvers || {},
236
+ T.nilable(T::Hash[Symbol, T::Array[Integer]])
237
+ )
154
238
  end
155
239
 
240
+ sig { returns(String) }
156
241
  def default_branch
157
242
  @default_branch ||=
158
- gitlab_client_for_source.project(source.repo).default_branch
243
+ T.let(
244
+ T.unsafe(gitlab_client_for_source).project(source.repo).default_branch,
245
+ T.nilable(String)
246
+ )
159
247
  end
160
248
  end
161
249
  end
@@ -21,10 +21,10 @@ module Dependabot
21
21
  /\[(?<tag>(?:\#|GH-)?\d+)\]\(\)/i
22
22
  ].freeze, T::Array[Regexp])
23
23
 
24
- sig { returns(String) }
24
+ sig { returns(T.nilable(String)) }
25
25
  attr_reader :source_url
26
26
 
27
- sig { params(source_url: String).void }
27
+ sig { params(source_url: T.nilable(String)).void }
28
28
  def initialize(source_url:)
29
29
  @source_url = source_url
30
30
  end
@@ -46,9 +46,18 @@ module Dependabot
46
46
  .match("#{REPO_REGEX}#{TAG_REGEX}")
47
47
  &.named_captures
48
48
  &.fetch("repo", nil)
49
- source = repo ? "https://github.com/#{repo}" : source_url
50
49
 
51
- "[#{repo ? (repo + tag) : tag}](#{source}/issues/#{number})"
50
+ source = if repo
51
+ "https://github.com/#{repo}"
52
+ elsif source_url
53
+ source_url
54
+ end
55
+
56
+ if source
57
+ "[#{repo ? (repo + tag) : tag}](#{source}/issues/#{number})"
58
+ else
59
+ issue_link
60
+ end
52
61
  end
53
62
  end
54
63
  end