Skip to content

Commit

Permalink
directory is the job directory (#8762)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman authored Jan 11, 2024
1 parent 498c343 commit bc4de14
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
14 changes: 4 additions & 10 deletions common/lib/dependabot/dependency_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class DependencyFile
sig { returns(T.nilable(String)) }
attr_accessor :content

# This is the directory of the job source, not the directory of the file itself.
# The name actually contains the relative path from the job directory.
sig { returns(String) }
attr_accessor :directory

Expand All @@ -38,11 +40,6 @@ class DependencyFile
sig { returns(T.nilable(String)) }
attr_accessor :mode

# The directory that this file was fetched for. This is useful for multi-directory
# updates, where a set of files that are related to each other are updated together.
sig { returns(T.nilable(String)) }
attr_accessor :job_directory

class ContentEncoding
UTF_8 = "utf-8"
BASE64 = "base64"
Expand Down Expand Up @@ -71,15 +68,14 @@ class Mode
content_encoding: String,
deleted: T::Boolean,
operation: String,
mode: T.nilable(String),
job_directory: T.nilable(String)
mode: T.nilable(String)
)
.void
end
def initialize(name:, content:, directory: "/", type: "file",
support_file: false, vendored_file: false, symlink_target: nil,
content_encoding: ContentEncoding::UTF_8, deleted: false,
operation: Operation::UPDATE, mode: nil, job_directory: nil)
operation: Operation::UPDATE, mode: nil)
@name = name
@content = content
@directory = T.let(clean_directory(directory), String)
Expand All @@ -88,7 +84,6 @@ def initialize(name:, content:, directory: "/", type: "file",
@vendored_file = vendored_file
@content_encoding = content_encoding
@operation = operation
@job_directory = job_directory

# Make deleted override the operation. Deleted is kept when operation
# was introduced to keep compatibility with downstream dependants.
Expand Down Expand Up @@ -127,7 +122,6 @@ def to_h
"mode" => mode
}

details["job_directory"] = job_directory if job_directory
details["symlink_target"] = symlink_target if symlink_target
details
end
Expand Down
5 changes: 1 addition & 4 deletions common/lib/dependabot/file_fetchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ def target_branch

sig { returns(T::Array[DependencyFile]) }
def files
@files ||= T.let(
fetch_files.each { |f| f.job_directory = directory },
T.nilable(T::Array[DependencyFile])
)
@files ||= T.let(fetch_files, T.nilable(T::Array[DependencyFile]))
end

sig { abstract.returns(T::Array[DependencyFile]) }
Expand Down
5 changes: 1 addition & 4 deletions updater/lib/dependabot/dependency_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def humanized
end

def updated_dependency_files_hash
files = updated_dependency_files.map(&:to_h)
# incidental to the job, no need to send to the server
files.each { |f| f.delete("job_directory") }
files
updated_dependency_files.map(&:to_h)
end

def grouped_update?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def current_dependency_files(job)
directory = Pathname.new(job.source.directory).cleanpath.to_s

@dependency_file_batch.filter_map do |_path, data|
next data[:file] if data[:file].job_directory.nil?
next data[:file] if data[:file].directory.nil?

data[:file] if Pathname.new(data[:file].job_directory).cleanpath.to_s == directory
data[:file] if Pathname.new(data[:file].directory).cleanpath.to_s == directory
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
describe "current_dependency_files" do
let(:files) do
[
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-gemfile", directory: "/", job_directory: "/"),
Dependabot::DependencyFile.new(name: "Gemfile.lock", content: "mock-gemfile-lock", directory: "/hello/..",
job_directory: "/"),
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-package-json", directory: "/elsewhere",
job_directory: "/other"),
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-package-json", directory: "unknown",
job_directory: "/hello"),
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-package-json", directory: "../../oob",
job_directory: "/oob")
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-gemfile", directory: "/"),
Dependabot::DependencyFile.new(name: "Gemfile.lock", content: "mock-gemfile-lock", directory: "/hello/.."),
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-package-json", directory: "/elsewhere"),
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-package-json", directory: "unknown"),
Dependabot::DependencyFile.new(name: "Gemfile", content: "mock-package-json", directory: "../../oob")
]
end

Expand Down

0 comments on commit bc4de14

Please sign in to comment.