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.
12 13 14 15 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 12 def initialize(url:, credentials:) @url = url @credentials = credentials end |
Instance Method Details
#head_commit_for_ref(ref) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 47 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. The format # of this opening clause is documented at # https://git-scm.com/docs/http-protocol#_smart_server_response line = upload_pack.gsub(/^[0-9a-f]{4}# service=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
64 65 66 67 68 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 64 def head_commit_for_ref_sha(ref) refs_for_upload_pack .find { |r| r.ref_sha == ref } &.commit_sha end |
#ref_names ⇒ Object
43 44 45 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 43 def ref_names refs_for_upload_pack.map(&:name) end |
#refs_for_upload_pack ⇒ Object
39 40 41 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 39 def refs_for_upload_pack @refs_for_upload_pack ||= parse_refs_for_upload_pack end |
#tags ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 23 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
35 36 37 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 35 def @tags_for_upload_pack ||= refs_for_upload_pack.select { |ref| ref.ref_type == :tag } end |
#upload_pack ⇒ Object
17 18 19 20 21 |
# File 'lib/dependabot/git_metadata_fetcher.rb', line 17 def upload_pack @upload_pack ||= fetch_upload_pack_for(url) rescue Octokit::ClientError raise Dependabot::GitDependenciesNotReachable, [url] end |