Class: MergePrJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/merge_pr_job.rb

Overview

Done's entry rule (§12.4 decision): dragging to the terminal column is the irreversible act — mark the PR ready, squash-merge it, delete the branch.

Instance Method Summary collapse

Instance Method Details

#perform(card_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/jobs/merge_pr_job.rb', line 6

def perform(card_id)
  card = Card.find(card_id)
  return if card.pr_url.blank? || card.pr_state == "merged"
  return unless checks_green?(card)
  return unless mergeable?(card)

  # Best-effort undraft — a QA column may already have done it, and gh
  # errors on an already-ready PR; the merge step is the real gate.
  Open3.capture2e("gh", "pr", "ready", card.pr_url)
  unless run_step(card, ["gh", "pr", "merge", card.pr_url, "--squash", "--delete-branch"])
    # The floor (card #55): a card whose merge failed must never sit in
    # Done claiming done — block it so the attention dropdown surfaces it.
    card.update!(status: "blocked")
    return
  end

  card.update!(pr_state: "merged")
  card.log!("status_change", text: "PR squash-merged and branch deleted — shipped 🎉")
end