import type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; import type { Comment } from "../schema.js"; type Review = RestEndpointMethodTypes["pulls"]["listReviews"]["response"]["data"][number]; /** * Configuration options for CodeRabbit review parsing and filtering. * * These options control which types of CodeRabbit suggestions are included * and how they are processed and prioritized. */ export interface CodeRabbitOptions { /** Include nitpick suggestions (minor style/formatting issues) */ include_nits?: boolean; /** Include duplicate code detection suggestions */ include_duplicates?: boolean; /** Include additional suggestions (enhancements, improvements) */ include_additional?: boolean; /** Specific suggestion types to include (filters others out) */ suggestion_types?: string[]; /** Sort actionable items first when prioritizing */ prioritize_actionable?: boolean; /** Group comments by suggestion type in output */ group_by_type?: boolean; /** Generate AI agent prompts from suggestions */ extract_agent_prompts?: boolean; } /** * Process a CodeRabbit review with authorship checking and pre-filtering. * * This is the main entry point for CodeRabbit review processing. It handles: * 1. Authorship checking (only processes CodeRabbit AI reviews) * 2. Pre-filtering (filters out internal state/main review commits) * 3. Delegates to parsing if both checks pass * * @param body - The review body text * @param review - The GitHub review object * @param pr - Pull request information * @param pr.owner - Repository owner * @param pr.repo - Repository name * @param pr.number - Pull request number * @param author - The review author login * @param authorAssociation - The author's association with the repo * @param isBot - Whether the author is a bot * @param options - CodeRabbit-specific options * @param includeStatusIndicators - Whether to include status indicators * @returns Array of parsed actionable comments */ export declare function processCodeRabbitReview(body: string, review: Review, pr: { owner: string; repo: string; number: number; }, author: string, authorAssociation: string, isBot: boolean, options?: CodeRabbitOptions, includeStatusIndicators?: boolean): Comment[]; /** * Process a CodeRabbit issue comment with authorship checking and pre-filtering. * * This is the main entry point for CodeRabbit issue comment processing. It handles: * 1. Authorship checking (only processes CodeRabbit AI comments) * 2. Pre-filtering (filters out rate limit messages and internal state) * 3. Delegates to parsing if both checks pass * * @param body - The issue comment body text * @param issueComment - The GitHub issue comment object * @param pr - Pull request information * @param author - The comment author login * @param authorAssociation - The author's association with the repo * @param isBot - Whether the author is a bot * @param options - CodeRabbit-specific options * @param includeStatusIndicators - Whether to include status indicators * @returns Array of parsed actionable comments */ type IssueCommentShape = { id: number; created_at: string; updated_at: string; html_url: string; }; export declare function processCodeRabbitIssueComment(body: string, issueComment: IssueCommentShape, pr: { owner: string; repo: string; number: number; }, author: string, authorAssociation: string, isBot: boolean, options?: CodeRabbitOptions, includeStatusIndicators?: boolean): Comment[]; /** * Parse CodeRabbit structured sections from review body. * * This function handles the complex task of parsing CodeRabbit's HTML-based * review format into structured data. CodeRabbit uses collapsible HTML sections * with specific patterns that need careful parsing. * * ## Section Types and Patterns * * CodeRabbit reviews contain these section types: * - ๐Ÿงน Nitpicks: Minor style/formatting issues (low severity) * - โ™ป๏ธ Duplicate code: Code duplication suggestions (medium severity) * - ๐Ÿ“œ Additional suggestions: Enhancement recommendations (medium severity) * - Actionable items: Must-fix issues (high severity, no emoji) * * ## HTML Structure Parsed * * Each section follows this pattern: * ```html *
* ๐Ÿงน Nitpicks (3) * *
* ``` * * Within sections, individual suggestions follow: * ```html * `file.ts` (2) * `42: **Issue description**` * ```diff * - old code * + new code * ``` * ``` * * ## Parsing Strategy * * The function uses a state machine approach: * 1. **Section Detection**: Look for `
` patterns with emojis * 2. **File Context**: Track current file from nested summaries * 3. **Item Parsing**: Extract line ranges and descriptions * 4. **Code Block Parsing**: Handle diff blocks with special escaping * 5. **State Management**: Track parsing state across lines * * ## Edge Cases Handled * * - Escaped backticks in diff blocks (`\`\`\`diff`) * - Multi-line descriptions spanning multiple lines * - Missing or malformed line ranges * - Nested HTML structures * - Actionable items without emoji indicators * * @param body - Raw HTML review body from CodeRabbit * @returns Array of parsed sections with items and metadata */ export declare function parseCodeRabbitSections(body: string): Array<{ type: "nit" | "duplicate" | "additional" | "actionable"; title: string; count: number; content: string; items: Array<{ file_path: string; line_range: string; title: string; description: string; code_suggestion?: { old_code: string; new_code: string; language?: string; }; severity: "low" | "medium" | "high"; }>; }>; /** * Create a CodeRabbit comment with enhanced metadata and validation. * * This function converts a parsed CodeRabbit suggestion item into a standardized * Comment object with comprehensive metadata for downstream processing. * * ## Key Processing Steps * * 1. **Line Range Validation**: Safely parse and validate line numbers * 2. **ID Generation**: Create unique synthetic ID for tracking * 3. **Metadata Enhancement**: Add CodeRabbit-specific metadata * 4. **Action Commands**: Generate CLI/MCP commands for resolution * 5. **Status Indicators**: Calculate priority and resolution status * * ## Line Range Parsing * * Handles various line range formats: * - Single line: "42" โ†’ start=42, end=42 * - Range: "42-45" โ†’ start=42, end=45 * - Invalid: "abc" โ†’ start=undefined, end=undefined * * ## CodeRabbit Metadata * * Each comment includes rich metadata: * - `suggestion_type`: nit, duplicate, additional, actionable * - `severity`: low, medium, high (inferred from type) * - `category`: security, performance, style, bug, general * - `file_context`: path and line information * - `code_suggestion`: parsed diff if available * - `agent_prompt`: AI-friendly prompt for resolution * - `implementation_guidance`: priority and effort estimates * * @param item - Parsed suggestion item from section parsing * @param suggestionType - Type of suggestion (nit, duplicate, etc.) * @param review - Original GitHub review object * @param pr - Pull request information * @param author - Review author username * @param authorAssociation - GitHub author association * @param isBot - Whether author is a bot * @param options - CodeRabbit parsing options * @param includeStatusIndicators - Whether to calculate status indicators * @returns Standardized Comment object with CodeRabbit metadata */ /** * Create a standardized Comment object from CodeRabbit suggestion item * @param item - Parsed CodeRabbit suggestion item * @param suggestionType - Type of suggestion (nit, duplicate, etc.) * @param review - GitHub review object * @param pr - Pull request information * @param pr.owner - Repository owner * @param pr.repo - Repository name * @param pr.number - Pull request number * @param author - Review author * @param authorAssociation - GitHub author association * @param isBot - Whether author is a bot * @param options - Optional CodeRabbit parsing options * @param includeStatusIndicators - Whether to include status indicators * @returns Standardized Comment object with CodeRabbit metadata */ export declare function createCodeRabbitComment(item: any, suggestionType: string, review: any, pr: { owner: string; repo: string; number: number; }, author: string, authorAssociation: string, isBot: boolean, options?: any, includeStatusIndicators?: boolean): Comment; /** * Pre-filter function to check if a CodeRabbit review body should be filtered out entirely. * This checks for main review commits with internal state before parsing into individual suggestions. * * @param reviewBody - The review body text to check * @returns true if this review body should be filtered out entirely */ export declare function shouldFilterCodeRabbitReviewBody(reviewBody: string): boolean; /** * Check if the author is CodeRabbit AI. * @param author - The author login name * @returns true if the author is CodeRabbit AI */ export declare function isCodeRabbitAuthor(author: string): boolean; /** * Apply CodeRabbit-specific filtering and sorting to comments. * * This function implements the final processing pipeline for CodeRabbit * comments, applying user-specified filtering and sorting options. * * ## Filtering Options * * - **Type Filtering**: Include/exclude specific suggestion types * - **Boolean Filters**: Control inclusion of nits, duplicates, additional * - **Actionable Priority**: Always include actionable items regardless of filters * * ## Sorting Options * * - **Priority Sorting**: Sort actionable items first * - **Type Grouping**: Group comments by suggestion type * - **File Ordering**: Within groups, sort by file path alphabetically * * ## Processing Pipeline * * 1. **Type Filtering**: Apply suggestion_type filters * 2. **Boolean Filtering**: Apply include_nits, include_duplicates, etc. * 3. **Priority Sorting**: Move actionable items to top if requested * 4. **Type Grouping**: Group by suggestion type if requested * 5. **File Sorting**: Sort by file path within groups * * @param comments - Array of CodeRabbit comments to process * @param options - CodeRabbit filtering and sorting options * @returns Filtered and sorted array of comments */ export declare function applyCodeRabbitFiltering(comments: Comment[], options: CodeRabbitOptions): Comment[]; export {}; //# sourceMappingURL=coderabbit.d.ts.map