Class: Dependabot::GitMetadataFetcher

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

Constant Summary collapse

KNOWN_HOSTS =
/github\.com|bitbucket\.org|gitlab.com/i.freeze

Instance Method Summary collapse

Constructor Details

#initialize(url:, credentials:) ⇒ GitMetadataFetcher

Returns a new instance of GitMetadataFetcher.



11
12
13
14
# File 'lib/dependabot/git_metadata_fetcher.rb', line 11

def initialize(url:, credentials:)
  @url = url
  @credentials = credentials
end

Instance Method Details

#head_commit_for_ref(ref) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dependabot/git_metadata_fetcher.rb', line 32

def head_commit_for_ref(ref)
  if ref == "HEAD"
    # Remove the opening clause of the upload pack as this isn't always
    # followed by a line break. When it isn't (e.g., with Bitbucket) it
    # causes problems for our `sha_for_update_pack_line` logic
    line = upload_pack.gsub(/.*git-upload-pack/, "").
           lines.find { |l| l.include?(" HEAD") }
    return sha_for_update_pack_line(line) if line
  end

  refs_for_upload_pack.
    find { |r| r.name == ref }&.
    commit_sha
end

#ref_namesObject



28
29
30
# File 'lib/dependabot/git_metadata_fetcher.rb', line 28

def ref_names
  refs_for_upload_pack.map(&:name)
end

#tagsObject



22
23
24
25
26
# File 'lib/dependabot/git_metadata_fetcher.rb', line 22

def tags
  return [] unless upload_pack

  @tags ||= tags_for_upload_pack
end

#upload_packObject



16
17
18
19
20
# File 'lib/dependabot/git_metadata_fetcher.rb', line 16

def upload_pack
  @upload_pack ||= fetch_upload_pack_for(url)
rescue Octokit::ClientError
  raise Dependabot::GitDependenciesNotReachable, [url]
end