Class: Dependabot::FileUpdaters::ArtifactUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/file_updaters/artifact_updater.rb

Direct Known Subclasses

VendorUpdater

Instance Method Summary collapse

Constructor Details

#initialize(repo_contents_path:, target_directory:) ⇒ ArtifactUpdater

Returns a new instance of ArtifactUpdater.



19
20
21
22
# File 'lib/dependabot/file_updaters/artifact_updater.rb', line 19

def initialize(repo_contents_path:, target_directory:)
  @repo_contents_path = repo_contents_path
  @target_directory = target_directory
end

Instance Method Details

#updated_files(base_directory:, only_paths: nil) ⇒ Object



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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dependabot/file_updaters/artifact_updater.rb', line 35

def updated_files(base_directory:, only_paths: nil)
  return [] unless repo_contents_path && target_directory

  Dir.chdir(T.must(repo_contents_path)) do
    # rubocop:disable Performance/DeletePrefix
    relative_dir = Pathname.new(base_directory).sub(%r{\A/}, "").join(T.must(target_directory))
    # rubocop:enable Performance/DeletePrefix

    status = T.let(
      SharedHelpers.run_shell_command(
        "git status --untracked-files all --porcelain v1 #{relative_dir}",
        fingerprint: "git status --untracked-files all --porcelain v1 <relative_dir>"
      ),
      String
    )
    changed_paths = status.split("\n").map(&:split)
    changed_paths.filter_map do |type, path|
      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)

      # Skip this file if we are looking for specific paths and this isn't on the list
      next if only_paths && !only_paths.include?(file_path.to_s)

      # 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 == "??"

      encoded_content, encoding = get_encoded_file_contents(T.must(path), operation)

      create_dependency_file(
        name: file_path.to_s,
        content: encoded_content,
        directory: base_directory,
        operation: operation,
        content_encoding: encoding
      )
    end
  end
end