Skip to content

Commit

Permalink
Fix a Metrics/PerceivedComplexity warning
Browse files Browse the repository at this point in the history
  • Loading branch information
brrygrdn committed Jun 16, 2023
1 parent cb3eaa6 commit 42a6497
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions common/lib/dependabot/file_updaters/artifact_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ def updated_files(base_directory:, only_paths: nil)
operation = Dependabot::DependencyFile::Operation::UPDATE
operation = Dependabot::DependencyFile::Operation::DELETE if type == "D"
operation = Dependabot::DependencyFile::Operation::CREATE if type == "??"
encoding = ""
encoded_content = File.read(path) unless operation == Dependabot::DependencyFile::Operation::DELETE
if binary_file?(path)
encoding = Dependabot::DependencyFile::ContentEncoding::BASE64
if operation != Dependabot::DependencyFile::Operation::DELETE
encoded_content = Base64.encode64(encoded_content)
end
end

encoded_content, encoding = get_encoded_file_contents(path, operation)

create_dependency_file(
name: file_path.to_s,
Expand All @@ -75,6 +69,24 @@ def updated_files(base_directory:, only_paths: nil)

attr_reader :repo_contents_path, :target_directory

def get_encoded_file_contents(path, operation)
encoded_content = nil
encoding = ""

return encoded_content, encoding if operation == Dependabot::DependencyFile::Operation::DELETE

encoded_content = File.read(path)

if binary_file?(path)
encoding = Dependabot::DependencyFile::ContentEncoding::BASE64
if operation != Dependabot::DependencyFile::Operation::DELETE
encoded_content = Base64.encode64(encoded_content)
end
end

[encoded_content, encoding]
end

def binary_file?(path)
return false unless File.exist?(path)

Expand Down

0 comments on commit 42a6497

Please sign in to comment.