Class: Dependabot::FileFetchers::Base
- Inherits:
-
Object
- Object
- Dependabot::FileFetchers::Base
- Defined in:
- lib/dependabot/file_fetchers/base.rb
Direct Known Subclasses
Constant Summary collapse
- CLIENT_NOT_FOUND_ERRORS =
[ Octokit::NotFound, Gitlab::Error::NotFound, Dependabot::Clients::Azure::NotFound, Dependabot::Clients::Bitbucket::NotFound, Dependabot::Clients::CodeCommit::NotFound ].freeze
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#repo_contents_path ⇒ Object
readonly
Returns the value of attribute repo_contents_path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
-
#clone_repo_contents ⇒ Object
Returns the path to the cloned repo.
- #commit ⇒ Object
- #directory ⇒ Object
- #files ⇒ Object
-
#initialize(source:, credentials:, repo_contents_path: nil) ⇒ Base
constructor
Creates a new FileFetcher for retrieving ‘DependencyFile`s.
- #repo ⇒ Object
- #target_branch ⇒ Object
Constructor Details
#initialize(source:, credentials:, repo_contents_path: nil) ⇒ Base
Creates a new FileFetcher for retrieving ‘DependencyFile`s.
Files are typically grabbed individually via the source’s API. repo_contents_path is an optional empty directory that will be used to clone the entire source repository on first read.
If provided, file data will be loaded from the clone. Submodules and directory listings are not currently supported by repo_contents_path and still use an API trip.
45 46 47 48 49 50 |
# File 'lib/dependabot/file_fetchers/base.rb', line 45 def initialize(source:, credentials:, repo_contents_path: nil) @source = source @credentials = credentials @repo_contents_path = repo_contents_path @linked_paths = {} end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
18 19 20 |
# File 'lib/dependabot/file_fetchers/base.rb', line 18 def credentials @credentials end |
#repo_contents_path ⇒ Object (readonly)
Returns the value of attribute repo_contents_path.
18 19 20 |
# File 'lib/dependabot/file_fetchers/base.rb', line 18 def repo_contents_path @repo_contents_path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
18 19 20 |
# File 'lib/dependabot/file_fetchers/base.rb', line 18 def source @source end |
Class Method Details
.required_files_in?(_filename_array) ⇒ Boolean
28 29 30 |
# File 'lib/dependabot/file_fetchers/base.rb', line 28 def self.required_files_in?(_filename_array) raise NotImplementedError end |
.required_files_message ⇒ Object
32 33 34 |
# File 'lib/dependabot/file_fetchers/base.rb', line 32 def self. raise NotImplementedError end |
Instance Method Details
#clone_repo_contents ⇒ Object
Returns the path to the cloned repo
81 82 83 84 85 86 |
# File 'lib/dependabot/file_fetchers/base.rb', line 81 def clone_repo_contents @clone_repo_contents ||= _clone_repo_contents(target_directory: repo_contents_path) rescue Dependabot::SharedHelpers::HelperSubprocessFailed raise Dependabot::RepoNotFound, source end |
#commit ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dependabot/file_fetchers/base.rb', line 68 def commit return source.commit if source.commit branch = target_branch || default_branch_for_repo @commit ||= client_for_provider.fetch_commit(repo, branch) rescue *CLIENT_NOT_FOUND_ERRORS raise Dependabot::BranchNotFound, branch rescue Octokit::Conflict => e raise unless e..include?("Repository is empty") end |
#directory ⇒ Object
56 57 58 |
# File 'lib/dependabot/file_fetchers/base.rb', line 56 def directory Pathname.new(source.directory || "/").cleanpath.to_path end |
#files ⇒ Object
64 65 66 |
# File 'lib/dependabot/file_fetchers/base.rb', line 64 def files @files ||= fetch_files end |
#repo ⇒ Object
52 53 54 |
# File 'lib/dependabot/file_fetchers/base.rb', line 52 def repo source.repo end |
#target_branch ⇒ Object
60 61 62 |
# File 'lib/dependabot/file_fetchers/base.rb', line 60 def target_branch source.branch end |