Class: Dependabot::FileUpdaters::VendorUpdater
- Inherits:
-
Object
- Object
- Dependabot::FileUpdaters::VendorUpdater
- Defined in:
- lib/dependabot/file_updaters/vendor_updater.rb
Instance Method Summary collapse
-
#initialize(repo_contents_path:, vendor_dir:) ⇒ VendorUpdater
constructor
A new instance of VendorUpdater.
-
#updated_vendor_cache_files(base_directory:) ⇒ Array<Dependabot::DependencyFile>
Returns changed files in the vendor/cache folder.
Constructor Details
#initialize(repo_contents_path:, vendor_dir:) ⇒ VendorUpdater
Returns a new instance of VendorUpdater.
8 9 10 11 |
# 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 |
Instance Method Details
#updated_vendor_cache_files(base_directory:) ⇒ Array<Dependabot::DependencyFile>
Returns changed files in the vendor/cache folder
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# 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 { |l| l.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.(File.join(Dir.pwd, base_directory))) file_path = Pathname.new(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 |