Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict type Dependabot::Hex::FileUpdater::NativeHelpers #9976

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions hex/lib/dependabot/hex/file_updater.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "dependabot/file_updaters"
require "dependabot/file_updaters/base"
require "dependabot/shared_helpers"
require "sorbet-runtime"

module Dependabot
module Hex
class FileUpdater < Dependabot::FileUpdaters::Base
extend T::Sig

require_relative "file_updater/mixfile_updater"
require_relative "file_updater/lockfile_updater"

sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
[
/^mix\.exs$/,
/^mix\.lock$/
]
end

sig { override.returns(T::Array[Dependabot::DependencyFile]) }
def updated_dependency_files
updated_files = []

Expand All @@ -30,40 +35,45 @@ def updated_dependency_files

if lockfile
updated_files <<
updated_file(file: lockfile, content: updated_lockfile_content)
updated_file(file: T.must(lockfile), content: updated_lockfile_content)
end

updated_files
end

private

sig { override.void }
def check_required_files
raise "No mix.exs!" unless get_original_file("mix.exs")
end

sig { params(file: Dependabot::DependencyFile).returns(String) }
def updated_mixfile_content(file)
MixfileUpdater.new(
dependencies: dependencies,
mixfile: file
).updated_mixfile_content
end

sig { returns(String) }
def updated_lockfile_content
@updated_lockfile_content ||=
LockfileUpdater.new(
dependencies: dependencies,
dependency_files: dependency_files,
credentials: credentials
).updated_lockfile_content
@updated_lockfile_content ||= T.let(nil, T.nilable(String))
LockfileUpdater.new(
dependencies: dependencies,
dependency_files: dependency_files,
credentials: credentials
).updated_lockfile_content
end

sig { returns(T::Array[Dependabot::DependencyFile]) }
def mixfiles
dependency_files.select { |f| f.name.end_with?("mix.exs") }
end

sig { returns(T.nilable(Dependabot::DependencyFile)) }
def lockfile
@lockfile ||= get_original_file("mix.lock")
@lockfile ||= T.let(get_original_file("mix.lock"), T.nilable(Dependabot::DependencyFile))
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion hex/lib/dependabot/hex/native_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# typed: true
# typed: strong
# frozen_string_literal: true

require "sorbet-runtime"

module Dependabot
module Hex
module NativeHelpers
extend T::Sig

sig { returns(String) }
def self.hex_helpers_dir
helpers_root = ENV.fetch("DEPENDABOT_NATIVE_HELPERS_PATH", nil)
return File.join(helpers_root, "hex") unless helpers_root.nil?

File.join(__dir__, "../../../../hex/helpers")
end

sig { params(path: String).returns(String) }
def self.clean_path(path)
Pathname.new(path).cleanpath.to_path
end
Expand Down
Loading