{"modulePath":"github.com/bborbe/github-pr-watcher","version":"v0.31.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package command\n\nPackage command defines the TriggerPRReviewCommand payload and its Kafka sender for the github-pr watcher's request topic.\n\n## Constants\n\n```go\nconst DoNotMergeLabel = \"do-not-merge\"\n```\nDoNotMergeLabel is the PR label whose presence blocks the merge.\n\n```go\nconst DoNotMergeReviewBody = DoNotMergeReviewMarker + \"\\n\\n\" +\n\t\"Held by the `do-not-merge` label. Remove the label to release this PR.\"\n```\nDoNotMergeReviewBody is the body posted with the blocking review. The first line is the marker; the rest explains the hold to whoever reads the PR.\n\n```go\nconst DoNotMergeReviewDismissalMessage = \"do-not-merge label removed\"\n```\nDoNotMergeReviewDismissalMessage is recorded on the dismissal so the PR's timeline says why the block was lifted.\n\n```go\nconst DoNotMergeReviewMarker = \"\u003c!-- do-not-merge-gate --\u003e\"\n```\nDoNotMergeReviewMarker opens the body of every review this mechanism posts.\n\nIt 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.\n\n```go\nconst DoNotMergeStatusContext = \"do-not-merge\"\n```\nDoNotMergeStatusContext 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.\n\n```go\nconst SetDoNotMergeReviewCommandOperation base.CommandOperation = \"set-do-not-merge-review\"\n```\nSetDoNotMergeReviewCommandOperation is the Kafka command operation for enforcing the \\`do-not-merge\\` gate through a pull-request review. Wire string: \"set-do-not-merge-review\".\n\nIt 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.\n\nThis is the route the fleet actually uses to hold a PR. It was introduced when the reviewer App declared no Commit statuses: Write; the App holds that permission now (observed 2026-11-17), so the commit-status route (SetDoNotMergeStatusCommandOperation) posts as well. A CHANGES\\_REQUESTED review blocks the merge on every ruleset that sets required\\_approving\\_review\\_count: 1, and Pull requests: Write is already held.\n\n```go\nconst SetDoNotMergeStatusCommandOperation base.CommandOperation = \"set-do-not-merge-status\"\n```\nSetDoNotMergeStatusCommandOperation 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\".\n\nIt 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.\n\n```go\nconst SetTaskLinkStatusCommandOperation base.CommandOperation = \"set-task-link-status\"\n```\nSetTaskLinkStatusCommandOperation is the Kafka command operation for posting the \\`task-link\\` commit status on a PR head SHA. Wire string: \"set-task-link-status\".\n\nIt 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.\n\n```go\nconst TaskLinkStatusContext = \"task-link\"\n```\nTaskLinkStatusContext is the commit-status context the master-protection rulesets require by name. Renaming it silently breaks every merge in the repos that require it.\n\n```go\nconst TriggerPRReviewCommandOperation base.CommandOperation = \"trigger-pr-review\"\n```\nTriggerPRReviewCommandOperation is the Kafka command operation for triggering a single-PR review. Wire string: \"trigger-pr-review\".\n\n## Functions\n\n```go\nfunc HasTaskLinkLine(body string) bool\n```\nHasTaskLinkLine reports whether any line of body is exactly a \\`Task:\\` line followed by a lowercase task UUID.\n\nIt matches per line, never against the whole body with a multiline flag: \\[\\[:space:]] also matches a newline, so a whole-body match would let \\`Task:\\` and the UUID sit on different lines, which the line-based grep rejects.\n\n```go\nfunc NewSetDoNotMergeReviewCommandExecutor(\n\tghClient pkg.GitHubClient,\n) cdb.CommandObjectExecutorTx\n```\nNewSetDoNotMergeReviewCommandExecutor 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.\n\nIt 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.\n\nExit-path mapping:\n\n  - malformed payload / failed Validate  → cdb.ErrCommandObjectSkipped\n  - unparseable PR URL                   → cdb.ErrCommandObjectSkipped\n  - permanent GitHub error (4xx)         → cdb.ErrCommandObjectSkipped\n  - GitHub 5xx / network error           → wrapped error (transient, retried)\n  - success, or already in the wanted state → nil, nil, nil\n\nSendResultEnabled is false: the review is fire-and-forget, matching the trigger and status executors.\n\n```go\nfunc NewSetDoNotMergeStatusCommandExecutor(\n\tghClient pkg.GitHubClient,\n) cdb.CommandObjectExecutorTx\n```\nNewSetDoNotMergeStatusCommandExecutor creates a cdb.CommandObjectExecutorTx that consumes SetDoNotMergeStatusCommand messages and posts the \\`do-not-merge\\` commit status the master-protection ruleset requires.\n\nIt 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.\n\nExit-path mapping:\n\n  - malformed payload / failed Validate  → cdb.ErrCommandObjectSkipped\n  - unparseable PR URL                   → cdb.ErrCommandObjectSkipped\n  - GitHub 4xx/5xx / network error       → wrapped error (transient, retried)\n  - success                              → nil, nil, nil\n\nSendResultEnabled is false: the post is fire-and-forget, matching the trigger executor.\n\n```go\nfunc NewSetTaskLinkStatusCommandExecutor(\n\tghClient pkg.GitHubClient,\n) cdb.CommandObjectExecutorTx\n```\nNewSetTaskLinkStatusCommandExecutor creates a cdb.CommandObjectExecutorTx that consumes SetTaskLinkStatusCommand messages and posts the \\`task-link\\` commit status the master-protection rulesets require.\n\nIt 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.\n\nExit-path mapping:\n\n  - malformed payload / failed Validate  → cdb.ErrCommandObjectSkipped\n  - unparseable PR URL                   → cdb.ErrCommandObjectSkipped\n  - permanent GitHub error               → cdb.ErrCommandObjectSkipped (logged loudly)\n  - GitHub 5xx / network error           → wrapped error (transient, retried)\n  - success                              → nil, nil, nil\n\nSendResultEnabled is false: the post is fire-and-forget, matching the do-not-merge status executor.\n\n```go\nfunc NewTriggerPRReviewCommandExecutor(\n\tghClient pkg.GitHubClient,\n\tcreateSender task.CreateCommandSender,\n\ttaskCreationFilter filter.TaskCreationFilter,\n\ttrustDecision trust.Trust,\n\tmechanicalOverrideAuthors []string,\n\tstage string,\n\tmaxSlugLen int,\n\tmaxTitleLen int,\n\ttaskSuffix string,\n\ttargetVault string,\n\tmaxAdditions int,\n\tmaxChangedFiles int,\n\tmetrics pkg.Metrics,\n\tretryGuard pkg.RetryGuard,\n\toverrideLedger pkg.OverrideLedger,\n\tcoalescer coalesce.Coalescer,\n\tcurrentDateTime libtime.CurrentDateTimeGetter,\n) cdb.CommandObjectExecutorTx\n```\nNewTriggerPRReviewCommandExecutor creates a cdb.CommandObjectExecutorTx that consumes TriggerPRReviewCommand messages and drives the single-PR review pipeline: GitHub fetch → filter → trust → downstream publish.\n\nExit-path mapping (per spec 066 § Desired Behavior 5):\n\n  - invalid URL (Validate fails)            → cdb.ErrCommandObjectSkipped\n  - filter-rejected PR (filter.Skip==true)  → cdb.ErrCommandObjectSkipped\n  - untrusted author (trust.IsTrusted==false) → cdb.ErrCommandObjectSkipped\n  - GitHub 5xx / network error              → wrapped error (transient, retried)\n  - trust infrastructure error              → wrapped error (transient, retried)\n  - downstream CreateTaskCommand send error → wrapped error (transient, retried)\n  - in-flight duplicate (forced)             → cdb.ErrCommandObjectSkipped from the guard\n  - success                                  → nil, nil, nil\n\nSendResultEnabled 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.\n\n## Types\n\n```go\ntype SetDoNotMergeReviewCommand struct {\n\t// URL is the GitHub PR URL; owner/repo/number are parsed from it.\n\tURL string `json:\"url\"`\n\t// HeadSHA is the commit the review is submitted against.\n\tHeadSHA string `json:\"head_sha\"`\n\t// Labels is the PR's label set at delivery time.\n\tLabels []string `json:\"labels,omitempty\"`\n}\n```\nSetDoNotMergeReviewCommand 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.\n\nLabels 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.\n\n```go\nfunc (cmd SetDoNotMergeReviewCommand) Blocked() bool\n```\nBlocked reports whether the do-not-merge label is present.\n\n```go\nfunc (cmd SetDoNotMergeReviewCommand) Validate(ctx context.Context) error\n```\nValidate 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.\n\n```go\ntype SetDoNotMergeReviewCommandSender interface {\n\tSendCommand(ctx context.Context, cmd SetDoNotMergeReviewCommand) error\n}\n```\nSetDoNotMergeReviewCommandSender sends SetDoNotMergeReviewCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.\n\n```go\nfunc NewSetDoNotMergeReviewCommandSender(\n\tcommandCreator base.CommandCreator,\n\tinitiator cqrsiam.Initiator,\n\tcommandObjectSender cdb.CommandObjectSender,\n) SetDoNotMergeReviewCommandSender\n```\nNewSetDoNotMergeReviewCommandSender 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.\n\n```go\ntype SetDoNotMergeStatusCommand struct {\n\t// URL is the GitHub PR URL; owner/repo/number are parsed from it.\n\tURL string `json:\"url\"`\n\t// HeadSHA is the commit the status is posted against.\n\tHeadSHA string `json:\"head_sha\"`\n\t// Labels is the PR's label set at delivery time.\n\tLabels []string `json:\"labels,omitempty\"`\n}\n```\nSetDoNotMergeStatusCommand 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.\n\nLabels 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.\n\n```go\nfunc (cmd SetDoNotMergeStatusCommand) Blocked() bool\n```\nBlocked reports whether the do-not-merge label is present.\n\n```go\nfunc (cmd SetDoNotMergeStatusCommand) Validate(ctx context.Context) error\n```\nValidate 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.\n\n```go\ntype SetDoNotMergeStatusCommandSender interface {\n\tSendCommand(ctx context.Context, cmd SetDoNotMergeStatusCommand) error\n}\n```\nSetDoNotMergeStatusCommandSender sends SetDoNotMergeStatusCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.\n\n```go\nfunc NewSetDoNotMergeStatusCommandSender(\n\tcommandCreator base.CommandCreator,\n\tinitiator cqrsiam.Initiator,\n\tcommandObjectSender cdb.CommandObjectSender,\n) SetDoNotMergeStatusCommandSender\n```\nNewSetDoNotMergeStatusCommandSender 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.\n\n```go\ntype SetTaskLinkStatusCommand struct {\n\t// URL is the GitHub PR URL; owner/repo/number are parsed from it.\n\tURL string `json:\"url\"`\n\t// HeadSHA is the commit the status is posted against.\n\tHeadSHA string `json:\"head_sha\"`\n\t// Body is the PR description at delivery time. Empty is legitimate: a PR\n\t// with no description must produce a failure status.\n\tBody string `json:\"body,omitempty\"`\n}\n```\nSetTaskLinkStatusCommand is the payload for SetTaskLinkStatusCommandOperation, published by the webhook handler on every pull\\_request delivery that can change the body, and consumed by the in-pod command consumer.\n\nBody is the PR description at delivery time. The executor derives the state from it rather than re-reading the PR, for the same reason the do-not-merge command carries its label set: a second API read races a rapid edit.\n\n```go\nfunc (cmd SetTaskLinkStatusCommand) Linked() bool\n```\nLinked reports whether the PR body carries a line naming a task identifier.\n\n```go\nfunc (cmd SetTaskLinkStatusCommand) Validate(ctx context.Context) error\n```\nValidate 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.\n\nBody is deliberately not validated: an empty body is a legitimate input that must produce a failure status, so rejecting it would leave a previously green PR green after its description was cleared.\n\n```go\ntype SetTaskLinkStatusCommandSender interface {\n\tSendCommand(ctx context.Context, cmd SetTaskLinkStatusCommand) error\n}\n```\nSetTaskLinkStatusCommandSender sends SetTaskLinkStatusCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.\n\n```go\nfunc NewSetTaskLinkStatusCommandSender(\n\tcommandCreator base.CommandCreator,\n\tinitiator cqrsiam.Initiator,\n\tcommandObjectSender cdb.CommandObjectSender,\n) SetTaskLinkStatusCommandSender\n```\nNewSetTaskLinkStatusCommandSender creates a SetTaskLinkStatusCommandSender. 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.\n\n```go\ntype TriggerPRReviewCommand struct {\n\tURL string `json:\"url\"`\n\t// Force is the operator's explicit \"review this now\" request: it salts the\n\t// task identifier (bypassing controller dedupe) and bypasses the\n\t// oversized-PR park. It is NOT a webhook discriminator — the plain\n\t// /trigger endpoint also publishes Force=false.\n\tForce bool `json:\"force,omitempty\"`\n\t// Webhook marks a command the webhook handler published on a pull_request\n\t// event. Only the webhook path sets it; the operator /trigger endpoint\n\t// leaves it false, which is what keeps an explicit operator request from\n\t// being deferred to the poll path. Absent on messages published before the\n\t// field existed, so they decode as false and behave as operator requests.\n\tWebhook bool `json:\"webhook,omitempty\"`\n}\n```\nTriggerPRReviewCommand 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.\n\nURL 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).\n\n```go\nfunc (cmd TriggerPRReviewCommand) Validate(ctx context.Context) error\n```\nValidate 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.\n\n```go\ntype TriggerPRReviewCommandSender interface {\n\tSendCommand(ctx context.Context, cmd TriggerPRReviewCommand) error\n}\n```\nTriggerPRReviewCommandSender sends TriggerPRReviewCommand payloads to Kafka. Calls Validate before publishing — a validation error is returned without touching Kafka.\n\n```go\nfunc NewTriggerPRReviewCommandSender(\n\tcommandCreator base.CommandCreator,\n\tinitiator cqrsiam.Initiator,\n\tcommandObjectSender cdb.CommandObjectSender,\n) TriggerPRReviewCommandSender\n```\nNewTriggerPRReviewCommandSender 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.\n\n","path":"github.com/bborbe/github-pr-watcher/pkg/command","name":"command","synopsis":"Package command defines the TriggerPRReviewCommand payload and its Kafka sender for the github-pr watcher's request topic.","isRedistributable":true}
