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.
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/dependabot/file_fetchers/base.rb', line 143 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[T.untyped, T.untyped]) @submodules = T.let([], T::Array[T.untyped]) @options = @files = T.let([], T::Array[DependencyFile]) end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
68 69 70 |
# File 'lib/dependabot/file_fetchers/base.rb', line 68 def credentials @credentials end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
74 75 76 |
# File 'lib/dependabot/file_fetchers/base.rb', line 74 def @options end |
#repo_contents_path ⇒ Object (readonly)
Returns the value of attribute repo_contents_path.
71 72 73 |
# File 'lib/dependabot/file_fetchers/base.rb', line 71 def repo_contents_path @repo_contents_path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
65 66 67 |
# File 'lib/dependabot/file_fetchers/base.rb', line 65 def source @source end |
Class Method Details
.required_files_in?(filenames) ⇒ Boolean
112 113 114 |
# File 'lib/dependabot/file_fetchers/base.rb', line 112 def self.required_files_in?(filenames) filenames.any? end |
.required_files_message ⇒ Object
117 118 119 |
# File 'lib/dependabot/file_fetchers/base.rb', line 117 def self. "Required files are missing from configured directory" end |
Instance Method Details
#allow_beta_ecosystems? ⇒ Boolean
179 180 181 |
# File 'lib/dependabot/file_fetchers/base.rb', line 179 def allow_beta_ecosystems? Experiments.enabled?(:enable_beta_ecosystems) end |
#clone_repo_contents ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/dependabot/file_fetchers/base.rb', line 213 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
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/dependabot/file_fetchers/base.rb', line 198 def commit return T.must(cloned_commit) if cloned_commit return T.must(source.commit) if source.commit branch = target_branch || default_branch_for_repo @commit ||= T.let(T.unsafe(client_for_provider).fetch_commit(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
169 170 171 |
# File 'lib/dependabot/file_fetchers/base.rb', line 169 def directory Pathname.new(source.directory || "/").cleanpath.to_path end |
#ecosystem_versions ⇒ Object
229 |
# File 'lib/dependabot/file_fetchers/base.rb', line 229 def ecosystem_versions; end |
#exclude_paths=(excludes) ⇒ Object
158 159 160 |
# File 'lib/dependabot/file_fetchers/base.rb', line 158 def exclude_paths=(excludes) @exclude_paths = excludes end |
#fetch_files ⇒ Object
232 |
# File 'lib/dependabot/file_fetchers/base.rb', line 232 def fetch_files; end |
#files ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/dependabot/file_fetchers/base.rb', line 184 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
164 165 166 |
# File 'lib/dependabot/file_fetchers/base.rb', line 164 def repo source.repo end |
#target_branch ⇒ Object
174 175 176 |
# File 'lib/dependabot/file_fetchers/base.rb', line 174 def target_branch source.branch end |