command

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: BSD-2-Clause Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package command defines the TriggerPRReviewCommand payload and its Kafka sender for the github-pr watcher's request topic.

Index

Constants

View Source
const DoNotMergeLabel = "do-not-merge"

DoNotMergeLabel is the PR label whose presence blocks the merge.

View Source
const DoNotMergeReviewBody = DoNotMergeReviewMarker + "\n\n" +
	"Held by the `do-not-merge` label. Remove the label to release this PR."

DoNotMergeReviewBody is the body posted with the blocking review. The first line is the marker; the rest explains the hold to whoever reads the PR.

View Source
const DoNotMergeReviewDismissalMessage = "do-not-merge label removed"

DoNotMergeReviewDismissalMessage is recorded on the dismissal so the PR's timeline says why the block was lifted.

View Source
const DoNotMergeReviewMarker = "<!-- do-not-merge-gate -->"

DoNotMergeReviewMarker opens the body of every review this mechanism posts.

It is what makes the gate's reviews distinguishable from the reviewer bot's genuine verdicts on the same PR, so the label-removal path can dismiss its own review without erasing a real CHANGES_REQUESTED finding. An HTML comment renders invisibly, so the marker costs the human reader nothing.

View Source
const DoNotMergeStatusContext = "do-not-merge"

DoNotMergeStatusContext is the commit-status context the master-protection ruleset requires in every repo that used to run a `check-do-not-merge` bridge workflow. Renaming it silently removes the merge gate.

View Source
const SetDoNotMergeReviewCommandOperation base.CommandOperation = "set-do-not-merge-review"

SetDoNotMergeReviewCommandOperation is the Kafka command operation for enforcing the `do-not-merge` gate through a pull-request review. Wire string: "set-do-not-merge-review".

It rides the same GithubPRReviewV1SchemaID topic trio as the trigger and commit-status commands: the in-pod command consumer dispatches by operation, so no new schema ID and no `bborbe/maintainer` change are needed.

This is the route the fleet actually uses to hold a PR. The commit-status route (SetDoNotMergeStatusCommandOperation) cannot work: the reviewer App declares no Commit statuses: Write, and an installation cannot grant a permission the App does not declare. A CHANGES_REQUESTED review blocks the merge on every ruleset that sets required_approving_review_count: 1, and Pull requests: Write is already held.

View Source
const SetDoNotMergeStatusCommandOperation base.CommandOperation = "set-do-not-merge-status"

SetDoNotMergeStatusCommandOperation is the Kafka command operation for posting the `do-not-merge` commit status on a PR head SHA. Wire string: "set-do-not-merge-status".

It rides the existing GithubPRReviewV1SchemaID topic trio: the in-pod command consumer dispatches by operation, so no new schema ID and no `bborbe/maintainer` change are needed.

View Source
const TriggerPRReviewCommandOperation base.CommandOperation = "trigger-pr-review"

TriggerPRReviewCommandOperation is the Kafka command operation for triggering a single-PR review. Wire string: "trigger-pr-review".

Variables

This section is empty.

Functions

func NewSetDoNotMergeReviewCommandExecutor added in v0.26.0

func NewSetDoNotMergeReviewCommandExecutor(
	ghClient pkg.GitHubClient,
) cdb.CommandObjectExecutorTx

NewSetDoNotMergeReviewCommandExecutor creates a cdb.CommandObjectExecutorTx that consumes SetDoNotMergeReviewCommand messages and enforces the `do-not-merge` gate with a pull-request review: a CHANGES_REQUESTED review while the label is present, and a dismissal of that review once it is gone.

It lives in the in-pod command consumer rather than the webhook handler for the same reason the status executor does: GitHub API access stays in one place and a failed call is retried, instead of turning a GitHub blip into a delivery GitHub never resends.

Exit-path mapping:

  • malformed payload / failed Validate → cdb.ErrCommandObjectSkipped
  • unparseable PR URL → cdb.ErrCommandObjectSkipped
  • permanent GitHub error (4xx) → cdb.ErrCommandObjectSkipped
  • GitHub 5xx / network error → wrapped error (transient, retried)
  • success, or already in the wanted state → nil, nil, nil

SendResultEnabled is false: the review is fire-and-forget, matching the trigger and status executors.

func NewSetDoNotMergeStatusCommandExecutor added in v0.22.0

func NewSetDoNotMergeStatusCommandExecutor(
	ghClient pkg.GitHubClient,
) cdb.CommandObjectExecutorTx

NewSetDoNotMergeStatusCommandExecutor creates a cdb.CommandObjectExecutorTx that consumes SetDoNotMergeStatusCommand messages and posts the `do-not-merge` commit status the master-protection ruleset requires.

It lives in the in-pod command consumer rather than the webhook handler so that GitHub API access stays in one place and a failed post is retried: the handler is a receiver, and an unretried network call there would turn a GitHub blip into a delivery GitHub never resends.

Exit-path mapping:

  • malformed payload / failed Validate → cdb.ErrCommandObjectSkipped
  • unparseable PR URL → cdb.ErrCommandObjectSkipped
  • GitHub 4xx/5xx / network error → wrapped error (transient, retried)
  • success → nil, nil, nil

SendResultEnabled is false: the post is fire-and-forget, matching the trigger executor.

func NewTriggerPRReviewCommandExecutor

func NewTriggerPRReviewCommandExecutor(
	ghClient pkg.GitHubClient,
	createSender task.CreateCommandSender,
	taskCreationFilter filter.TaskCreationFilter,
	trustDecision trust.Trust,
	mechanicalOverrideAuthors []string,
	stage string,
	maxSlugLen int,
	maxTitleLen int,
	taskSuffix string,
	targetVault string,
	maxAdditions int,
	maxChangedFiles int,
	metrics pkg.Metrics,
	retryGuard pkg.RetryGuard,
	overrideLedger pkg.OverrideLedger,
	coalescer coalesce.Coalescer,
	currentDateTime libtime.CurrentDateTimeGetter,
) cdb.CommandObjectExecutorTx

NewTriggerPRReviewCommandExecutor creates a cdb.CommandObjectExecutorTx that consumes TriggerPRReviewCommand messages and drives the single-PR review pipeline: GitHub fetch → filter → trust → downstream publish.

Exit-path mapping (per spec 066 § Desired Behavior 5):

  • invalid URL (Validate fails) → cdb.ErrCommandObjectSkipped
  • filter-rejected PR (filter.Skip==true) → cdb.ErrCommandObjectSkipped
  • untrusted author (trust.IsTrusted==false) → cdb.ErrCommandObjectSkipped
  • GitHub 5xx / network error → wrapped error (transient, retried)
  • trust infrastructure error → wrapped error (transient, retried)
  • downstream CreateTaskCommand send error → wrapped error (transient, retried)
  • in-flight duplicate (forced) → cdb.ErrCommandObjectSkipped from the guard
  • success → nil, nil, nil

SendResultEnabled is false (spec Non-goal: fire-and-forget, no result topic). The github_pr_published metric is incremented from this executor (not the HTTP handler) with labels: create, skipped, kafka_error, trust_error, deferred, inflight_skipped.

Types

type SetDoNotMergeReviewCommand added in v0.26.0

type SetDoNotMergeReviewCommand struct {
	// URL is the GitHub PR URL; owner/repo/number are parsed from it.
	URL string `json:"url"`
	// HeadSHA is the commit the review is submitted against.
	HeadSHA string `json:"head_sha"`
	// Labels is the PR's label set at delivery time.
	Labels []string `json:"labels,omitempty"`
}

SetDoNotMergeReviewCommand is the payload for SetDoNotMergeReviewCommandOperation, published by the webhook handler on every pull_request delivery that can change the label state, and consumed by the in-pod command consumer.

Labels is the PR's full label set as carried by the webhook payload. The executor derives the state from it rather than re-reading the PR: a second API read races a rapid label/unlabel and would make the two-state proof flaky.

func (SetDoNotMergeReviewCommand) Blocked added in v0.26.0

func (cmd SetDoNotMergeReviewCommand) Blocked() bool

Blocked reports whether the do-not-merge label is present.

func (SetDoNotMergeReviewCommand) Validate added in v0.26.0

func (cmd SetDoNotMergeReviewCommand) Validate(ctx context.Context) error

Validate enforces the command's schema rules. URL must parse to a GitHub-platform PR URL (same rules as TriggerPRReviewCommand), and HeadSHA must be non-empty — a review submitted against an empty commit is a 422 at the API boundary, far from the cause.

type SetDoNotMergeReviewCommandSender added in v0.26.0

type SetDoNotMergeReviewCommandSender interface {
	SendCommand(ctx context.Context, cmd SetDoNotMergeReviewCommand) error
}

SetDoNotMergeReviewCommandSender sends SetDoNotMergeReviewCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.

func NewSetDoNotMergeReviewCommandSender added in v0.26.0

func NewSetDoNotMergeReviewCommandSender(
	commandCreator base.CommandCreator,
	initiator cqrsiam.Initiator,
	commandObjectSender cdb.CommandObjectSender,
) SetDoNotMergeReviewCommandSender

NewSetDoNotMergeReviewCommandSender creates a SetDoNotMergeReviewCommandSender. The commandCreator and initiator are injected at construction time per the cqrs/docs/producing-commands.md "Factory Wiring" pattern — built once at wiring, reused across every SendCommand call. The commandObjectSender wraps the Kafka sync producer.

type SetDoNotMergeStatusCommand added in v0.22.0

type SetDoNotMergeStatusCommand struct {
	// URL is the GitHub PR URL; owner/repo/number are parsed from it.
	URL string `json:"url"`
	// HeadSHA is the commit the status is posted against.
	HeadSHA string `json:"head_sha"`
	// Labels is the PR's label set at delivery time.
	Labels []string `json:"labels,omitempty"`
}

SetDoNotMergeStatusCommand is the payload for SetDoNotMergeStatusCommandOperation, published by the webhook handler on every pull_request delivery that can change the label state, and consumed by the in-pod command consumer.

Labels is the PR's full label set as carried by the webhook payload. The executor derives the state from it rather than re-reading the PR: a second API read races a rapid label/unlabel and would make the two-state proof flaky.

func (SetDoNotMergeStatusCommand) Blocked added in v0.22.0

func (cmd SetDoNotMergeStatusCommand) Blocked() bool

Blocked reports whether the do-not-merge label is present.

func (SetDoNotMergeStatusCommand) Validate added in v0.22.0

func (cmd SetDoNotMergeStatusCommand) Validate(ctx context.Context) error

Validate enforces the command's schema rules. URL must parse to a GitHub-platform PR URL (same rules as TriggerPRReviewCommand), and HeadSHA must be non-empty — a status posted against an empty ref is a 422 at the API boundary, far from the cause.

type SetDoNotMergeStatusCommandSender added in v0.22.0

type SetDoNotMergeStatusCommandSender interface {
	SendCommand(ctx context.Context, cmd SetDoNotMergeStatusCommand) error
}

SetDoNotMergeStatusCommandSender sends SetDoNotMergeStatusCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.

func NewSetDoNotMergeStatusCommandSender added in v0.22.0

func NewSetDoNotMergeStatusCommandSender(
	commandCreator base.CommandCreator,
	initiator cqrsiam.Initiator,
	commandObjectSender cdb.CommandObjectSender,
) SetDoNotMergeStatusCommandSender

NewSetDoNotMergeStatusCommandSender creates a SetDoNotMergeStatusCommandSender. The commandCreator and initiator are injected at construction time per the cqrs/docs/producing-commands.md "Factory Wiring" pattern — built once at wiring, reused across every SendCommand call. The commandObjectSender wraps the Kafka sync producer.

type TriggerPRReviewCommand

type TriggerPRReviewCommand struct {
	URL string `json:"url"`
	// Force is the operator's explicit "review this now" request: it salts the
	// task identifier (bypassing controller dedupe) and bypasses the
	// oversized-PR park. It is NOT a webhook discriminator — the plain
	// /trigger endpoint also publishes Force=false.
	Force bool `json:"force,omitempty"`
	// Webhook marks a command the webhook handler published on a pull_request
	// event. Only the webhook path sets it; the operator /trigger endpoint
	// leaves it false, which is what keeps an explicit operator request from
	// being deferred to the poll path. Absent on messages published before the
	// field existed, so they decode as false and behave as operator requests.
	Webhook bool `json:"webhook,omitempty"`
}

TriggerPRReviewCommand is the payload for TriggerPRReviewCommandOperation. It is published to the github-pr watcher's request topic by the /trigger HTTP handler and consumed by the in-pod command consumer.

URL is the GitHub PR URL the operator wants reviewed. Force, when true, causes the executor to derive a salted TaskIdentifier via pkg.DeriveTaskIDForce (microsecond-resolution time nonce) so the agent controller's vault-file dedup skip does NOT fire and a fresh review task is created for the same head SHA (spec 069).

func (TriggerPRReviewCommand) Validate

func (cmd TriggerPRReviewCommand) Validate(ctx context.Context) error

Validate enforces the command's schema rules. URL must be non-empty and must parse to a GitHub-platform PR URL (same rules as the HTTP handler's parseAndValidateURL — see pkg/handler/trigger_handler.go). Non-GitHub platforms and unparseable URLs are rejected here so a buggy client that bypasses the HTTP layer cannot enqueue garbage.

type TriggerPRReviewCommandSender

type TriggerPRReviewCommandSender interface {
	SendCommand(ctx context.Context, cmd TriggerPRReviewCommand) error
}

TriggerPRReviewCommandSender sends TriggerPRReviewCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.

func NewTriggerPRReviewCommandSender

func NewTriggerPRReviewCommandSender(
	commandCreator base.CommandCreator,
	initiator cqrsiam.Initiator,
	commandObjectSender cdb.CommandObjectSender,
) TriggerPRReviewCommandSender

NewTriggerPRReviewCommandSender creates a TriggerPRReviewCommandSender. The commandCreator and initiator are injected at construction time per the cqrs/docs/producing-commands.md "Factory Wiring" pattern (matches trading/frontend/command's reference impl) — built once at wiring, reused across every SendCommand call. The commandObjectSender wraps the Kafka sync producer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL