Documentation
¶
Overview ¶
Package command defines the TriggerPRReviewCommand payload and its Kafka sender for the github-pr watcher's request topic.
Index ¶
- Constants
- func NewSetDoNotMergeStatusCommandExecutor(ghClient pkg.GitHubClient) cdb.CommandObjectExecutorTx
- func NewTriggerPRReviewCommandExecutor(ghClient pkg.GitHubClient, createSender task.CreateCommandSender, ...) cdb.CommandObjectExecutorTx
- type SetDoNotMergeStatusCommand
- type SetDoNotMergeStatusCommandSender
- type TriggerPRReviewCommand
- type TriggerPRReviewCommandSender
Constants ¶
const DoNotMergeLabel = "do-not-merge"
DoNotMergeLabel is the PR label whose presence blocks the merge.
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.
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.
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 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 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.