Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach Updater to Invoke fetch files Based on Multi-Dir #8309

Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0b9595d
adding modification to repo_contents to support multi-dir repo_contents
honeyankit Oct 30, 2023
3b673b2
Fixed merge conflicts
honeyankit Oct 31, 2023
7b5bfc9
Invoke dependency_files multiple times based on multi-dir and clean t…
honeyankit Oct 31, 2023
9c36d6a
removed debugger and more cleaning
honeyankit Oct 31, 2023
46720c4
add test cases for file_fetch to support multi-dir
honeyankit Nov 1, 2023
b5f5236
fixed failing test for file_fetcher for multiple dir
honeyankit Nov 1, 2023
5b6e0c1
removed unwanted files and comments
honeyankit Nov 1, 2023
07a1a98
save correct contents of dependency_files when mutli-dir support is e…
honeyankit Nov 1, 2023
913d807
disable the lint warning and added comments related to GHES backward …
honeyankit Nov 2, 2023
6f574ad
updater uses bundler tests so switchting from python to bundler
honeyankit Nov 2, 2023
cd47b18
added bundler fixute and removed python fixture
honeyankit Nov 2, 2023
decbb60
added memoized to dependency_files_for_multi_directories since it get…
honeyankit Nov 2, 2023
215787c
Fixed the test case with unused HTTP interactions left in the cassette
honeyankit Nov 2, 2023
6edcf4d
added the retry for directroy specific loop
honeyankit Nov 2, 2023
55cb097
lint slayer commit
honeyankit Nov 2, 2023
305a91d
added changes back to base.rb from main
honeyankit Nov 2, 2023
b2d7e83
created with_retries helper to remove duplicates retries
honeyankit Nov 2, 2023
4dc1637
reuse all instantiation logic and keep a @file_fetchers instance vari…
honeyankit Nov 4, 2023
f20e59a
memoize the dependency_files method to fix failing smoke test
honeyankit Nov 4, 2023
4d2238f
fixed the ecosystem_versions failing test
honeyankit Nov 4, 2023
cc060a4
Merge branch 'main' into honeyankit/teach-updater-to-use-directories-…
jakecoffman Nov 9, 2023
9db7971
Merge branch 'main' into honeyankit/teach-updater-to-use-directories-…
jakecoffman Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding modification to repo_contents to support multi-dir repo_contents
  • Loading branch information
honeyankit committed Nov 6, 2023
commit 0b9595d97711a6816b6e5065430b7646da2fddf6
65 changes: 51 additions & 14 deletions common/lib/dependabot/file_fetchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def directory
Pathname.new(source.directory || "/").cleanpath.to_path
end

def directories
source.directories.map do |directory|
Pathname.new(directory || "/").cleanpath.to_path
end
end

def target_branch
source.branch
end
Expand Down Expand Up @@ -113,11 +119,13 @@ def ecosystem_versions

private

# multi-dir - Look at this code
def fetch_support_file(name)
fetch_file_if_present(name)&.tap { |f| f.support_file = true }
end

def fetch_file_if_present(filename, fetch_submodules: false)
debugger
unless repo_contents_path.nil?
begin
return load_cloned_file_if_present(filename)
Expand All @@ -135,7 +143,7 @@ def fetch_file_if_present(filename, fetch_submodules: false)
.map(&:name).include?(basename)
return unless repo_includes_basename

fetch_file_from_host(filename, fetch_submodules: fetch_submodules)
fetch_file_from_host(filename, file_dir: dir, fetch_submodules: fetch_submodules)
rescue *CLIENT_NOT_FOUND_ERRORS
nil
end
Expand Down Expand Up @@ -163,10 +171,13 @@ def load_cloned_file_if_present(filename)
)
end

def fetch_file_from_host(filename, type: "file", fetch_submodules: false)
# multi-dir - Change the directory here
def fetch_file_from_host(filename, file_dir: nil, type: "file", fetch_submodules: false)
debugger
return load_cloned_file_if_present(filename) unless repo_contents_path.nil?

path = Pathname.new(File.join(directory, filename)).cleanpath.to_path
# multi-dir - Fix me!!!
path = Pathname.new(File.join(file_dir, filename)).cleanpath.to_path
content = _fetch_file_content(path, fetch_submodules: fetch_submodules)
clean_path = path.gsub(%r{^/}, "")

Expand All @@ -176,7 +187,7 @@ def fetch_file_from_host(filename, type: "file", fetch_submodules: false)

DependencyFile.new(
name: Pathname.new(filename).cleanpath.to_path,
directory: directory,
directory: File.dirname(path),
type: type,
content: content,
symlink_target: symlink_target
Expand All @@ -200,18 +211,43 @@ def subpaths(path)
components.map { |component| components[0..components.index(component)].join("/") }
end

## multi-dir - This place we need to add directories instead of directory to get all the requirements.txt files
# def repo_contents(dir: ".", ignore_base_directory: false,
# raise_errors: true, fetch_submodules: false)
# debugger
# dir = File.join(directory, dir) unless ignore_base_directory
# path = Pathname.new(dir).cleanpath.to_path.gsub(%r{^/*}, "")

# @repo_contents ||= {}
# @repo_contents[dir] ||= if repo_contents_path
# _cloned_repo_contents(path)
# else
# _fetch_repo_contents(path, raise_errors: raise_errors,
# fetch_submodules: fetch_submodules)
# end
# end

# multi-dir - This place we need to add directories instead of directory to get all the requirements.txt files
def repo_contents(dir: ".", ignore_base_directory: false,
raise_errors: true, fetch_submodules: false)
dir = File.join(directory, dir) unless ignore_base_directory
path = Pathname.new(dir).cleanpath.to_path.gsub(%r{^/*}, "")

@repo_contents ||= {}
@repo_contents[dir] ||= if repo_contents_path
_cloned_repo_contents(path)
else
_fetch_repo_contents(path, raise_errors: raise_errors,
fetch_submodules: fetch_submodules)
end
# debugger
combined_contents = []

directories.each do |each_dir|
adjusted_dir = File.join(each_dir, dir) unless ignore_base_directory
path = Pathname.new(adjusted_dir).cleanpath.to_path.gsub(%r{^/*}, "")

@repo_contents ||= {}
@repo_contents[adjusted_dir] ||= if repo_contents_path
_cloned_repo_contents(path)
else
_fetch_repo_contents(path, raise_errors: raise_errors,
fetch_submodules: fetch_submodules)
end
combined_contents.concat(@repo_contents[adjusted_dir])
end
debugger
combined_contents
end

def cloned_commit
Expand Down Expand Up @@ -357,6 +393,7 @@ def _fetch_repo_contents_fully_specified(provider, repo, path, commit)
end

def _github_repo_contents(repo, path, commit)
# debugger
path = path.gsub(" ", "%20")
github_response = github_client.contents(repo, path: path, ref: commit)

Expand Down