Class: Ace::Review::Molecules::GhCommentPoster

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/molecules/gh_comment_poster.rb

Overview

Post review comments to GitHub PR

Class Method Summary collapse

Class Method Details

.post_comment(pr_identifier, review_text, options = {}) ⇒ Hash

Post a review comment to a PR

Parameters:

  • pr_identifier (String)

    PR identifier

  • review_text (String)

    Review content

  • options (Hash) (defaults to: {})

    Posting options

Options Hash (options):

  • :dry_run (Boolean)

    Don’t actually post (default: false)

  • :metadata (Hash)

    Review metadata (preset, model, timestamp)

Returns:

  • (Hash)

    Result with :success, :comment_url, :preview, :error



18
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
55
56
57
58
59
60
61
62
63
64
# File 'lib/ace/review/molecules/gh_comment_poster.rb', line 18

def self.post_comment(pr_identifier, review_text, options = {})
  # Parse identifier using ace-git
  parsed = Ace::Git::Atoms::PrIdentifierParser.parse(pr_identifier)
  gh_format = parsed.gh_format

  # Check PR state before posting
  state_check = check_pr_state(gh_format)
  return state_check unless state_check[:success]

  # Format comment with metadata
  formatted_comment = format_review_comment(review_text, options[:metadata] || {})

  # Handle dry run
  if options[:dry_run]
    return {
      success: true,
      dry_run: true,
      preview: formatted_comment,
      pr_identifier: gh_format
    }
  end

  # Post comment via gh CLI
  result = post_via_gh(gh_format, formatted_comment)

  if result[:success]
    comment_url = extract_comment_url(result[:stdout], parsed.to_h)
    {
      success: true,
      comment_url: comment_url,
      pr_identifier: gh_format
    }
  else
    {
      success: false,
      error: "Failed to post comment: #{result[:stderr]}"
    }
  end
rescue Ace::Review::Errors::GhCliNotInstalledError, Ace::Review::Errors::GhAuthenticationError,
  Ace::Git::GhNotInstalledError, Ace::Git::GhAuthenticationError
  raise
rescue => e
  {
    success: false,
    error: "Failed to post comment: #{e.message}"
  }
end