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
- GIT_SUBMODULE_INACCESSIBLE_ERROR =
/^fatal: unable to access '(?<url>.*)': The requested URL returned error: (?<code>\d+)$/
- GIT_SUBMODULE_CLONE_ERROR =
/^fatal: clone of '(?<url>.*)' into submodule path '.*' failed$/
- GIT_SUBMODULE_ERROR_REGEX =
/(#{GIT_SUBMODULE_INACCESSIBLE_ERROR})|(#{GIT_SUBMODULE_CLONE_ERROR})/
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#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
- #ecosystem_versions ⇒ Object
- #files ⇒ Object
-
#initialize(source:, credentials:, repo_contents_path: nil, options: {}) ⇒ Base
constructor
Creates a new FileFetcher for retrieving ‘DependencyFile`s.
- #repo ⇒ Object
- #target_branch ⇒ Object
Constructor Details
#initialize(source:, credentials:, repo_contents_path: nil, options: {}) ⇒ 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.
options supports custom feature enablement
55 56 57 58 59 60 61 |
# File 'lib/dependabot/file_fetchers/base.rb', line 55 def initialize(source:, credentials:, repo_contents_path: nil, options: {}) @source = source @credentials = credentials @repo_contents_path = repo_contents_path @linked_paths = {} @options = end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
20 21 22 |
# File 'lib/dependabot/file_fetchers/base.rb', line 20 def credentials @credentials end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/dependabot/file_fetchers/base.rb', line 20 def @options end |
#repo_contents_path ⇒ Object (readonly)
Returns the value of attribute repo_contents_path.
20 21 22 |
# File 'lib/dependabot/file_fetchers/base.rb', line 20 def repo_contents_path @repo_contents_path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
20 21 22 |
# File 'lib/dependabot/file_fetchers/base.rb', line 20 def source @source end |
Class Method Details
.required_files_in?(_filename_array) ⇒ Boolean
36 37 38 |
# File 'lib/dependabot/file_fetchers/base.rb', line 36 def self.required_files_in?(_filename_array) raise NotImplementedError end |
.required_files_message ⇒ Object
40 41 42 |
# File 'lib/dependabot/file_fetchers/base.rb', line 40 def self. raise NotImplementedError end |
Instance Method Details
#clone_repo_contents ⇒ Object
Returns the path to the cloned repo
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dependabot/file_fetchers/base.rb', line 93 def clone_repo_contents @clone_repo_contents ||= _clone_repo_contents(target_directory: repo_contents_path) rescue Dependabot::SharedHelpers::HelperSubprocessFailed => e if e..include?("fatal: Remote branch #{target_branch} not found in upstream origin") raise Dependabot::BranchNotFound, target_branch elsif e..include?("No space left on device") raise Dependabot::OutOfDisk end raise Dependabot::RepoNotFound, source end |
#commit ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dependabot/file_fetchers/base.rb', line 79 def commit return cloned_commit if cloned_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
67 68 69 |
# File 'lib/dependabot/file_fetchers/base.rb', line 67 def directory Pathname.new(source.directory || "/").cleanpath.to_path end |
#ecosystem_versions ⇒ Object
106 107 108 |
# File 'lib/dependabot/file_fetchers/base.rb', line 106 def ecosystem_versions nil end |
#files ⇒ Object
75 76 77 |
# File 'lib/dependabot/file_fetchers/base.rb', line 75 def files @files ||= fetch_files end |
#repo ⇒ Object
63 64 65 |
# File 'lib/dependabot/file_fetchers/base.rb', line 63 def repo source.repo end |
#target_branch ⇒ Object
71 72 73 |
# File 'lib/dependabot/file_fetchers/base.rb', line 71 def target_branch source.branch end |