Class: Ace::Review::Molecules::GhPrFetcher
- Inherits:
-
Object
- Object
- Ace::Review::Molecules::GhPrFetcher
- Defined in:
- lib/ace/review/molecules/gh_pr_fetcher.rb
Overview
Fetch PR diff and metadata via gh CLI
Class Method Summary collapse
-
.fetch_diff(pr_identifier, options = {}) ⇒ Hash
Fetch PR diff content.
-
.fetch_metadata(pr_identifier, options = {}) ⇒ Hash
Fetch PR metadata (state, draft status, title, etc.).
-
.fetch_pr(pr_identifier, options = {}) ⇒ Hash
Fetch both diff and metadata in one call.
Class Method Details
.fetch_diff(pr_identifier, options = {}) ⇒ Hash
Fetch PR diff content
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ace/review/molecules/gh_pr_fetcher.rb', line 19 def self.fetch_diff(pr_identifier, = {}) # Parse identifier to get gh CLI format using ace-git parsed = Ace::Git::Atoms::PrIdentifierParser.parse(pr_identifier) gh_format = parsed.gh_format # Default timeout for PR diff operations timeout = [:timeout] || 30 # Fetch diff with retry logic result = Ace::Review::Atoms::RetryWithBackoff.execute() do Ace::Git::Molecules::GhCliExecutor.execute("pr", ["diff", gh_format], timeout: timeout) end if result[:success] { success: true, diff: result[:stdout], identifier: gh_format, parsed: parsed.to_h } else handle_fetch_error(result, pr_identifier) end rescue Ace::Review::Errors::DiffTooLargeError # Fall back to local git diff when GitHub API rejects large diffs fetch_local_diff_fallback(pr_identifier, ) rescue Ace::Review::Errors::GhCliNotInstalledError, Ace::Review::Errors::GhAuthenticationError, Ace::Git::GhNotInstalledError, Ace::Git::GhAuthenticationError # Re-raise authentication and installation errors raise rescue => e { success: false, error: "Failed to fetch PR diff: #{e.}" } end |
.fetch_metadata(pr_identifier, options = {}) ⇒ Hash
Fetch PR metadata (state, draft status, title, etc.)
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ace/review/molecules/gh_pr_fetcher.rb', line 62 def self.(pr_identifier, = {}) # Parse identifier using ace-git parsed = Ace::Git::Atoms::PrIdentifierParser.parse(pr_identifier) gh_format = parsed.gh_format # Default timeout for PR operations timeout = [:timeout] || 30 # Fetch metadata as JSON fields = "number,state,isDraft,title,body,author,headRefName,baseRefName,url" result = Ace::Review::Atoms::RetryWithBackoff.execute() do Ace::Git::Molecules::GhCliExecutor.execute("pr", ["view", gh_format, "--json", fields], timeout: timeout) end if result[:success] = JSON.parse(result[:stdout]) { success: true, metadata: , identifier: gh_format, parsed: parsed.to_h } else handle_fetch_error(result, pr_identifier) end rescue JSON::ParserError => e { success: false, error: "Failed to parse PR metadata: #{e.}" } rescue Ace::Review::Errors::GhCliNotInstalledError, Ace::Review::Errors::GhAuthenticationError, Ace::Git::GhNotInstalledError, Ace::Git::GhAuthenticationError raise rescue => e { success: false, error: "Failed to fetch PR metadata: #{e.}" } end |
.fetch_pr(pr_identifier, options = {}) ⇒ Hash
Fetch both diff and metadata in one call
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ace/review/molecules/gh_pr_fetcher.rb', line 108 def self.fetch_pr(pr_identifier, = {}) # Fetch diff and metadata diff_result = fetch_diff(pr_identifier, ) return diff_result unless diff_result[:success] = (pr_identifier, ) return unless [:success] { success: true, diff: diff_result[:diff], metadata: [:metadata], identifier: diff_result[:identifier], parsed: diff_result[:parsed] } end |