Class: Dependabot::FileFetchers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/file_fetchers/base.rb

Constant Summary collapse

CLIENT_NOT_FOUND_ERRORS =
[
  Octokit::NotFound,
  Gitlab::Error::NotFound,
  Dependabot::Clients::Azure::NotFound,
  Dependabot::Clients::Bitbucket::NotFound
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, credentials:) ⇒ Base

Returns a new instance of Base.



33
34
35
36
37
38
# File 'lib/dependabot/file_fetchers/base.rb', line 33

def initialize(source:, credentials:)
  @source = source
  @credentials = credentials

  @linked_paths = {}
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



16
17
18
# File 'lib/dependabot/file_fetchers/base.rb', line 16

def credentials
  @credentials
end

#sourceObject (readonly)

Returns the value of attribute source.



16
17
18
# File 'lib/dependabot/file_fetchers/base.rb', line 16

def source
  @source
end

Class Method Details

.required_files_in?(_filename_array) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/dependabot/file_fetchers/base.rb', line 25

def self.required_files_in?(_filename_array)
  raise NotImplementedError
end

.required_files_messageObject

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/dependabot/file_fetchers/base.rb', line 29

def self.required_files_message
  raise NotImplementedError
end

Instance Method Details

#commitObject



56
57
58
59
60
61
62
63
64
# File 'lib/dependabot/file_fetchers/base.rb', line 56

def 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.message.include?("Repository is empty")
end

#directoryObject



44
45
46
# File 'lib/dependabot/file_fetchers/base.rb', line 44

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

#filesObject



52
53
54
# File 'lib/dependabot/file_fetchers/base.rb', line 52

def files
  @files ||= fetch_files
end

#repoObject



40
41
42
# File 'lib/dependabot/file_fetchers/base.rb', line 40

def repo
  source.repo
end

#target_branchObject



48
49
50
# File 'lib/dependabot/file_fetchers/base.rb', line 48

def target_branch
  source.branch
end