Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

10.5 KB
Raw Blame
/**
 * Auto-generated Zod validation schemas from the Django backend OpenAPI schema.
 * To modify these schemas, update the Django serializers or views, then run:
 *   hogli build:openapi
 * Questions or issues? #team-devex on Slack
 *
 * PostHog API - generated
 * OpenAPI spec version: 1.0.0
 */
import * as zod from 'zod'

/**
 * Create a new repo.
 */
export const VisualReviewReposCreateBody = /* @__PURE__ */ zod.object({
    repo_full_name: zod.string(),
    repo_external_id: zod.number().nullish(),
})

/**
 * Update a repo's settings.
 */
export const VisualReviewReposPartialUpdateBody = /* @__PURE__ */ zod.object({
    baseline_file_paths: zod.record(zod.string(), zod.string()).nullish(),
    enable_pr_comments: zod
        .boolean()
        .nullish()
        .describe('Post a pull request comment when a run finds visual changes to review.'),
    debt_digest_enabled: zod
        .boolean()
        .nullish()
        .describe(
            'Post the visual review debt digest to the Slack channels of the teams that own the snapshots. Off by default. The digest goes out every Monday morning.'
        ),
})

/**
 * Quarantine a snapshot identifier for a specific run type.
 */
export const visualReviewReposQuarantineCreateBodyIdentifierMax = 512

export const visualReviewReposQuarantineCreateBodyReasonMax = 255

export const visualReviewReposQuarantineCreateBodyNotifyOwnersDefault = false

export const VisualReviewReposQuarantineCreateBody = /* @__PURE__ */ zod.object({
    identifier: zod
        .string()
        .max(visualReviewReposQuarantineCreateBodyIdentifierMax)
        .describe('Snapshot identifier to quarantine.'),
    reason: zod
        .string()
        .max(visualReviewReposQuarantineCreateBodyReasonMax)
        .describe('Why this snapshot is being quarantined.'),
    expires_at: zod.iso
        .datetime({ offset: true })
        .nullish()
        .describe(
            'When the quarantine lifts itself, as an ISO 8601 datetime. Through MCP an omitted or later expiry becomes 30 days from now; anywhere else omitting it means no expiry.'
        ),
    source_run_id: zod
        .uuid()
        .nullish()
        .describe(
            "Optional pointer to the run whose failing snapshot prompted this quarantine — used to surface a 'view the failing run' link later."
        ),
    notify_owners: zod
        .boolean()
        .default(visualReviewReposQuarantineCreateBodyNotifyOwnersDefault)
        .describe(
            'Post the quarantine to the Slack channel of the team that owns the story, naming the user who quarantined it. Only Storybook snapshots have an owning team. Best effort: skipped when the story has no owning team or the project has no Slack integration.'
        ),
})

/**
 * Expire all active quarantine entries for an identifier.
 */
export const visualReviewReposQuarantineExpireCreateBodyIdentifierMax = 512

export const VisualReviewReposQuarantineExpireCreateBody = /* @__PURE__ */ zod.object({
    identifier: zod
        .string()
        .max(visualReviewReposQuarantineExpireCreateBodyIdentifierMax)
        .describe('Snapshot identifier to unquarantine'),
})

/**
 * Create a new run from a CI manifest.
 */
export const VisualReviewRunsCreateBody = /* @__PURE__ */ zod.object({
    repo_id: zod.uuid(),
    run_type: zod.string(),
    commit_sha: zod.string(),
    branch: zod.string(),
    snapshots: zod.array(
        zod.object({
            identifier: zod.string(),
            content_hash: zod.string(),
            width: zod.number().nullish(),
            height: zod.number().nullish(),
            metadata: zod.record(zod.string(), zod.unknown()).optional(),
        })
    ),
    pr_number: zod.number().nullish(),
    baseline_hashes: zod.record(zod.string(), zod.string()).optional(),
    unchanged_count: zod.number().optional(),
    removed_identifiers: zod.array(zod.string()).optional(),
    purpose: zod.string().optional(),
    metadata: zod.record(zod.string(), zod.unknown()).optional(),
    is_partial: zod.boolean().optional(),
})

/**
 * Add a batch of snapshots to a pending run (shard-based flow).
 */
export const VisualReviewRunsAddSnapshotsCreateBody = /* @__PURE__ */ zod.object({
    snapshots: zod.array(
        zod.object({
            identifier: zod.string(),
            content_hash: zod.string(),
            width: zod.number().nullish(),
            height: zod.number().nullish(),
            metadata: zod.record(zod.string(), zod.unknown()).optional(),
        })
    ),
    baseline_hashes: zod.record(zod.string(), zod.string()).optional(),
    story_index_hash: zod
        .string()
        .optional()
        .describe(
            "SHA-256 of the story-to-file map the CLI built from the Storybook index.json of this run's build. Every shard of a run sends the same value. Empty when the run sends no map."
        ),
})

/**
 * Mark snapshots reviewed (DB only).
 *
 * Records the per-snapshot "Accept change" decision. Does not commit the baseline
 * or change the GitHub gate — call finalize to ship the run. Works on a quarantined
 * snapshot too: a quarantined snapshot approved here is committed by finalize, which
 * updates a quarantined story's baseline entry without lifting the quarantine.
 */
export const VisualReviewRunsApproveCreateBody = /* @__PURE__ */ zod.object({
    snapshots: zod
        .array(
            zod.object({
                identifier: zod
                    .string()
                    .describe('The snapshot identifier to approve (e.g. Storybook story id plus theme).'),
                new_hash: zod
                    .string()
                    .describe('The content hash of the new baseline image to record for this identifier.'),
            })
        )
        .describe(
            'Snapshots to mark reviewed, each with `identifier` and `new_hash`. This only records the review in the database (the per-snapshot \"Accept change\" action) — it does not change the baseline or the GitHub gate. Commit the baseline and green the gate with the finalize endpoint.'
        ),
})

/**
 * Complete a run: detect removals, verify uploads, trigger diff processing.
 */
export const visualReviewRunsCompleteCreateBodyCheckRunIdMax = 32

export const visualReviewRunsCompleteCreateBodyCheckRunIdRegExp = new RegExp('^\\d+$')

export const VisualReviewRunsCompleteCreateBody = /* @__PURE__ */ zod.object({
    check_run_id: zod
        .string()
        .max(visualReviewRunsCompleteCreateBodyCheckRunIdMax)
        .regex(visualReviewRunsCompleteCreateBodyCheckRunIdRegExp)
        .optional()
        .describe(
            'Numeric GitHub Actions job ID of the CI job that completes the run, from `${{ job.check_run_id }}`. Recompute re-runs this job, so it re-reads the verdict without capturing the snapshots again. Omit it outside GitHub Actions.'
        ),
})

/**
 * Finalize a fully-reviewed run: commit the approved baseline and green the gate.
 *
 * Commits exactly the snapshots approved in the DB (tolerated ones keep their baseline)
 * and only succeeds once every changed/new snapshot is resolved. With approve_all=true,
 * any still-pending changed/new snapshot is approved first; quarantined snapshots are
 * skipped, but a quarantined snapshot approved by identifier is still committed.
 * With commit_to_github=false the server returns the signed baseline YAML instead of
 * committing it.
 */
export const visualReviewRunsFinalizeCreateBodyApproveAllDefault = false
export const visualReviewRunsFinalizeCreateBodyCommitToGithubDefault = true
export const visualReviewRunsFinalizeCreateBodyAddImagesToCommentOnPrDefault = false

export const VisualReviewRunsFinalizeCreateBody = /* @__PURE__ */ zod.object({
    approve_all: zod
        .boolean()
        .default(visualReviewRunsFinalizeCreateBodyApproveAllDefault)
        .describe(
            "Approve every still-pending changed and new snapshot before finalizing (tolerated snapshots are left untouched). Leave false to finalize a run you've already reviewed — finalizing fails if any changed\/new snapshot is still unreviewed."
        ),
    commit_to_github: zod
        .boolean()
        .default(visualReviewRunsFinalizeCreateBodyCommitToGithubDefault)
        .describe(
            'Whether the server commits the approved baseline to the PR branch and greens the gate (the normal path — leave true). Set false only for tooling that commits the baseline itself: the server skips the commit and returns the signed YAML in `baseline_content` instead. With false, the gate is NOT greened, `metadata.baseline_commit_sha` is absent, and no post-approval PR comment is posted.'
        ),
    add_images_to_comment_on_pr: zod
        .boolean()
        .default(visualReviewRunsFinalizeCreateBodyAddImagesToCommentOnPrDefault)
        .describe(
            "Whether to embed the before\/after snapshot images in the post-approval PR comment. The comment itself is posted when the repo has PR comments enabled and `commit_to_github` is true: it updates the run's review prompt when the run has one, and posts a new comment when it does not. This flag only controls the images. Defaults false — the comment stays a text summary unless the reviewer opts in to attach the snapshots."
        ),
})

/**
 * Lift a quarantined snapshot's quarantine once this run's pull request merges. The lift applies only after a default-branch run that contains the merge renders the expected picture, and the baseline entry holds that same picture. Requesting a lift never approves a picture: approve a changed or new snapshot by identifier first. Requesting again from the same pull request replaces the pending request.
 */
export const visualReviewRunsLiftOnMergeCreateBodyIdentifierMax = 512

export const VisualReviewRunsLiftOnMergeCreateBody = /* @__PURE__ */ zod.object({
    identifier: zod
        .string()
        .max(visualReviewRunsLiftOnMergeCreateBodyIdentifierMax)
        .describe(
            "Identifier of a quarantined snapshot in this run, such as a Storybook story ID. The snapshot's picture is what a default-branch run must render for the quarantine to lift. An unchanged snapshot uses its baseline. A changed or new snapshot must be approved first, because requesting a lift never approves a picture."
        ),
})

/**
 * Mark a changed snapshot as a known tolerated alternate.
 */
export const VisualReviewRunsTolerateCreateBody = /* @__PURE__ */ zod.object({
    snapshot_id: zod
        .uuid()
        .describe(
            'UUID of the changed snapshot to mark as a known tolerated alternate. Future runs that produce the same alternate hash for this identifier will not be flagged as changes.'
        ),
})