class Dependabot::FileUpdaters::VendorUpdater
Constants
- TEXT_ENCODINGS
Attributes
repo_contents_path[R]
vendor_dir[R]
Public Class Methods
new(repo_contents_path:, vendor_dir:)
click to toggle source
# File lib/dependabot/file_updaters/vendor_updater.rb, line 8 def initialize(repo_contents_path:, vendor_dir:) @repo_contents_path = repo_contents_path @vendor_dir = vendor_dir end
Public Instance Methods
updated_vendor_cache_files(base_directory:)
click to toggle source
Returns changed files in the vendor/cache folder
@param base_directory [String] Update config base directory @return [Array<Dependabot::DependencyFile>]
# File lib/dependabot/file_updaters/vendor_updater.rb, line 17 def updated_vendor_cache_files(base_directory:) return [] unless repo_contents_path && vendor_dir Dir.chdir(repo_contents_path) do relative_dir = Pathname.new(vendor_dir).relative_path_from( repo_contents_path ) status = SharedHelpers.run_shell_command( "git status --untracked-files all --porcelain v1 #{relative_dir}" ) changed_paths = status.split("\n").map(&:split) changed_paths.map do |type, path| # The following types are possible to be returned: # M = Modified = Default for DependencyFile # D = Deleted # ?? = Untracked = Created 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 project_root = Pathname.new(File.expand_path(File.join(Dir.pwd, base_directory))) file_path = Pathname.new(path).expand_path.relative_path_from(project_root) Dependabot::DependencyFile.new( name: file_path.to_s, content: encoded_content, directory: base_directory, operation: operation, content_encoding: encoding ) end end end
Private Instance Methods
binary_file?(path)
click to toggle source
# File lib/dependabot/file_updaters/vendor_updater.rb, line 68 def binary_file?(path) return false unless File.exist?(path) encoding = `file -b --mime-encoding #{path}`.strip !TEXT_ENCODINGS.include?(encoding) end