Class: Dependabot::GitMetadataFetcher
- Inherits:
-
Object
- Object
- Dependabot::GitMetadataFetcher
- 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
- #head_commit_for_ref(ref) ⇒ Object
-
#initialize(url:, credentials:) ⇒ GitMetadataFetcher
constructor
A new instance of GitMetadataFetcher.
- #ref_names ⇒ Object
- #tags ⇒ Object
- #upload_pack ⇒ Object
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_names ⇒ Object
28 29 30 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 28 def ref_names refs_for_upload_pack.map(&:name) end |
#tags ⇒ Object
22 23 24 25 26 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 22 def return [] unless upload_pack @tags ||= end |
#upload_pack ⇒ Object
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 |