Skip to main content
A forge is a code host such as GitHub. This helper ships a reviewed change through a forge. It pushes the work branch, opens or updates one pull request, proves that the change can merge, squashes the work into the base branch, and deletes the work branch. Call this helper after a review gate passes. A host supplies the five operations, in the same way it supplies memory. The helper is host-side code: it imports no runtime package.

The five operations

  1. Push the branch. pushBranch points the work branch at the head revision. A second call with the same head does nothing.
  2. Open one pull request. openOrUpdatePullRequest opens one pull request for the branch, or updates the open one. The body is a synthesis of the commit bodies.
  3. Read the status. readPullRequestStatus reads the merge state, the head revision, and the check runs.
  4. Squash the merge. squashMerge squashes the pull request into the base branch. The message is the same synthesis, so the reasoning that produced the change is the reasoning that ships it.
  5. Delete the branch. deleteBranch deletes the work branch after the merge.

The gate

The gate is a pure function over one status. The change ships only when the expected workflow ran and passed on the exact head revision, and the branch can merge. Every other case prints RESULT: FAIL with the reason on the line. A check run counts as passed only when its conclusion is exactly success. Green checks on other workflows do not ship a change. Green checks from an earlier revision do not ship a change either.

Contract

Source

Copy examples/packages/forge-helper.ts from the repository. The example imports no package. It runs offline.

Run the example

From an Obversa checkout, run:
The result is:
The report has three parts. verdicts holds the verdict for each fixture pull request. ship holds the shipped change: the pull request number, the proof that two calls opened one pull request, the merge, the branch deletion, the synthesis message, and the operation log. ghArguments holds the argument list for each operation. After you copy the source into a project that has tsx installed, pnpm exec tsx forge-helper.ts runs the same example.

Failure behavior

The four fixture pull requests print four fail verdicts:
  • RESULT: FAIL because the branch cannot merge
  • RESULT: FAIL because the checks are from an earlier revision
  • RESULT: FAIL because the expected workflow never ran on the head revision
  • RESULT: FAIL because the tests check finished as failure
The demo ships only on the exact string RESULT: PASS. The gate stops the ship when the verdict says anything else. The helper writes no files and makes no network calls. Run it again from the start at any time.

The GitHub adapter

The adapter returns one argument list for each operation. Each list is a pure function of its input. A new branch and an open pull request use the extra lists in the source. The execution layer is one function with no logic of its own. It runs gh with the printed list and returns the output. It needs a gh login, and nothing in this file runs it. To use the helper in a process, give the five operations to your host and call them after your review gate passes. The mock host in the source shows each operation, and the gate stays the same for every host.