--- name: coderabbit-sdk-patterns description: >- Build a least-privilege adapter for documented REST API operations without inventing endpoints or treating PR comments as an SDK. Use when this operator task needs a current, evidence-backed CodeRabbit workflow. Trigger with "integrate with the CodeRabbit API". allowed-tools: Read,Glob,Grep,Write,Edit version: 2.0.0 argument-hint: "[target] [evidence-or-scope]" model: inherit effort: high author: Jeremy Longshore license: MIT compatibility: Requires current CodeRabbit documentation and approved access for any live organization, repository, billing, or API change tags: [saas, coderabbit, api, integration, enterprise] --- # CodeRabbit API Adapter Patterns ## Overview CodeRabbit documents REST APIs for organizations, metrics, learnings, users, roles, logs, and security. Implement only referenced operations. ## Prerequisites - Identify the CodeRabbit organization, Git provider, repository, plan, and accountable owner. - Read `references/official-docs.md` and re-check any time-sensitive contract before execution. - Use synthetic or read-only evidence until the approval boundary is satisfied. - Preserve the repository's independent CI, security, and human-review requirements. ## Current Contract - API auth uses the documented `x-coderabbitai-api-key` header. - Many endpoints require Enterprise, roles, permissions, and a suitable key. - Pagination, partial success, exports, and feature flags vary. - Reviewed docs do not identify a general official language SDK. ## Authentication Treat Git-provider sessions, CodeRabbit web sessions, CLI credentials, and CodeRabbit API keys as separate credentials. Use only an already-approved session or secret-manager reference, never print a secret, and do not place credentials in `.coderabbit.yaml`, source files, logs, or deliverables. ## Instructions 1. Select one operation and record plan, permission, key type, request, pagination, and response. 2. Build a thin typed adapter with injected URL and secret reference. 3. Implement only documented errors and preserve partial success. 4. Test fixtures, then one approved read-only request. ## Tool Discipline - Use **Glob** to locate candidate configuration and evidence files without widening scope. - Use **Grep** to find relevant fields, commands, identifiers, and stale claims. - Use **Read** to inspect the smallest required files and authoritative evidence. - Use **Write** only for a new approved local draft or evidence artifact. - Use **Edit** only for a bounded approved change whose rollback is known. - Do not use these file tools as a substitute for authenticated CodeRabbit or provider operations. ## Approval Boundaries Require Admin and security approval for keys; require separate approval for writes, roles, seats, or exports. Keep analysis and drafts local until approval is explicit, and record who approved the action and its scope. ## Output A contract record, adapter, redacted fixtures, pagination handling, live-read receipt, and rotation owner. Include source dates, unknowns, and the exact boundary between observed fact and recommendation. ## Error Handling | Condition | Response | |---|---| | Current contract is unclear or docs disagree | Stop mutation, cite both sources, and request owner resolution. | | Required access or approval is missing | Produce a draft and evidence plan only. | | Validation or pilot behavior differs from expectation | Restore the prior state and retain the failed evidence. | | Output contains secrets or private code | Stop, quarantine the artifact, redact it, and notify the data owner. | ## Examples ### Example 1 Fetch paginated metrics with cursor provenance. ### Example 2 Reconcile partial success before bulk role changes. ## Validation - Confirm every claim against the dated sources in `references/official-docs.md`. - Verify the requested scope, owner, approval, happy path, failure path, and rollback. - Re-read the effective configuration or provider state after any approved change. - Report unsupported fields, undocumented endpoints, and unverified assumptions as failures. ## Resources - [Official documentation and contract notes](references/official-docs.md) - Re-check the dated contract before any live operation. - Treat unresolved or changed vendor behavior as a stop condition.