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
Instance Method Summary collapse
- #head_commit_for_ref(ref) ⇒ Object
- #head_commit_for_ref_sha(ref) ⇒ Object
-
#initialize(url:, credentials:) ⇒ GitMetadataFetcher
constructor
A new instance of GitMetadataFetcher.
- #ref_names ⇒ Object
- #refs_for_upload_pack ⇒ Object
- #tags ⇒ Object
- #tags_for_upload_pack ⇒ 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 46 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 |
#head_commit_for_ref_sha(ref) ⇒ Object
61 62 63 64 65 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 61 def head_commit_for_ref_sha(ref) refs_for_upload_pack. find { |r| r.ref_sha == ref }&. commit_sha end |
#ref_names ⇒ Object
42 43 44 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 42 def ref_names refs_for_upload_pack.map(&:name) end |
#refs_for_upload_pack ⇒ Object
38 39 40 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 38 def refs_for_upload_pack @refs_for_upload_pack ||= parse_refs_for_upload_pack end |
#tags ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 22 def return [] unless upload_pack @tags ||= .map do |ref| OpenStruct.new( name: ref.name, tag_sha: ref.ref_sha, commit_sha: ref.commit_sha ) end end |
#tags_for_upload_pack ⇒ Object
34 35 36 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 34 def @tags_for_upload_pack ||= refs_for_upload_pack.select { |ref| ref.ref_type == :tag } 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 |