Class: Dependabot::FileFetchers::Base
- Inherits:
-
Object
- Object
- Dependabot::FileFetchers::Base
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/dependabot/file_fetchers/base.rb
Direct Known Subclasses
Constant Summary collapse
- CLIENT_NOT_FOUND_ERRORS =
T.let( [ Octokit::NotFound, Gitlab::Error::NotFound, Dependabot::Clients::Azure::NotFound, Dependabot::Clients::Bitbucket::NotFound, Dependabot::Clients::CodeCommit::NotFound ].freeze, T::Array[T.class_of(StandardError)] )
- 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})/- GIT_RETRYABLE_ERRORS =
T.let( [ /remote error: Internal Server Error/, /fatal: Couldn\'t find remote ref/, %r{git fetch_pack: expected ACK/NAK, got}, /protocol error: bad pack header/, /The remote end hung up unexpectedly/, /TLS packet with unexpected length was received/, /RPC failed; result=\d+, HTTP code = \d+/, /Connection timed out/, /Connection reset by peer/, /Unable to look up/, /Couldn\'t resolve host/, /The requested URL returned error: (429|5\d{2})/ ].freeze, T::Array[Regexp] )
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
- #allow_beta_ecosystems? ⇒ Boolean
- #clone_repo_contents ⇒ Object
- #commit ⇒ Object
- #directory ⇒ Object
- #ecosystem_versions ⇒ Object
- #exclude_paths=(excludes) ⇒ Object
- #fetch_files ⇒ Object
- #files ⇒ Object
-
#initialize(source:, credentials:, repo_contents_path: nil, options: {}, update_config: nil) ⇒ Base
constructor
A new instance of Base.
- #repo ⇒ Object
- #target_branch ⇒ Object
Constructor Details
#initialize(source:, credentials:, repo_contents_path: nil, options: {}, update_config: nil) ⇒ Base
Returns a new instance of Base.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/dependabot/file_fetchers/base.rb', line 129 def initialize(source:, credentials:, repo_contents_path: nil, options: {}, update_config: nil) @source = source @credentials = credentials @repo_contents_path = repo_contents_path @update_config = T.let(update_config, T.nilable(Dependabot::Config::UpdateConfig)) @exclude_paths = T.let(update_config&.exclude_paths || [], T::Array[String]) @linked_paths = T.let({}, T::Hash[String, LinkedPath]) @submodules = T.let([], T::Array[String]) @repo_contents = T.let(nil, T.nilable(T::Hash[String, T::Array[RepositoryContent]])) @options = @files = T.let([], T::Array[DependencyFile]) end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
54 55 56 |
# File 'lib/dependabot/file_fetchers/base.rb', line 54 def credentials @credentials end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
60 61 62 |
# File 'lib/dependabot/file_fetchers/base.rb', line 60 def @options end |
#repo_contents_path ⇒ Object (readonly)
Returns the value of attribute repo_contents_path.
57 58 59 |
# File 'lib/dependabot/file_fetchers/base.rb', line 57 def repo_contents_path @repo_contents_path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
51 52 53 |
# File 'lib/dependabot/file_fetchers/base.rb', line 51 def source @source end |
Class Method Details
.required_files_in?(filenames) ⇒ Boolean
98 99 100 |
# File 'lib/dependabot/file_fetchers/base.rb', line 98 def self.required_files_in?(filenames) filenames.any? end |
.required_files_message ⇒ Object
103 104 105 |
# File 'lib/dependabot/file_fetchers/base.rb', line 103 def self. "Required files are missing from configured directory" end |
Instance Method Details
#allow_beta_ecosystems? ⇒ Boolean
166 167 168 |
# File 'lib/dependabot/file_fetchers/base.rb', line 166 def allow_beta_ecosystems? Experiments.enabled?(:enable_beta_ecosystems) end |
#clone_repo_contents ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/dependabot/file_fetchers/base.rb', line 201 def clone_repo_contents @clone_repo_contents ||= T.let( _clone_repo_contents(target_directory: repo_contents_path), T.nilable(String) ) 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.new(source, e.) end |
#commit ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/dependabot/file_fetchers/base.rb', line 185 def commit resolved_cloned_commit = cloned_commit return resolved_cloned_commit if resolved_cloned_commit return T.must(source.commit) if source.commit branch = target_branch || default_branch_for_repo @commit ||= T.let(fetch_commit_for_provider(repo, branch), T.nilable(String)) rescue *CLIENT_NOT_FOUND_ERRORS raise Dependabot::BranchNotFound, branch rescue Octokit::Conflict => e raise unless e..include?("Repository is empty") end |
#directory ⇒ Object
156 157 158 |
# File 'lib/dependabot/file_fetchers/base.rb', line 156 def directory Pathname.new(source.directory || "/").cleanpath.to_path end |
#ecosystem_versions ⇒ Object
217 |
# File 'lib/dependabot/file_fetchers/base.rb', line 217 def ecosystem_versions; end |
#exclude_paths=(excludes) ⇒ Object
145 146 147 |
# File 'lib/dependabot/file_fetchers/base.rb', line 145 def exclude_paths=(excludes) @exclude_paths = excludes end |
#fetch_files ⇒ Object
220 |
# File 'lib/dependabot/file_fetchers/base.rb', line 220 def fetch_files; end |
#files ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/dependabot/file_fetchers/base.rb', line 171 def files return @files if @files.any? files = fetch_files.compact raise Dependabot::DependencyFileNotFound.new(nil, "No files found in #{directory}") unless files.any? unless self.class.required_files_in?(files.map(&:name)) raise DependencyFileNotFound.new(nil, self.class.) end @files = files end |
#repo ⇒ Object
151 152 153 |
# File 'lib/dependabot/file_fetchers/base.rb', line 151 def repo source.repo end |
#target_branch ⇒ Object
161 162 163 |
# File 'lib/dependabot/file_fetchers/base.rb', line 161 def target_branch source.branch end |