Class: Ace::Demo::Molecules::DemoCommentPoster

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/demo/molecules/demo_comment_poster.rb

Instance Method Summary collapse

Constructor Details

#initialize(gh_bin: "gh") ⇒ DemoCommentPoster

Returns a new instance of DemoCommentPoster.



10
11
12
# File 'lib/ace/demo/molecules/demo_comment_poster.rb', line 10

def initialize(gh_bin: "gh")
  @gh_bin = gh_bin
end

Instance Method Details

#post(pr:, comment_body:, dry_run: false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ace/demo/molecules/demo_comment_poster.rb', line 14

def post(pr:, comment_body:, dry_run: false)
  return {dry_run: true} if dry_run

  Tempfile.create(["ace-demo-pr-comment", ".md"]) do |file|
    file.write(comment_body)
    file.flush

    _stdout, stderr, status = Open3.capture3(@gh_bin, "pr", "comment", pr.to_s, "--body-file", file.path)
    raise_auth_if_needed!(stderr)

    unless status.success?
      raise PrNotFoundError, "PR ##{pr} not found" if pr_not_found?(stderr)

      raise GhCommentError, "Failed to post comment to PR ##{pr}: #{stderr.strip}"
    end
  end

  {dry_run: false, posted: true}
end