/** * Sticky PR Comment — find-or-create a single root Maina comment per PR. * * Searches for `` marker in existing comments. * If found: updates the existing comment (preserves reactions). * If not found: creates a new comment. * * Race mitigation: create-then-deduplicate. After creating, re-list to check * for duplicates and delete ours if another run created one first. */ import type { Result } from "../db/index"; const MARKER = ""; export interface StickyCommentOptions { /** GitHub token (GITHUB_TOKEN or PAT) */ token: string; /** Repository owner */ owner: string; /** Repository name */ repo: string; /** Pull request number */ prNumber: number; /** Comment body (marker will be prepended if missing) */ body: string; /** GitHub API base URL (default: https://api.github.com) */ apiBase?: string; } export interface StickyCommentResult { /** The comment ID (for future updates) */ commentId: number; /** Whether this was a new comment or an update */ action: "created" | "updated"; } /** * Build the comment body with the Maina marker. */ export function buildCommentBody(content: string, runId?: string): string { const markerLine = runId ? `` : MARKER; return `${markerLine}\n${content}`; } /** * Ensure the body contains the marker. Prepends it if missing. */ function ensureMarker(body: string): string { if (body.includes("