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.



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

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

Instance Method Details

#head_commit_for_ref(ref) ⇒ Object



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

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



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

def ref_names
  refs_for_upload_pack.map(&:name)
end

#tagsObject



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

def tags
  return [] unless upload_pack

  @tags ||= tags_for_upload_pack
end

#upload_packObject



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

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