Class: Gem::Guardian::GitHubClient
- Inherits:
-
Object
- Object
- Gem::Guardian::GitHubClient
- Defined in:
- lib/gem/guardian/github_client.rb
Overview
Reads GitHub release and tag metadata for provenance checks.
Constant Summary collapse
- DEFAULT_HOST =
Default GitHub API endpoint used by the client.
"https://api.github.com"
Instance Method Summary collapse
-
#initialize(host: DEFAULT_HOST, http: Net::HTTP) ⇒ GitHubClient
constructor
A new instance of GitHubClient.
-
#release(repository, tag) ⇒ Object
Returns the release payload for +repository+ and +tag+.
-
#tag_verification(repository, tag) ⇒ Object
Returns the tag verification payload for +repository+ and +tag+.
Constructor Details
#initialize(host: DEFAULT_HOST, http: Net::HTTP) ⇒ GitHubClient
Returns a new instance of GitHubClient.
14 15 16 17 |
# File 'lib/gem/guardian/github_client.rb', line 14 def initialize(host: DEFAULT_HOST, http: Net::HTTP) @host = host.delete_suffix("/") @http = http end |
Instance Method Details
#release(repository, tag) ⇒ Object
Returns the release payload for +repository+ and +tag+.
20 21 22 23 24 |
# File 'lib/gem/guardian/github_client.rb', line 20 def release(repository, tag) fetch_json("/repos/#{repository}/releases/tags/#{tag}") rescue StandardError nil end |
#tag_verification(repository, tag) ⇒ Object
Returns the tag verification payload for +repository+ and +tag+. rubocop:disable Metrics/CyclomaticComplexity
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gem/guardian/github_client.rb', line 28 def tag_verification(repository, tag) ref = fetch_json("/repos/#{repository}/git/ref/tags/#{tag}") return unless ref.is_a?(Hash) object = ref["object"] return unless object.is_a?(Hash) return object["verification"] if object["type"] == "tag" && object["verification"].is_a?(Hash) commit = fetch_json("/repos/#{repository}/commits/#{object["sha"]}") commit.is_a?(Hash) ? commit["commit"]&.fetch("verification", nil) : nil rescue StandardError nil end |