dependabot-hex 0.260.0 → 0.261.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39dd9ca7f95a819b66edcc28326f4f0a95b1e3998d34722026c306a0b19fb800
4
- data.tar.gz: 1a55909dce2ef7233bfcf75b48885a4d7c6d0ada3e4a2f61ba285a6ee724de2a
3
+ metadata.gz: 27d33792dfe1e80e7983633d35c802b8e740e597b27511bbf5b62d7d53d2524e
4
+ data.tar.gz: f8a13617553b91170a7dca0a50ebdb3a9d68326961c3919851119e1b6b08b972
5
5
  SHA512:
6
- metadata.gz: 7e319edb1873858b339c1bcdc7063a55e452f6c1d6d5b071e03b49079f9151dd8b4cf5723190d0ec0f349b624a98129a9e41b2debab8c160ae0d66929bb72738
7
- data.tar.gz: 46c804f5470f9fc7969fe24b9e1bf076737786215042baea77f457eac52e67a8c4775e7094dce8faef76675f6d62605fa5100f8d0324fd2e8b72422ed4a58fa2
6
+ metadata.gz: d21ffaea5f67baf3b4c937d578cc1f2f7dc5945d7cdc90e6f7bd28a38309f58b2821aff0df65d41aa3be7d970995bc8792045f23a83da1c4c79f16b730b14e3c
7
+ data.tar.gz: ab89c2440795290fd4088ed5b6d7d705d8d4b2d33f96e396ea3e5c56492c9ab7f943783282cb91b28759ce10e3c00982a27ef0b57c9bb5bb9bbd583cffcdd726
@@ -1,13 +1,19 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  module Dependabot
5
7
  module Hex
6
8
  module CredentialHelpers
9
+ extend T::Sig
10
+
11
+ sig { params(credentials: T::Array[Dependabot::Credential]).returns(T::Array[Dependabot::Credential]) }
7
12
  def self.hex_credentials(credentials)
8
13
  organization_credentials(credentials) + repo_credentials(credentials)
9
14
  end
10
15
 
16
+ sig { params(credentials: T.untyped).returns(T::Array[Dependabot::Credential]) }
11
17
  def self.organization_credentials(credentials)
12
18
  defaults = Dependabot::Credential.new({ "organization" => "", "token" => "" })
13
19
  keys = %w(type organization token)
@@ -16,7 +22,7 @@ module Dependabot
16
22
  .select { |cred| cred["type"] == "hex_organization" }
17
23
  .flat_map { |cred| defaults.merge(cred).slice(*keys).values }
18
24
  end
19
-
25
+ sig { params(credentials: T::Array[Dependabot::Credential]).returns(T::Array[Dependabot::Credential]) }
20
26
  def self.repo_credentials(credentials)
21
27
  # Credentials are serialized as an array that may not have optional fields. Using a
22
28
  # default ensures that the array is always the same length, even if values are empty.
@@ -1,6 +1,7 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
4
5
  require "dependabot/dependency"
5
6
  require "dependabot/file_parsers"
6
7
  require "dependabot/file_parsers/base"
@@ -13,8 +14,10 @@ require "dependabot/errors"
13
14
  module Dependabot
14
15
  module Hex
15
16
  class FileParser < Dependabot::FileParsers::Base
17
+ extend T::Sig
16
18
  require "dependabot/file_parsers/base/dependency_set"
17
19
 
20
+ sig { override.returns(T::Array[Dependabot::Dependency]) }
18
21
  def parse
19
22
  # TODO: git sourced dependency's mixfiles are evaluated. Provide guards before removing this.
20
23
  raise ::Dependabot::UnexpectedExternalCode if @reject_external_code
@@ -43,11 +46,12 @@ module Dependabot
43
46
 
44
47
  private
45
48
 
49
+ sig { returns(T::Array[T.any(T::Hash[String, String], T::Hash[String, T.untyped])]) }
46
50
  def dependency_details
47
51
  SharedHelpers.in_a_temporary_directory do
48
52
  write_sanitized_mixfiles
49
53
  write_sanitized_supporting_files
50
- File.write("mix.lock", lockfile.content) if lockfile
54
+ File.write("mix.lock", lockfile&.content) if lockfile
51
55
  FileUtils.cp(elixir_helper_parse_deps_path, "parse_deps.exs")
52
56
 
53
57
  SharedHelpers.run_helper_subprocess(
@@ -69,28 +73,32 @@ module Dependabot
69
73
  JSON.parse(result_json).fetch("result")
70
74
  end
71
75
 
76
+ sig { void }
72
77
  def write_sanitized_mixfiles
73
78
  mixfiles.each do |file|
74
79
  path = file.name
75
80
  FileUtils.mkdir_p(Pathname.new(path).dirname)
76
- File.write(path, sanitize_mixfile(file.content))
81
+ File.write(path, sanitize_mixfile(T.must(file.content)))
77
82
  end
78
83
  end
79
84
 
85
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
80
86
  def write_sanitized_supporting_files
81
87
  dependency_files.select(&:support_file).each do |file|
82
88
  path = file.name
83
89
  FileUtils.mkdir_p(Pathname.new(path).dirname)
84
- File.write(path, sanitize_mixfile(file.content))
90
+ File.write(path, sanitize_mixfile(T.must(file.content)))
85
91
  end
86
92
  end
87
93
 
94
+ sig { params(content: String).returns(String) }
88
95
  def sanitize_mixfile(content)
89
96
  Hex::FileUpdater::MixfileSanitizer.new(
90
97
  mixfile_content: content
91
98
  ).sanitized_content
92
99
  end
93
100
 
101
+ sig { returns(T::Hash[String, String]) }
94
102
  def mix_env
95
103
  {
96
104
  "MIX_EXS" => File.join(NativeHelpers.hex_helpers_dir, "mix.exs"),
@@ -100,28 +108,34 @@ module Dependabot
100
108
  }
101
109
  end
102
110
 
111
+ sig { returns(String) }
103
112
  def elixir_helper_path
104
113
  File.join(NativeHelpers.hex_helpers_dir, "lib/run.exs")
105
114
  end
106
115
 
116
+ sig { returns(String) }
107
117
  def elixir_helper_parse_deps_path
108
118
  File.join(NativeHelpers.hex_helpers_dir, "lib/parse_deps.exs")
109
119
  end
110
120
 
121
+ sig { override.void }
111
122
  def check_required_files
112
123
  raise "No mixfile!" if mixfiles.none?
113
124
  end
114
125
 
126
+ sig { params(hash: T::Hash[String, String]).returns(T::Hash[Symbol, T.nilable(String)]) }
115
127
  def symbolize_keys(hash)
116
128
  hash.keys.to_h { |k| [k.to_sym, hash[k]] }
117
129
  end
118
130
 
131
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
119
132
  def mixfiles
120
133
  dependency_files.select { |f| f.name.end_with?("mix.exs") }
121
134
  end
122
135
 
136
+ sig { returns(T.nilable(Dependabot::DependencyFile)) }
123
137
  def lockfile
124
- @lockfile ||= get_original_file("mix.lock")
138
+ @lockfile ||= T.let(get_original_file("mix.lock"), T.nilable(Dependabot::DependencyFile))
125
139
  end
126
140
  end
127
141
  end
@@ -1,13 +1,17 @@
1
- # typed: true
1
+ # typed: strong
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "dependabot/hex/file_updater"
5
5
  require "dependabot/shared_helpers"
6
+ require "sorbet-runtime"
6
7
 
7
8
  module Dependabot
8
9
  module Hex
9
10
  class FileUpdater
10
11
  class MixfileGitPinUpdater
12
+ extend T::Sig
13
+
14
+ sig { params(dependency_name: String, mixfile_content: String, previous_pin: String, updated_pin: String).void }
11
15
  def initialize(dependency_name:, mixfile_content:,
12
16
  previous_pin:, updated_pin:)
13
17
  @dependency_name = dependency_name
@@ -16,6 +20,7 @@ module Dependabot
16
20
  @updated_pin = updated_pin
17
21
  end
18
22
 
23
+ sig { returns(String) }
19
24
  def updated_content
20
25
  updated_content = update_pin(mixfile_content)
21
26
 
@@ -26,11 +31,19 @@ module Dependabot
26
31
 
27
32
  private
28
33
 
34
+ sig { returns(String) }
29
35
  attr_reader :dependency_name
36
+
37
+ sig { returns(String) }
30
38
  attr_reader :mixfile_content
39
+
40
+ sig { returns(String) }
31
41
  attr_reader :previous_pin
42
+
43
+ sig { returns(String) }
32
44
  attr_reader :updated_pin
33
45
 
46
+ sig { params(content: String).returns(String) }
34
47
  def update_pin(content)
35
48
  requirement_line_regex =
36
49
  /
@@ -43,6 +56,7 @@ module Dependabot
43
56
  end
44
57
  end
45
58
 
59
+ sig { returns(T::Boolean) }
46
60
  def content_should_change?
47
61
  previous_pin == updated_pin
48
62
  end
@@ -1,20 +1,23 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "dependabot/hex/file_updater"
5
5
  require "dependabot/shared_helpers"
6
+ require "sorbet-runtime"
6
7
 
7
8
  module Dependabot
8
9
  module Hex
9
10
  class FileUpdater
10
11
  class MixfileSanitizer
12
+ extend T::Sig
13
+ sig { params(mixfile_content: String).void }
11
14
  def initialize(mixfile_content:)
12
15
  @mixfile_content = mixfile_content
13
16
  end
14
17
 
15
18
  FILE_READ = /File.read\(.*?\)/
16
19
  FILE_READ_BANG = /File.read!\(.*?\)/
17
- PIPE = Regexp.escape("|>").freeze
20
+ PIPE = T.let(Regexp.escape("|>").freeze, String)
18
21
  VERSION_FILE = /"VERSION"/i
19
22
 
20
23
  NESTED_VERSION_FILE_READ = /String\.trim\(#{FILE_READ}\)/
@@ -22,18 +25,25 @@ module Dependabot
22
25
  PIPED_VERSION_FILE_READ = /#{VERSION_FILE}[[:space:]]+#{PIPE}[[:space:]]+#{FILE_READ}/
23
26
  PIPED_VERSION_FILE_READ_BANG = /#{VERSION_FILE}[[:space:]]+#{PIPE}[[:space:]]+#{FILE_READ_BANG}/
24
27
 
25
- # rubocop:disable Performance/MethodObjectAsBlock
28
+ sig { returns(String) }
26
29
  def sanitized_content
27
- mixfile_content
28
- .then(&method(:prevent_version_file_loading))
29
- .then(&method(:prevent_config_path_loading))
30
+ @mixfile_content
31
+ .then { |content| prevent_version_file_loading(content) }
32
+ .then { |content| prevent_config_path_loading(content) }
30
33
  end
31
- # rubocop:enable Performance/MethodObjectAsBlock
32
34
 
33
35
  private
34
36
 
37
+ sig { returns(String) }
35
38
  attr_reader :mixfile_content
36
39
 
40
+ sig { params(configuration: String).returns(String) }
41
+ def prevent_config_path_loading(configuration)
42
+ configuration
43
+ .gsub(/^\s*config_path:.*(?:,|$)/, "")
44
+ end
45
+
46
+ sig { params(configuration: String).returns(String) }
37
47
  def prevent_version_file_loading(configuration)
38
48
  configuration
39
49
  .gsub(NESTED_VERSION_FILE_READ_BANG, 'String.trim("0.0.1")')
@@ -41,11 +51,6 @@ module Dependabot
41
51
  .gsub(PIPED_VERSION_FILE_READ, '{:ok, "0.0.1"}')
42
52
  .gsub(PIPED_VERSION_FILE_READ_BANG, '"0.0.1"')
43
53
  end
44
-
45
- def prevent_config_path_loading(configuration)
46
- configuration
47
- .gsub(/^\s*config_path:.*(?:,|$)/, "")
48
- end
49
54
  end
50
55
  end
51
56
  end
@@ -1,16 +1,20 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "dependabot/file_updaters"
5
5
  require "dependabot/file_updaters/base"
6
6
  require "dependabot/shared_helpers"
7
+ require "sorbet-runtime"
7
8
 
8
9
  module Dependabot
9
10
  module Hex
10
11
  class FileUpdater < Dependabot::FileUpdaters::Base
12
+ extend T::Sig
13
+
11
14
  require_relative "file_updater/mixfile_updater"
12
15
  require_relative "file_updater/lockfile_updater"
13
16
 
17
+ sig { override.returns(T::Array[Regexp]) }
14
18
  def self.updated_files_regex
15
19
  [
16
20
  /^mix\.exs$/,
@@ -18,6 +22,7 @@ module Dependabot
18
22
  ]
19
23
  end
20
24
 
25
+ sig { override.returns(T::Array[Dependabot::DependencyFile]) }
21
26
  def updated_dependency_files
22
27
  updated_files = []
23
28
 
@@ -30,7 +35,7 @@ module Dependabot
30
35
 
31
36
  if lockfile
32
37
  updated_files <<
33
- updated_file(file: lockfile, content: updated_lockfile_content)
38
+ updated_file(file: T.must(lockfile), content: updated_lockfile_content)
34
39
  end
35
40
 
36
41
  updated_files
@@ -38,10 +43,12 @@ module Dependabot
38
43
 
39
44
  private
40
45
 
46
+ sig { override.void }
41
47
  def check_required_files
42
48
  raise "No mix.exs!" unless get_original_file("mix.exs")
43
49
  end
44
50
 
51
+ sig { params(file: Dependabot::DependencyFile).returns(String) }
45
52
  def updated_mixfile_content(file)
46
53
  MixfileUpdater.new(
47
54
  dependencies: dependencies,
@@ -49,21 +56,24 @@ module Dependabot
49
56
  ).updated_mixfile_content
50
57
  end
51
58
 
59
+ sig { returns(String) }
52
60
  def updated_lockfile_content
53
- @updated_lockfile_content ||=
54
- LockfileUpdater.new(
55
- dependencies: dependencies,
56
- dependency_files: dependency_files,
57
- credentials: credentials
58
- ).updated_lockfile_content
61
+ @updated_lockfile_content ||= T.let(nil, T.nilable(String))
62
+ LockfileUpdater.new(
63
+ dependencies: dependencies,
64
+ dependency_files: dependency_files,
65
+ credentials: credentials
66
+ ).updated_lockfile_content
59
67
  end
60
68
 
69
+ sig { returns(T::Array[Dependabot::DependencyFile]) }
61
70
  def mixfiles
62
71
  dependency_files.select { |f| f.name.end_with?("mix.exs") }
63
72
  end
64
73
 
74
+ sig { returns(T.nilable(Dependabot::DependencyFile)) }
65
75
  def lockfile
66
- @lockfile ||= get_original_file("mix.lock")
76
+ @lockfile ||= T.let(get_original_file("mix.lock"), T.nilable(Dependabot::DependencyFile))
67
77
  end
68
78
  end
69
79
  end
@@ -1,23 +1,27 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "excon"
5
5
  require "dependabot/metadata_finders"
6
6
  require "dependabot/metadata_finders/base"
7
7
  require "dependabot/registry_client"
8
+ require "sorbet-runtime"
8
9
 
9
10
  module Dependabot
10
11
  module Hex
11
12
  class MetadataFinder < Dependabot::MetadataFinders::Base
12
- SOURCE_KEYS = %w(
13
+ extend T::Sig
14
+
15
+ SOURCE_KEYS = T.let(%w(
13
16
  GitHub Github github
14
17
  GitLab Gitlab gitlab
15
18
  BitBucket Bitbucket bitbucket
16
19
  Source source
17
- ).freeze
20
+ ).freeze, T::Array[String])
18
21
 
19
22
  private
20
23
 
24
+ sig { override.returns(T.nilable(Dependabot::Source)) }
21
25
  def look_up_source
22
26
  case new_source_type
23
27
  when "default" then find_source_from_hex_listing
@@ -26,19 +30,22 @@ module Dependabot
26
30
  end
27
31
  end
28
32
 
33
+ sig { returns(T.nilable(String)) }
29
34
  def new_source_type
30
35
  dependency.source_type
31
36
  end
32
37
 
38
+ sig { returns(T.nilable(Dependabot::Source)) }
33
39
  def find_source_from_hex_listing
34
40
  potential_source_urls =
35
41
  SOURCE_KEYS
36
- .filter_map { |key| hex_listing.dig("meta", "links", key) }
42
+ .filter_map { |key| T.must(hex_listing).dig("meta", "links", key) }
37
43
 
38
44
  source_url = potential_source_urls.find { |url| Source.from_url(url) }
39
45
  Source.from_url(source_url)
40
46
  end
41
47
 
48
+ sig { returns(T.nilable(Dependabot::Source)) }
42
49
  def find_source_from_git_url
43
50
  info = dependency.requirements.filter_map { |r| r[:source] }.first
44
51
 
@@ -46,11 +53,12 @@ module Dependabot
46
53
  Source.from_url(url)
47
54
  end
48
55
 
56
+ sig { returns(T.nilable(T::Hash[String, T.untyped])) }
49
57
  def hex_listing
50
58
  return @hex_listing unless @hex_listing.nil?
51
59
 
52
60
  response = Dependabot::RegistryClient.get(url: "https://hex.pm/api/packages/#{dependency.name}")
53
- @hex_listing = JSON.parse(response.body)
61
+ @hex_listing = T.let(JSON.parse(response.body), T.nilable(T::Hash[String, T.untyped]))
54
62
  end
55
63
  end
56
64
  end
@@ -1,9 +1,14 @@
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 Hex
6
8
  module NativeHelpers
9
+ extend T::Sig
10
+
11
+ sig { returns(String) }
7
12
  def self.hex_helpers_dir
8
13
  helpers_root = ENV.fetch("DEPENDABOT_NATIVE_HELPERS_PATH", nil)
9
14
  return File.join(helpers_root, "hex") unless helpers_root.nil?
@@ -11,6 +16,7 @@ module Dependabot
11
16
  File.join(__dir__, "../../../../hex/helpers")
12
17
  end
13
18
 
19
+ sig { params(path: String).returns(String) }
14
20
  def self.clean_path(path)
15
21
  Pathname.new(path).cleanpath.to_path
16
22
  end
@@ -1,6 +1,8 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  require "dependabot/dependency_file"
5
7
  require "dependabot/hex/update_checker"
6
8
  require "dependabot/hex/file_updater/mixfile_requirement_updater"
@@ -14,6 +16,8 @@ module Dependabot
14
16
  # This class takes a set of dependency files and sanitizes them for use
15
17
  # in UpdateCheckers::Elixir::Hex.
16
18
  class FilePreparer
19
+ extend T::Sig
20
+
17
21
  def initialize(dependency_files:, dependency:,
18
22
  unlock_requirement: true,
19
23
  replacement_git_pin: nil,
@@ -179,7 +183,7 @@ module Dependabot
179
183
  end
180
184
 
181
185
  def version_regex
182
- version_class::VERSION_PATTERN
186
+ Dependabot::Hex::Version::VERSION_PATTERN
183
187
  end
184
188
 
185
189
  def dependency_appears_in_file?(file_name)
@@ -1,6 +1,8 @@
1
- # typed: false
1
+ # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "sorbet-runtime"
5
+
4
6
  require "dependabot/version"
5
7
  require "dependabot/utils"
6
8
 
@@ -11,6 +13,8 @@ require "dependabot/utils"
11
13
  module Dependabot
12
14
  module Hex
13
15
  class Version < Dependabot::Version
16
+ extend T::Sig
17
+
14
18
  attr_reader :build_info
15
19
 
16
20
  VERSION_PATTERN = Gem::Version::VERSION_PATTERN + '(\+[0-9a-zA-Z\-.]+)?'
@@ -40,7 +44,7 @@ module Dependabot
40
44
 
41
45
  def <=>(other)
42
46
  version_comparison = super(other)
43
- return version_comparison unless version_comparison.zero?
47
+ return version_comparison unless version_comparison&.zero?
44
48
 
45
49
  return build_info.nil? ? 0 : 1 unless other.is_a?(Hex::Version)
46
50
 
@@ -54,7 +58,7 @@ module Dependabot
54
58
 
55
59
  local_comparison = Gem::Version.new(lhs) <=> Gem::Version.new(rhs)
56
60
 
57
- return local_comparison unless local_comparison.zero?
61
+ return local_comparison unless local_comparison&.zero?
58
62
 
59
63
  lhsegments.count <=> rhsegments.count
60
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-hex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.260.0
4
+ version: 0.261.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-06 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dependabot-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.260.0
19
+ version: 0.261.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.260.0
26
+ version: 0.261.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: debug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -272,7 +272,7 @@ licenses:
272
272
  - MIT
273
273
  metadata:
274
274
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
275
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.260.0
275
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.261.1
276
276
  post_install_message:
277
277
  rdoc_options: []
278
278
  require_paths: