dependabot-common 0.380.0 → 0.381.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a6875517541de554dabb2e9256474b7b063b2af8a82bbf6579eb86e729e917e
4
- data.tar.gz: c29581ace26310f39fb0b24c44702c943c01ab49bcc7787d9dfe4e5dd6093a5c
3
+ metadata.gz: d1bc1965fa1a1b0995cf9a71e47f098f471c2727513d3a69d7c8cf35b82a3cc3
4
+ data.tar.gz: 4273d18c7f649c135c28db5f864d82dc120f56a683a2b5fd823a09a486fc530b
5
5
  SHA512:
6
- metadata.gz: 8f33816f8f94a02f956f067923cd79f44783dec54c23745a713cfc3fc51f6e27b55294ba31fa6f3640626988ad4a8d89f4a68b7971fe5ea14ff6886828b4d718
7
- data.tar.gz: 7a24d2dd23e16b58f8eadc9b975146983c8693e99d0a473401ca392438bc5c81ed7e2b2c1a79e070c6e40189b955783000bac75b59811583a3d4a6fde8ce43b8
6
+ metadata.gz: 72acbd4917a61c50117d9014f26ac4cae89567215682764b01506c1a36f4eb80df3245f4ca4cad9ad7ab0f5d834e9e4540a67a6ea0dab5441d2d9c0a62f6acff
7
+ data.tar.gz: d2acef41e94afb6b5d0d171139e615adbbcc491e89a35ec78d7852b2d745e301ea3f9ec212b035452f7898cdfd791c8e2ff25decf021e5bc2fbda58011879688
@@ -88,7 +88,7 @@ module Dependabot
88
88
 
89
89
  sig { params(repo: String, branch: String).returns(String) }
90
90
  def fetch_commit(repo, branch)
91
- response = T.unsafe(self).ref(repo, "heads/#{branch}")
91
+ response = T.unsafe(ref(repo, "heads/#{branch}"))
92
92
 
93
93
  raise Octokit::NotFound if response.is_a?(Array)
94
94
 
@@ -97,7 +97,7 @@ module Dependabot
97
97
 
98
98
  sig { params(repo: String).returns(String) }
99
99
  def fetch_default_branch(repo)
100
- T.unsafe(self).repository(repo).default_branch
100
+ T.unsafe(repository(repo)).default_branch
101
101
  end
102
102
 
103
103
  ############
@@ -67,12 +67,12 @@ module Dependabot
67
67
 
68
68
  sig { params(repo: String, branch: String).returns(String) }
69
69
  def fetch_commit(repo, branch)
70
- T.unsafe(self).branch(repo, branch).commit.id
70
+ T.unsafe(branch(repo, branch)).commit.id
71
71
  end
72
72
 
73
73
  sig { params(repo: String).returns(String) }
74
74
  def fetch_default_branch(repo)
75
- T.unsafe(self).project(repo).default_branch
75
+ T.unsafe(project(repo)).default_branch
76
76
  end
77
77
 
78
78
  ############
@@ -96,7 +96,7 @@ module Dependabot
96
96
  stdout = T.let("", String)
97
97
  stderr = T.let("", String)
98
98
  status = T.let(nil, T.nilable(ProcessStatus))
99
- pid = T.let(nil, T.untyped)
99
+ pid = T.let(nil, T.nilable(Integer))
100
100
  start_time = Time.now
101
101
 
102
102
  begin
@@ -393,6 +393,18 @@ module Dependabot
393
393
  # rubocop:enable Lint/RedundantCopDisableDirective
394
394
  # rubocop:enable Metrics/AbcSize
395
395
 
396
+ # Interface for error classes that provide Sentry context (e.g. fingerprint).
397
+ # Include this module in any error class that defines #sentry_context.
398
+ module HasSentryContext
399
+ extend T::Sig
400
+ extend T::Helpers
401
+
402
+ interface!
403
+
404
+ sig { abstract.returns(T::Hash[Symbol, T.untyped]) }
405
+ def sentry_context; end
406
+ end
407
+
396
408
  class DependabotError < StandardError
397
409
  extend T::Sig
398
410
 
@@ -393,19 +393,19 @@ module Dependabot
393
393
  .returns(T.nilable(T::Hash[String, T.untyped]))
394
394
  end
395
395
  def update_linked_paths(repo, path, commit, github_response)
396
- case T.unsafe(github_response).type
396
+ case github_response[:type]
397
397
  when "submodule"
398
- sub_source = Source.from_url(T.unsafe(github_response).submodule_git_url)
398
+ sub_source = Source.from_url(github_response[:submodule_git_url])
399
399
  return unless sub_source
400
400
 
401
401
  @linked_paths[path] = {
402
402
  repo: sub_source.repo,
403
403
  provider: sub_source.provider,
404
- commit: T.unsafe(github_response).sha,
404
+ commit: github_response[:sha],
405
405
  path: "/"
406
406
  }
407
407
  when "symlink"
408
- updated_path = File.join(File.dirname(path), T.unsafe(github_response).target)
408
+ updated_path = File.join(File.dirname(path), github_response[:target])
409
409
  @linked_paths[path] = {
410
410
  repo: repo,
411
411
  provider: "github",
@@ -564,10 +564,10 @@ module Dependabot
564
564
  sig { params(repo: String, path: String, commit: String).returns(T::Array[RepositoryContent]) }
565
565
  def _github_repo_contents(repo, path, commit)
566
566
  path = path.gsub(" ", "%20")
567
- github_response = T.unsafe(github_client).contents(repo, path: path, ref: commit)
567
+ github_response = github_client.contents(repo, path: path, ref: commit)
568
568
 
569
569
  if github_response.respond_to?(:type)
570
- update_linked_paths(repo, path, commit, github_response)
570
+ update_linked_paths(repo, path, commit, T.unsafe(github_response))
571
571
  raise Octokit::NotFound
572
572
  end
573
573
 
@@ -629,18 +629,20 @@ module Dependabot
629
629
  sig { params(file: Sawyer::Resource).returns(RepositoryContent) }
630
630
  def _build_github_file_struct(file)
631
631
  RepositoryContent.new(
632
- name: T.unsafe(file).name,
633
- path: T.unsafe(file).path,
634
- type: T.unsafe(file).type,
635
- sha: T.unsafe(file).sha,
636
- size: T.unsafe(file).size
632
+ name: file[:name],
633
+ path: file[:path],
634
+ type: file[:type],
635
+ sha: file[:sha],
636
+ size: file[:size]
637
637
  )
638
638
  end
639
639
 
640
640
  sig { params(repo: String, path: String, commit: String).returns(T::Array[RepositoryContent]) }
641
641
  def _gitlab_repo_contents(repo, path, commit)
642
- T.unsafe(gitlab_client)
643
- .repo_tree(repo, path: path, ref: commit, per_page: 100)
642
+ T.unsafe(
643
+ gitlab_client
644
+ .repo_tree(repo, path: path, ref: commit, per_page: 100)
645
+ )
644
646
  .map do |file|
645
647
  # GitLab API essentially returns the output from `git ls-tree`
646
648
  type = case file.type
@@ -681,12 +683,12 @@ module Dependabot
681
683
 
682
684
  sig { params(repo: String, path: String, commit: String).returns(T::Array[RepositoryContent]) }
683
685
  def _bitbucket_repo_contents(repo, path, commit)
684
- response = T.unsafe(bitbucket_client)
685
- .fetch_repo_contents(
686
- repo,
687
- commit,
688
- path
689
- )
686
+ response = bitbucket_client
687
+ .fetch_repo_contents(
688
+ repo,
689
+ commit,
690
+ path
691
+ )
690
692
 
691
693
  response.map do |file|
692
694
  type = case file.fetch("type")
@@ -775,12 +777,12 @@ module Dependabot
775
777
  when "github"
776
778
  _fetch_file_content_from_github(path, repo, commit)
777
779
  when "gitlab"
778
- tmp = T.unsafe(gitlab_client).get_file(repo, path, commit).content
780
+ tmp = T.unsafe(gitlab_client.get_file(repo, path, commit)).content
779
781
  decode_binary_string(tmp)
780
782
  when "azure"
781
783
  azure_client.fetch_file_contents(commit, path)
782
784
  when "bitbucket"
783
- T.unsafe(bitbucket_client).fetch_file_contents(repo, commit, path)
785
+ bitbucket_client.fetch_file_contents(repo, commit, path)
784
786
  when "codecommit"
785
787
  codecommit_client.fetch_file_contents(repo, commit, path)
786
788
  else raise "Unsupported provider '#{source.provider}'."
@@ -790,30 +792,30 @@ module Dependabot
790
792
  # rubocop:disable Metrics/AbcSize
791
793
  sig { params(path: String, repo: String, commit: String).returns(String) }
792
794
  def _fetch_file_content_from_github(path, repo, commit)
793
- tmp = T.unsafe(github_client).contents(repo, path: path, ref: commit)
795
+ tmp = github_client.contents(repo, path: path, ref: commit)
794
796
 
795
797
  raise Octokit::NotFound if tmp.is_a?(Array)
796
798
 
797
- if tmp.type == "symlink"
799
+ if T.unsafe(tmp).type == "symlink"
798
800
  @linked_paths[path] = {
799
801
  repo: repo,
800
802
  provider: "github",
801
803
  commit: commit,
802
- path: Pathname.new(tmp.target).cleanpath.to_path
804
+ path: Pathname.new(T.unsafe(tmp).target).cleanpath.to_path
803
805
  }
804
- tmp = T.unsafe(github_client).contents(
806
+ tmp = github_client.contents(
805
807
  repo,
806
- path: Pathname.new(tmp.target).cleanpath.to_path,
808
+ path: Pathname.new(T.unsafe(tmp).target).cleanpath.to_path,
807
809
  ref: commit
808
810
  )
809
811
  end
810
812
 
811
- if tmp.content == ""
813
+ if T.unsafe(tmp).content == ""
812
814
  # The file may have exceeded the 1MB limit
813
815
  # see https://github.blog/changelog/2022-05-03-increased-file-size-limit-when-retrieving-file-contents-via-rest-api/
814
- T.unsafe(github_client).contents(repo, path: path, ref: commit, accept: "application/vnd.github.v3.raw")
816
+ T.unsafe(github_client.contents(repo, path: path, ref: commit, accept: "application/vnd.github.v3.raw"))
815
817
  else
816
- decode_binary_string(tmp.content)
818
+ decode_binary_string(T.unsafe(tmp).content)
817
819
  end
818
820
  rescue Octokit::Forbidden => e
819
821
  raise unless e.message.include?("too_large")
@@ -825,10 +827,10 @@ module Dependabot
825
827
  file_details = repo_contents(dir: dir).find { |f| f.name == basename }
826
828
  raise unless file_details
827
829
 
828
- tmp = T.unsafe(github_client).blob(repo, file_details.sha)
829
- return tmp.content if tmp.encoding == "utf-8"
830
+ tmp = github_client.blob(repo, file_details.sha)
831
+ return T.unsafe(tmp).content if T.unsafe(tmp).encoding == "utf-8"
830
832
 
831
- decode_binary_string(tmp.content)
833
+ decode_binary_string(T.unsafe(tmp).content)
832
834
  end
833
835
  # rubocop:enable Metrics/AbcSize
834
836
 
@@ -124,7 +124,22 @@ module Dependabot
124
124
  .returns(Dependabot::DependencyFile)
125
125
  end
126
126
  def create_dependency_file(parameters)
127
- Dependabot::DependencyFile.new(**T.unsafe(parameters))
127
+ Dependabot::DependencyFile.new(
128
+ name: parameters.fetch(:name),
129
+ content: parameters[:content],
130
+ directory: parameters.fetch(:directory, "/"),
131
+ type: parameters.fetch(:type, "file"),
132
+ support_file: parameters.fetch(:support_file, false),
133
+ vendored_file: parameters.fetch(:vendored_file, false),
134
+ symlink_target: parameters[:symlink_target],
135
+ content_encoding: parameters.fetch(
136
+ :content_encoding,
137
+ Dependabot::DependencyFile::ContentEncoding::UTF_8
138
+ ),
139
+ deleted: parameters.fetch(:deleted, false),
140
+ operation: parameters.fetch(:operation, Dependabot::DependencyFile::Operation::UPDATE),
141
+ mode: parameters[:mode]
142
+ )
128
143
  end
129
144
  end
130
145
  end
@@ -37,7 +37,22 @@ module Dependabot
37
37
  .returns(Dependabot::DependencyFile)
38
38
  end
39
39
  def create_dependency_file(parameters)
40
- Dependabot::DependencyFile.new(**T.unsafe({ **parameters, vendored_file: true }))
40
+ Dependabot::DependencyFile.new(
41
+ name: parameters.fetch(:name),
42
+ content: parameters[:content],
43
+ directory: parameters.fetch(:directory, "/"),
44
+ type: parameters.fetch(:type, "file"),
45
+ support_file: parameters.fetch(:support_file, false),
46
+ vendored_file: true,
47
+ symlink_target: parameters[:symlink_target],
48
+ content_encoding: parameters.fetch(
49
+ :content_encoding,
50
+ Dependabot::DependencyFile::ContentEncoding::UTF_8
51
+ ),
52
+ deleted: parameters.fetch(:deleted, false),
53
+ operation: parameters.fetch(:operation, Dependabot::DependencyFile::Operation::UPDATE),
54
+ mode: parameters[:mode]
55
+ )
41
56
  end
42
57
  end
43
58
  end
@@ -463,7 +463,7 @@ module Dependabot
463
463
  .for_github_dot_com(credentials: credentials)
464
464
 
465
465
  # TODO: create this method instead of relying on method_missing
466
- T.unsafe(client).compare(listing_source_repo, ref1, ref2).status
466
+ T.unsafe(client.compare(T.must(listing_source_repo), ref1, ref2)).status
467
467
  end
468
468
 
469
469
  sig { params(ref1: String, ref2: String).returns(String) }
@@ -471,10 +471,10 @@ module Dependabot
471
471
  client = Clients::GitlabWithRetries
472
472
  .for_gitlab_dot_com(credentials: credentials)
473
473
 
474
- comparison = T.unsafe(client).compare(listing_source_repo, ref1, ref2)
474
+ comparison = client.compare(T.must(listing_source_repo), ref1, ref2)
475
475
 
476
- if comparison.commits.none? then "behind"
477
- elsif comparison.compare_same_ref then "identical"
476
+ if T.unsafe(comparison).commits.none? then "behind"
477
+ elsif T.unsafe(comparison).compare_same_ref then "identical"
478
478
  else
479
479
  "ahead"
480
480
  end
@@ -489,7 +489,7 @@ module Dependabot
489
489
  client = Clients::BitbucketWithRetries
490
490
  .for_bitbucket_dot_org(credentials: credentials)
491
491
 
492
- response = T.unsafe(client).get(url)
492
+ response = client.get(url)
493
493
 
494
494
  # Conservatively assume that ref2 is ahead in the equality case, of
495
495
  # if we get an unexpected format (e.g., due to a 404)
@@ -688,7 +688,7 @@ module Dependabot
688
688
  source: T.must(source),
689
689
  credentials: credentials
690
690
  )
691
- T.unsafe(client).releases(T.must(source).repo, per_page: 100)
691
+ client.releases(T.must(source).repo, per_page: 100)
692
692
  rescue Octokit::Error
693
693
  []
694
694
  end,
@@ -102,7 +102,7 @@ module Dependabot
102
102
  @suggested_changelog_url = @suggested_changelog_url&.split("#")&.first
103
103
 
104
104
  @new_version = T.let(nil, T.nilable(String))
105
- @changelog_from_suggested_url = T.let(nil, T.untyped)
105
+ @changelog_from_suggested_url = T.let(nil, T.nilable(Sawyer::Resource))
106
106
  end
107
107
 
108
108
  sig { returns(T.nilable(String)) }
@@ -172,7 +172,7 @@ module Dependabot
172
172
 
173
173
  opts = { path: suggested_source&.directory, ref: suggested_source&.branch }.compact
174
174
  suggested_source_client = github_client_for_source(T.must(suggested_source))
175
- tmp_files = T.unsafe(suggested_source_client).contents(suggested_source&.repo, opts)
175
+ tmp_files = suggested_source_client.contents(T.must(suggested_source).repo, opts)
176
176
 
177
177
  filename = T.must(T.must(suggested_changelog_url).split("/").last)
178
178
  @changelog_from_suggested_url =
@@ -290,7 +290,7 @@ module Dependabot
290
290
  sig { params(file_source: Dependabot::Source, file: T.untyped).returns(String) }
291
291
  def fetch_github_file(file_source, file)
292
292
  # Hitting the download URL directly causes encoding problems
293
- raw_content = T.unsafe(github_client_for_source(file_source)).get(file.url).content
293
+ raw_content = T.unsafe(github_client_for_source(file_source).get(file.url)).content
294
294
  Base64.decode64(raw_content).force_encoding("UTF-8").encode
295
295
  end
296
296
 
@@ -305,8 +305,8 @@ module Dependabot
305
305
 
306
306
  sig { params(file: T.untyped).returns(String) }
307
307
  def fetch_bitbucket_file(file)
308
- T.unsafe(bitbucket_client).get(file.download_url).body
309
- .force_encoding("UTF-8").encode
308
+ bitbucket_client.get(file.download_url).body
309
+ .force_encoding("UTF-8").encode
310
310
  end
311
311
 
312
312
  sig { params(file: T.untyped).returns(String) }
@@ -349,37 +349,34 @@ module Dependabot
349
349
  end
350
350
  end
351
351
 
352
- # rubocop:disable Metrics/AbcSize
353
352
  sig { params(ref: T.nilable(String)).returns(T::Array[T.untyped]) }
354
353
  def fetch_github_file_list(ref)
355
354
  files = []
356
355
 
357
356
  if T.must(source).directory
358
357
  opts = { path: T.must(source).directory, ref: ref }.compact
359
- tmp_files = T.unsafe(github_client).contents(T.must(source).repo, opts)
358
+ tmp_files = github_client.contents(T.must(source).repo, opts)
360
359
  files += tmp_files if tmp_files.is_a?(Array)
361
360
  end
362
361
 
363
362
  opts = { ref: ref }.compact
364
- files += T.unsafe(github_client).contents(T.must(source).repo, opts)
363
+ files += github_client.contents(T.must(source).repo, opts)
365
364
 
366
365
  files.uniq.each do |f|
367
366
  next unless f.type == "dir" && f.name.match?(/docs?/o)
368
367
 
369
368
  opts = { path: f.path, ref: ref }.compact
370
- files += T.unsafe(github_client).contents(T.must(source).repo, opts)
369
+ files += github_client.contents(T.must(source).repo, opts)
371
370
  end
372
371
 
373
372
  files
374
373
  rescue Octokit::NotFound, Octokit::UnavailableForLegalReasons
375
374
  []
376
375
  end
377
- # rubocop:enable Metrics/AbcSize
378
-
379
376
  sig { returns(T.untyped) }
380
377
  def fetch_bitbucket_file_list
381
378
  branch = default_bitbucket_branch
382
- T.unsafe(bitbucket_client).fetch_repo_contents(T.must(source).repo).map do |file|
379
+ bitbucket_client.fetch_repo_contents(T.must(source).repo).map do |file|
383
380
  type = case file.fetch("type")
384
381
  when "commit_file" then "file"
385
382
  when "commit_directory" then "dir"
@@ -402,7 +399,7 @@ module Dependabot
402
399
  sig { returns(T.untyped) }
403
400
  def fetch_gitlab_file_list
404
401
  branch = default_gitlab_branch
405
- T.unsafe(gitlab_client).repo_tree(T.must(source).repo).map do |file|
402
+ T.unsafe(gitlab_client.repo_tree(T.must(source).repo)).map do |file|
406
403
  type = case file.type
407
404
  when "blob" then "file"
408
405
  when "tree" then "dir"
@@ -544,7 +541,7 @@ module Dependabot
544
541
  def default_bitbucket_branch
545
542
  @default_bitbucket_branch ||=
546
543
  T.let(
547
- T.unsafe(bitbucket_client).fetch_default_branch(T.must(source).repo),
544
+ bitbucket_client.fetch_default_branch(T.must(source).repo),
548
545
  T.nilable(String)
549
546
  )
550
547
  end
@@ -282,13 +282,15 @@ module Dependabot
282
282
 
283
283
  args = { sha: previous_tag, path: path }.compact
284
284
  previous_commit_shas =
285
- T.unsafe(github_client).commits(repo, **args).map(&:sha)
285
+ T.unsafe(github_client.commits(repo, **args)).map(&:sha)
286
286
 
287
287
  # NOTE: We reverse this so it's consistent with the array we get
288
288
  # from `github_client.compare(...)`
289
289
  args = { sha: new_tag, path: path }.compact
290
- T.unsafe(github_client)
291
- .commits(repo, **args)
290
+ T.unsafe(
291
+ github_client
292
+ .commits(repo, **args)
293
+ )
292
294
  .reject { |c| previous_commit_shas.include?(c.sha) }.reverse
293
295
  end
294
296
  return [] unless commits
@@ -306,9 +308,9 @@ module Dependabot
306
308
 
307
309
  sig { returns(T::Array[T::Hash[Symbol, String]]) }
308
310
  def fetch_bitbucket_commits
309
- T.unsafe(bitbucket_client)
310
- .compare(T.must(source).repo, previous_tag, new_tag)
311
- .map do |commit|
311
+ bitbucket_client
312
+ .compare(T.must(source).repo, T.must(previous_tag), T.must(new_tag))
313
+ .map do |commit|
312
314
  {
313
315
  message: commit.dig("summary", "raw"),
314
316
  sha: commit["hash"],
@@ -326,8 +328,10 @@ module Dependabot
326
328
 
327
329
  sig { returns(T::Array[T::Hash[Symbol, String]]) }
328
330
  def fetch_gitlab_commits
329
- T.unsafe(gitlab_client)
330
- .compare(T.must(source).repo, previous_tag, new_tag)
331
+ T.unsafe(
332
+ gitlab_client
333
+ .compare(T.must(source).repo, T.must(previous_tag), T.must(new_tag))
334
+ )
331
335
  .commits
332
336
  .map do |commit|
333
337
  {
@@ -281,21 +281,21 @@ module Dependabot
281
281
 
282
282
  sig { returns(T::Array[T.untyped]) }
283
283
  def fetch_github_releases
284
- releases = T.unsafe(github_client).releases(T.must(source).repo, per_page: 100)
284
+ releases = github_client.releases(T.must(source).repo, per_page: 100)
285
285
 
286
286
  # Remove any releases without a tag name. These are draft releases and
287
287
  # aren't yet associated with a tag, so shouldn't be used.
288
- releases = releases.reject { |r| r.tag_name.nil? }
288
+ releases = releases.reject { |r| T.unsafe(r).tag_name.nil? }
289
289
 
290
290
  clean_release_names =
291
- releases.map { |r| r.tag_name.gsub(/^[^0-9\.]*/, "") }
291
+ releases.map { |r| T.unsafe(r).tag_name.gsub(/^[^0-9\.]*/, "") }
292
292
 
293
293
  if clean_release_names.all? { |nm| version_class.correct?(nm) }
294
294
  releases.sort_by do |r|
295
- version_class.new(r.tag_name.gsub(/^[^0-9\.]*/, ""))
295
+ version_class.new(T.unsafe(r).tag_name.gsub(/^[^0-9\.]*/, ""))
296
296
  end.reverse
297
297
  else
298
- releases.sort_by(&:id).reverse
298
+ releases.sort_by { |r| T.unsafe(r).id }.reverse
299
299
  end
300
300
  rescue Octokit::NotFound, Octokit::UnavailableForLegalReasons
301
301
  []
@@ -304,18 +304,20 @@ module Dependabot
304
304
  sig { returns(T::Array[T.untyped]) }
305
305
  def fetch_gitlab_releases
306
306
  releases =
307
- T.unsafe(gitlab_client)
308
- .tags(T.must(source).repo)
307
+ T.unsafe(
308
+ gitlab_client
309
+ .tags(T.must(source).repo)
310
+ )
309
311
  .select(&:release)
310
- .sort_by { |r| r.commit.authored_date }
312
+ .sort_by { |r| T.unsafe(r).commit.authored_date }
311
313
  .reverse
312
314
 
313
315
  releases.map do |tag|
314
316
  GitLabRelease.new(
315
- name: tag.name,
316
- tag_name: tag.release.tag_name,
317
- body: tag.release.description,
318
- html_url: "#{T.must(source).url}/tags/#{tag.name}"
317
+ name: T.unsafe(tag).name,
318
+ tag_name: T.unsafe(tag).release.tag_name,
319
+ body: T.unsafe(tag).release.description,
320
+ html_url: "#{T.must(source).url}/tags/#{T.unsafe(tag).name}"
319
321
  )
320
322
  end
321
323
  rescue Gitlab::Error::NotFound
@@ -323,11 +323,16 @@ module Dependabot
323
323
 
324
324
  sig { returns(T::Boolean) }
325
325
  def wants_prerelease?
326
- return version_class.new(dependency.version).prerelease? if dependency.version
326
+ return true if dependency.numeric_version&.prerelease?
327
327
 
328
328
  dependency.requirements.any? do |req|
329
- reqs = (req.fetch(:requirement) || "").split(",").map(&:strip)
330
- reqs.any? { |r| r.match?(/[A-Za-z]/) }
329
+ req_string = req.fetch(:requirement) || ""
330
+ req_string.split(",").map(&:strip).any? do |r|
331
+ version_str = r.gsub(/^\s*[!<>=~^]+\s*/, "").strip
332
+ next false unless version_class.correct?(version_str)
333
+
334
+ version_class.new(version_str).prerelease?
335
+ end
331
336
  end
332
337
  end
333
338
 
@@ -196,7 +196,7 @@ module Dependabot
196
196
  @pull_requests_for_branch ||=
197
197
  T.let(
198
198
  begin
199
- T.unsafe(github_client_for_source).pull_requests(
199
+ github_client_for_source.pull_requests(
200
200
  source.repo,
201
201
  head: "#{source.repo.split('/').first}:#{branch_name}",
202
202
  state: "all"
@@ -204,13 +204,13 @@ module Dependabot
204
204
  rescue Octokit::InternalServerError
205
205
  # A GitHub bug sometimes means adding `state: all` causes problems.
206
206
  # In that case, fall back to making two separate requests.
207
- open_prs = T.unsafe(github_client_for_source).pull_requests(
207
+ open_prs = github_client_for_source.pull_requests(
208
208
  source.repo,
209
209
  head: "#{source.repo.split('/').first}:#{branch_name}",
210
210
  state: "open"
211
211
  )
212
212
 
213
- closed_prs = T.unsafe(github_client_for_source).pull_requests(
213
+ closed_prs = github_client_for_source.pull_requests(
214
214
  source.repo,
215
215
  head: "#{source.repo.split('/').first}:#{branch_name}",
216
216
  state: "closed"
@@ -254,7 +254,7 @@ module Dependabot
254
254
 
255
255
  sig { returns(T::Boolean) }
256
256
  def repo_exists?
257
- T.unsafe(github_client_for_source).repo(source.repo)
257
+ github_client_for_source.repo(source.repo)
258
258
  true
259
259
  rescue Octokit::NotFound
260
260
  false
@@ -265,7 +265,7 @@ module Dependabot
265
265
  tree = create_tree
266
266
 
267
267
  begin
268
- T.unsafe(github_client_for_source).create_commit(
268
+ github_client_for_source.create_commit(
269
269
  source.repo,
270
270
  commit_message,
271
271
  tree.sha,
@@ -317,8 +317,8 @@ module Dependabot
317
317
  content = if file.operation == Dependabot::DependencyFile::Operation::DELETE
318
318
  { sha: nil }
319
319
  elsif file.binary?
320
- sha = T.unsafe(github_client_for_source).create_blob(
321
- source.repo, file.content, "base64"
320
+ sha = github_client_for_source.create_blob(
321
+ source.repo, T.must(file.content), "base64"
322
322
  )
323
323
  { sha: sha }
324
324
  else
@@ -333,7 +333,7 @@ module Dependabot
333
333
  end
334
334
  end
335
335
 
336
- T.unsafe(github_client_for_source).create_tree(
336
+ github_client_for_source.create_tree(
337
337
  source.repo,
338
338
  file_trees,
339
339
  base_tree: base_commit
@@ -365,7 +365,7 @@ module Dependabot
365
365
 
366
366
  begin
367
367
  branch =
368
- T.unsafe(github_client_for_source).create_ref(source.repo, ref, commit.sha)
368
+ github_client_for_source.create_ref(source.repo, ref, commit.sha)
369
369
  @branch_name = ref.gsub(%r{^refs/heads/}, "")
370
370
  branch
371
371
  rescue Octokit::UnprocessableEntity => e
@@ -385,7 +385,7 @@ module Dependabot
385
385
 
386
386
  sig { params(commit: T.untyped).void }
387
387
  def update_branch(commit)
388
- T.unsafe(github_client_for_source).update_ref(
388
+ github_client_for_source.update_ref(
389
389
  source.repo,
390
390
  "heads/#{branch_name}",
391
391
  commit.sha,
@@ -406,7 +406,7 @@ module Dependabot
406
406
  reviewers_hash =
407
407
  T.must(reviewers).keys.to_h { |k| [k.to_sym, T.must(reviewers)[k]] }
408
408
 
409
- T.unsafe(github_client_for_source).request_pull_request_review(
409
+ github_client_for_source.request_pull_request_review(
410
410
  source.repo,
411
411
  pull_request.number,
412
412
  reviewers: reviewers_hash[:reviewers] || [],
@@ -458,7 +458,7 @@ module Dependabot
458
458
  "#{message}\n" \
459
459
  "```"
460
460
 
461
- T.unsafe(github_client_for_source).add_comment(
461
+ github_client_for_source.add_comment(
462
462
  source.repo,
463
463
  pull_request.number,
464
464
  msg
@@ -467,10 +467,10 @@ module Dependabot
467
467
 
468
468
  sig { params(pull_request: T.untyped).void }
469
469
  def add_assignees_to_pull_request(pull_request)
470
- T.unsafe(github_client_for_source).add_assignees(
470
+ github_client_for_source.add_assignees(
471
471
  source.repo,
472
472
  pull_request.number,
473
- assignees
473
+ T.must(assignees)
474
474
  )
475
475
  rescue Octokit::NotFound
476
476
  # This can happen if a passed assignee login is now an org account
@@ -482,7 +482,7 @@ module Dependabot
482
482
 
483
483
  sig { params(pull_request: T.untyped).void }
484
484
  def add_milestone_to_pull_request(pull_request)
485
- T.unsafe(github_client_for_source).update_issue(
485
+ github_client_for_source.update_issue(
486
486
  source.repo,
487
487
  pull_request.number,
488
488
  milestone: milestone
@@ -493,7 +493,7 @@ module Dependabot
493
493
 
494
494
  sig { returns(T.untyped) }
495
495
  def create_pull_request
496
- T.unsafe(github_client_for_source).create_pull_request(
496
+ github_client_for_source.create_pull_request(
497
497
  source.repo,
498
498
  target_branch,
499
499
  branch_name,
@@ -521,7 +521,7 @@ module Dependabot
521
521
  def default_branch
522
522
  @default_branch ||=
523
523
  T.let(
524
- T.unsafe(github_client_for_source).repo(source.repo).default_branch,
524
+ T.unsafe(github_client_for_source.repo(source.repo)).default_branch,
525
525
  T.nilable(String)
526
526
  )
527
527
  end
@@ -143,7 +143,7 @@ module Dependabot
143
143
  def branch_exists?
144
144
  @branch_ref ||=
145
145
  T.let(
146
- T.unsafe(gitlab_client_for_source).branch(source.repo, branch_name),
146
+ gitlab_client_for_source.branch(source.repo, branch_name),
147
147
  T.nilable(::Gitlab::ObjectifiedHash)
148
148
  )
149
149
  true
@@ -155,25 +155,27 @@ module Dependabot
155
155
  def commit_exists?
156
156
  @commits ||=
157
157
  T.let(
158
- T.unsafe(gitlab_client_for_source).commits(source.repo, ref_name: branch_name),
158
+ gitlab_client_for_source.commits(source.repo, ref_name: branch_name),
159
159
  T.nilable(::Gitlab::PaginatedResponse)
160
160
  )
161
- @commits.first.message == commit_message
161
+ T.unsafe(@commits).first.message == commit_message
162
162
  end
163
163
 
164
164
  sig { returns(T::Boolean) }
165
165
  def merge_request_exists?
166
- T.unsafe(gitlab_client_for_source).merge_requests(
167
- target_project_id || source.repo,
168
- source_branch: branch_name,
169
- target_branch: source.branch || default_branch,
170
- state: "all"
166
+ T.unsafe(
167
+ gitlab_client_for_source.merge_requests(
168
+ (target_project_id || source.repo).to_s,
169
+ source_branch: branch_name,
170
+ target_branch: source.branch || default_branch,
171
+ state: "all"
172
+ )
171
173
  ).any?
172
174
  end
173
175
 
174
176
  sig { returns(::Gitlab::ObjectifiedHash) }
175
177
  def create_branch
176
- T.unsafe(gitlab_client_for_source).create_branch(
178
+ gitlab_client_for_source.create_branch(
177
179
  source.repo,
178
180
  branch_name,
179
181
  base_commit
@@ -201,7 +203,7 @@ module Dependabot
201
203
  def create_submodule_update_commit
202
204
  file = T.must(files.first)
203
205
 
204
- T.unsafe(gitlab_client_for_source).edit_submodule(
206
+ gitlab_client_for_source.edit_submodule(
205
207
  source.repo,
206
208
  file.path.gsub(%r{^/}, ""),
207
209
  branch: branch_name,
@@ -212,7 +214,7 @@ module Dependabot
212
214
 
213
215
  sig { returns(T.nilable(::Gitlab::ObjectifiedHash)) }
214
216
  def create_merge_request
215
- T.unsafe(gitlab_client_for_source).create_merge_request(
217
+ gitlab_client_for_source.create_merge_request(
216
218
  source.repo,
217
219
  pr_name,
218
220
  source_branch: branch_name,
@@ -236,8 +238,8 @@ module Dependabot
236
238
  def add_approvers_to_merge_request(merge_request)
237
239
  return unless approvers_hash[:approvers] || approvers_hash[:group_approvers]
238
240
 
239
- T.unsafe(gitlab_client_for_source).create_merge_request_level_rule(
240
- target_project_id || source.repo,
241
+ gitlab_client_for_source.create_merge_request_level_rule(
242
+ (target_project_id || source.repo).to_s,
241
243
  T.unsafe(merge_request).iid,
242
244
  name: "dependency-updates",
243
245
  approvals_required: 1,
@@ -258,7 +260,7 @@ module Dependabot
258
260
  def default_branch
259
261
  @default_branch ||=
260
262
  T.let(
261
- T.unsafe(gitlab_client_for_source).project(source.repo).default_branch,
263
+ T.unsafe(gitlab_client_for_source.project(source.repo)).default_branch,
262
264
  T.nilable(String)
263
265
  )
264
266
  end
@@ -92,7 +92,7 @@ module Dependabot
92
92
  return if labels_for_pr.none?
93
93
  raise "Only GitHub!" unless source.provider == "github"
94
94
 
95
- T.unsafe(github_client_for_source).add_labels_to_an_issue(
95
+ github_client_for_source.add_labels_to_an_issue(
96
96
  source.repo,
97
97
  pull_request_number,
98
98
  labels_for_pr
@@ -320,16 +320,16 @@ module Dependabot
320
320
  def fetch_github_labels
321
321
  client = github_client_for_source
322
322
 
323
- labels =
324
- T.unsafe(client)
325
- .labels(source.repo, per_page: 100)
326
- .map(&:name)
323
+ labels = T.let(
324
+ T.unsafe(client.labels(source.repo, per_page: 100)).map(&:name),
325
+ T::Array[String]
326
+ )
327
327
 
328
- next_link = T.unsafe(client).last_response.rels[:next]
328
+ next_link = T.let(client.last_response.rels[:next], T.nilable(Sawyer::Relation))
329
329
 
330
330
  while next_link
331
- next_page = next_link.get
332
- labels += next_page.data.map(&:name)
331
+ next_page = T.let(next_link.get, Sawyer::Response)
332
+ labels += T.unsafe(next_page.data).map(&:name)
333
333
  next_link = next_page.rels[:next]
334
334
  end
335
335
 
@@ -338,9 +338,11 @@ module Dependabot
338
338
 
339
339
  sig { returns(T::Array[String]) }
340
340
  def fetch_gitlab_labels
341
- T.unsafe(gitlab_client_for_source)
342
- .labels(source.repo, per_page: 100)
343
- .auto_paginate
341
+ T.unsafe(
342
+ gitlab_client_for_source
343
+ .labels(source.repo, per_page: 100)
344
+ .auto_paginate
345
+ )
344
346
  .map(&:name)
345
347
  end
346
348
 
@@ -390,7 +392,7 @@ module Dependabot
390
392
 
391
393
  sig { returns(T::Array[String]) }
392
394
  def create_github_dependencies_label
393
- T.unsafe(github_client_for_source).add_label(
395
+ github_client_for_source.add_label(
394
396
  source.repo,
395
397
  DEFAULT_DEPENDENCIES_LABEL,
396
398
  "0366d6",
@@ -406,7 +408,7 @@ module Dependabot
406
408
 
407
409
  sig { returns(T::Array[String]) }
408
410
  def create_gitlab_dependencies_label
409
- T.unsafe(gitlab_client_for_source).create_label(
411
+ gitlab_client_for_source.create_label(
410
412
  source.repo,
411
413
  DEFAULT_DEPENDENCIES_LABEL,
412
414
  "#0366d6",
@@ -417,7 +419,7 @@ module Dependabot
417
419
 
418
420
  sig { returns(T::Array[String]) }
419
421
  def create_github_security_label
420
- T.unsafe(github_client_for_source).add_label(
422
+ github_client_for_source.add_label(
421
423
  source.repo,
422
424
  DEFAULT_SECURITY_LABEL,
423
425
  "ee0701",
@@ -433,7 +435,7 @@ module Dependabot
433
435
 
434
436
  sig { returns(T.nilable(T::Array[String])) }
435
437
  def create_gitlab_security_label
436
- T.unsafe(gitlab_client_for_source).create_label(
438
+ gitlab_client_for_source.create_label(
437
439
  source.repo,
438
440
  DEFAULT_SECURITY_LABEL,
439
441
  "#ee0701",
@@ -446,7 +448,7 @@ module Dependabot
446
448
  def create_github_language_label
447
449
  label = self.class.label_details_for_package_manager(package_manager)
448
450
  language_name = label.fetch(:name)
449
- T.unsafe(github_client_for_source).add_label(
451
+ github_client_for_source.add_label(
450
452
  source.repo,
451
453
  language_name,
452
454
  label.fetch(:colour),
@@ -470,7 +472,7 @@ module Dependabot
470
472
  language_name =
471
473
  self.class.label_details_for_package_manager(package_manager)
472
474
  .fetch(:name)
473
- T.unsafe(gitlab_client_for_source).create_label(
475
+ gitlab_client_for_source.create_label(
474
476
  source.repo,
475
477
  language_name,
476
478
  "#" + self.class.label_details_for_package_manager(package_manager)
@@ -347,7 +347,7 @@ module Dependabot
347
347
  sig { returns(T::Array[String]) }
348
348
  def recent_gitlab_commit_messages
349
349
  @recent_gitlab_commit_messages ||=
350
- T.unsafe(gitlab_client_for_source).commits(source.repo)
350
+ gitlab_client_for_source.commits(source.repo)
351
351
 
352
352
  @recent_gitlab_commit_messages
353
353
  .reject { |c| c.author_email == dependabot_email }
@@ -431,7 +431,7 @@ module Dependabot
431
431
  def recent_github_commits
432
432
  @recent_github_commits ||=
433
433
  T.let(
434
- T.unsafe(github_client_for_source).commits(source.repo, per_page: 100),
434
+ github_client_for_source.commits(source.repo, per_page: 100),
435
435
  T.untyped
436
436
  )
437
437
  rescue Octokit::Conflict, Octokit::NotFound
@@ -442,7 +442,7 @@ module Dependabot
442
442
  def last_gitlab_dependabot_commit_message
443
443
  @recent_gitlab_commit_messages ||=
444
444
  T.let(
445
- T.unsafe(gitlab_client_for_source).commits(source.repo),
445
+ gitlab_client_for_source.commits(source.repo),
446
446
  T.untyped
447
447
  )
448
448
 
@@ -91,7 +91,7 @@ module Dependabot
91
91
  target_branch = source.branch || pull_request.base.repo.default_branch
92
92
  return if target_branch == pull_request.base.ref
93
93
 
94
- T.unsafe(github_client_for_source).update_pull_request(
94
+ github_client_for_source.update_pull_request(
95
95
  source.repo,
96
96
  pull_request_number,
97
97
  base: target_branch
@@ -137,7 +137,7 @@ module Dependabot
137
137
  def pull_request
138
138
  @pull_request ||=
139
139
  T.let(
140
- T.unsafe(github_client_for_source).pull_request(
140
+ github_client_for_source.pull_request(
141
141
  source.repo,
142
142
  pull_request_number
143
143
  ),
@@ -147,7 +147,7 @@ module Dependabot
147
147
 
148
148
  sig { params(name: String).returns(T::Boolean) }
149
149
  def branch_exists?(name)
150
- T.unsafe(github_client_for_source).branch(source.repo, name)
150
+ github_client_for_source.branch(source.repo, name)
151
151
  true
152
152
  rescue Octokit::NotFound
153
153
  false
@@ -165,7 +165,7 @@ module Dependabot
165
165
  end
166
166
 
167
167
  begin
168
- T.unsafe(github_client_for_source).create_commit(
168
+ github_client_for_source.create_commit(
169
169
  source.repo,
170
170
  commit_message,
171
171
  tree.sha,
@@ -200,8 +200,8 @@ module Dependabot
200
200
  content = if file.operation == Dependabot::DependencyFile::Operation::DELETE
201
201
  { sha: nil }
202
202
  elsif file.binary?
203
- sha = T.unsafe(github_client_for_source).create_blob(
204
- source.repo, file.content, "base64"
203
+ sha = github_client_for_source.create_blob(
204
+ source.repo, T.must(file.content), "base64"
205
205
  )
206
206
  { sha: sha }
207
207
  else
@@ -216,7 +216,7 @@ module Dependabot
216
216
  end
217
217
  end
218
218
 
219
- T.unsafe(github_client_for_source).create_tree(
219
+ github_client_for_source.create_tree(
220
220
  source.repo,
221
221
  file_trees,
222
222
  base_tree: base_commit
@@ -240,7 +240,7 @@ module Dependabot
240
240
 
241
241
  sig { params(commit: T.untyped).returns(T.untyped) }
242
242
  def update_branch(commit)
243
- T.unsafe(github_client_for_source).update_ref(
243
+ github_client_for_source.update_ref(
244
244
  source.repo,
245
245
  "heads/" + pull_request.head.ref,
246
246
  commit.sha,
@@ -279,12 +279,14 @@ module Dependabot
279
279
  @commit_being_updated =
280
280
  T.let(
281
281
  if pull_request.commits == 1
282
- T.unsafe(github_client_for_source)
282
+ github_client_for_source
283
283
  .git_commit(source.repo, pull_request.head.sha)
284
284
  else
285
285
  commits =
286
- T.unsafe(github_client_for_source)
287
- .pull_request_commits(source.repo, pull_request_number)
286
+ T.unsafe(
287
+ github_client_for_source
288
+ .pull_request_commits(source.repo, pull_request_number)
289
+ )
288
290
 
289
291
  commit = commits.find { |c| c.sha == old_commit }
290
292
  commit&.commit
@@ -108,7 +108,7 @@ module Dependabot
108
108
 
109
109
  sig { params(name: String).returns(T::Boolean) }
110
110
  def branch_exists?(name)
111
- !T.unsafe(gitlab_client_for_source).branch(source.repo, name).nil?
111
+ !gitlab_client_for_source.branch(source.repo, name).nil?
112
112
  rescue ::Gitlab::Error::NotFound
113
113
  false
114
114
  end
@@ -116,7 +116,7 @@ module Dependabot
116
116
  # TODO: This needs to be typed when the underlying client is
117
117
  sig { returns(T.untyped) }
118
118
  def commit_being_updated
119
- T.unsafe(gitlab_client_for_source).commit(source.repo, old_commit)
119
+ gitlab_client_for_source.commit(source.repo, old_commit)
120
120
  end
121
121
 
122
122
  sig { void }
@@ -86,6 +86,7 @@ module Dependabot
86
86
 
87
87
  class HelperSubprocessFailed < Dependabot::DependabotError
88
88
  extend T::Sig
89
+ include Dependabot::HasSentryContext
89
90
 
90
91
  sig { returns(String) }
91
92
  attr_reader :error_class
@@ -112,7 +113,7 @@ module Dependabot
112
113
  @trace = trace
113
114
  end
114
115
 
115
- sig { returns(T::Hash[Symbol, T.untyped]) }
116
+ sig { override.returns(T::Hash[Symbol, T.untyped]) }
116
117
  def sentry_context
117
118
  { fingerprint: [@fingerprint], extra: @error_context.except(:stderr_output, :fingerprint) }
118
119
  end
data/lib/dependabot.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Dependabot
5
- VERSION = "0.380.0"
5
+ VERSION = "0.381.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.380.0
4
+ version: 0.381.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -617,7 +617,7 @@ licenses:
617
617
  - MIT
618
618
  metadata:
619
619
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
620
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.380.0
620
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.381.0
621
621
  rdoc_options: []
622
622
  require_paths:
623
623
  - lib