Class: Ace::Git::Worktree::Molecules::PullRequestCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git/worktree/molecules/pull_request_creator.rb

Overview

Creates draft pull requests for task worktrees through the forge-neutral provider contract.

The caller must supply the exact pushed head SHA (expected_head); creation or reuse is proven against that SHA by the provider, never inferred from branch names. Server selection resolves lazily inside the lifecycle organism, so local-only task runs never touch a forge.

Instance Method Summary collapse

Constructor Details

#initialize(server_name: nil, use_default: false, remote_name: nil, timeout: nil, runner: nil) ⇒ PullRequestCreator

Returns a new instance of PullRequestCreator.

Parameters:

  • server_name (String, nil) (defaults to: nil) —

    explicit server selection

  • use_default (Boolean) (defaults to: false) —

    resolve the configured default server

  • remote_name (String, nil) (defaults to: nil) —

    remote used for fallback resolution

  • timeout (Integer, nil) (defaults to: nil) —

    provider timeout

  • runner (Proc, nil) (defaults to: nil) —

    injectable provider runner (tests)



22
23
24
25
26
27
28
# File 'lib/ace/git/worktree/molecules/pull_request_creator.rb', line 22

def initialize(server_name: nil, use_default: false, remote_name: nil, timeout: nil, runner: nil)
  @selection = {
    server_name: server_name, use_default: use_default, remote_name: remote_name
  }
  @timeout = timeout
  @runner = runner
end

Instance Method Details

#create_draft(branch:, base:, title:, expected_head:, head_repository_url: nil, body: nil) ⇒ Hash

Create (or reconcile to) a draft PR for a pushed branch.

Parameters:

  • branch (String) —

    pushed head branch

  • base (String) —

    base branch/ref

  • title (String) —

    PR title

  • expected_head (String) —

    exact SHA the pushed branch resolves to

  • head_repository_url (String, nil) (defaults to: nil) —

    source repository URL (defaults to the selected server's repository)

  • body (String, nil) (defaults to: nil) —

    PR body text

Returns:

  • (Hash) —

    pr_number:, pr_url:, existing:, head_sha:, error:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ace/git/worktree/molecules/pull_request_creator.rb', line 40

def create_draft(branch:, base:, title:, expected_head:, head_repository_url: nil, body: nil)
  lifecycle = Ace::Git::Organisms::PullRequestLifecycle.new(**@selection.merge(timeout: @timeout, runner: @runner))
  receipt = lifecycle.create(
    head_ref: branch,
    head_repository_url: head_repository_url,
    base_ref: base,
    expected_head: expected_head,
    title: title,
    body: body,
    draft: true
  )
  pr = receipt.pull_request
  {
    success: true,
    pr_number: pr.number,
    pr_url: pr.url,
    existing: receipt.idempotency == :existing,
    head_sha: pr.head_sha,
    error: nil
  }
rescue Ace::Git::Error => e
  {success: false, pr_number: nil, pr_url: nil, existing: false, head_sha: nil, error: e.message}
end