Skip to content
OpenSmartRoute
Skillv1.0.0

coderabbit-sdk-patterns

Apply production-ready CodeRabbit automation patterns using GitHub API and PR comments. Use when building automation around CodeRabbit reviews, processing review feedback programmatically, or integrat

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (plugins/saas-packs/coderabbit-pack/skills/coderabbit-sdk-patterns/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill coderabbit-sdk-patterns. Copyright stays with the author (MIT).

CodeRabbit SDK Patterns

Overview

CodeRabbit does not have a traditional SDK. You interact with it through .coderabbit.yaml configuration, PR comment commands (@coderabbitai), and the GitHub/GitLab API to process its review output. These patterns show how to automate around CodeRabbit reviews programmatically.

Prerequisites

  • CodeRabbit installed on repository (see coderabbit-install-auth)
  • GitHub CLI (gh) or GitHub API access via personal access token
  • Node.js 18+ for automation scripts

Instructions

Step 1: Fetch CodeRabbit Reviews via GitHub API

// scripts/fetch-coderabbit-reviews.ts
import { Octokit } from "@octokit/rest";

const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

async function getCodeRabbitReview(owner: string, repo: string, prNumber: number) {
  const reviews = await octokit.pulls.listReviews({ owner, repo, pull_number: prNumber });

  const coderabbitReview = reviews.data.find(
    (r) => r.user?.login === "coderabbitai[bot]"
  );

  if (!coderabbitReview) {
    console.log("No CodeRabbit review found yet. Review typically takes 2-5 minutes.");
    return null;
  }

  return {
    state: coderabbitReview.state,      // "APPROVED" | "CHANGES_REQUESTED" | "COMMENTED"
    body: coderabbitReview.body,         // Walkthrough summary
    submittedAt: coderabbitReview.submitted_at,
  };
}

Step 2: Extract Line-Level Comments

async function getCodeRabbitComments(owner: string, repo: string, prNumber: number) {
  const comments = await octokit.pulls.listReviewComments({
    owner, repo, pull_number: prNumber,
  });

  const coderabbitComments = comments.data
    .filter((c) => c.user?.login === "coderabbitai[bot]")
    .map((c) => ({
      file: c.path,
      line: c.line || c.original_line,
      body: c.body,
      severity: categorizeSeverity(c.body),
      url: c.html_url,
    }));

  return coderabbitComments;
}

function categorizeSeverity(body: string): "critical" | "warning" | "suggestion" {
  const lower = body.toLowerCase();
  if (lower.includes("security") || lower.includes("vulnerability") || lower.includes("injection")) {
    return "critical";
  }
  if (lower.includes("bug") || lower.includes("error") || lower.includes("issue")) {
    return "warning";
  }
  return "suggestion";
}

Step 3: Post Commands to CodeRabbit via PR Comments

// Programmatically trigger CodeRabbit actions
async function sendCodeRabbitCommand(
  owner: string, repo: string, prNumber: number, command: string
) {
  await octokit.issues.createComment({
    owner, repo, issue_number: prNumber,
    body: `@coderabbitai ${command}`,
  });
}

// Available commands:
// "full review"                    - Complete review from scratch
// "summary"                        - Generate walkthrough summary
// "resolve"                        - Mark all comments resolved
// "generate-docstrings"            - Generate docstrings for functions
// "configuration"                  - Show current config as YAML
// "run <recipe>"                   - Run a finishing touch recipe

Step 4: Build a Review Dashboard Script

#!/bin/bash
# scripts/coderabbit-dashboard.sh - Review metrics for last 50 PRs
set -euo pipefail

ORG="${1:?Usage: $0 <org> <repo>}"
REPO="${2:?Usage: $0 <org> <repo>}"

echo "=== CodeRabbit Review Dashboard ==="
echo "Repository: $ORG/$REPO"
echo ""

# Count PRs with CodeRabbit reviews
TOTAL=$(gh api "repos/$ORG/$REPO/pulls?state=closed&per_page=50" --jq 'length')
REVIEWED=0

for PR_NUM in $(gh api "repos/$ORG/$REPO/pulls?state=closed&per_page=50" --jq '.[].number'); do
  HAS_CR=$(gh api "repos/$ORG/$REPO/pulls/$PR_NUM/reviews" \
    --jq '[.[] | select(.user.login=="coderabbitai[bot]")] | length' 2>/dev/null || echo "0")
  [ "$HAS_CR" -gt 0 ] && REVIEWED=$((REVIEWED + 1))
done

echo "Review Coverage: $REVIEWED/$TOTAL PRs reviewed ($(( REVIEWED * 100 / TOTAL ))%)"

Step 5: GitHub Actions Automation

# .github/workflows/coderabbit-gate.yml
# Block merge until CodeRabbit has reviewed
name: CodeRabbit Review Gate

on:
  pull_request_review:
    types: [submitted]

jobs:
  check-coderabbit:
    if: github.event.review.user.login == 'coderabbitai[bot]'
    runs-on: ubuntu-latest
    steps:
      - name: Check review state
        uses: actions/github-script@v7
        with:
          script: |
            const { data: reviews } = await github.rest.pulls.listReviews({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.issue.number,
            });
            const crReview = reviews.find(r => r.user.login === 'coderabbitai[bot]');
            if (crReview?.state === 'CHANGES_REQUESTED') {
              core.setFailed('CodeRabbit requested changes. Address feedback before merging.');
            } else {
              core.info(`CodeRabbit review state: ${crReview?.state || 'pending'}`);
            }

Output

  • GitHub API integration for fetching CodeRabbit review data
  • Automated command posting to trigger CodeRabbit actions
  • Review metrics dashboard script
  • CI gate that enforces CodeRabbit approval before merge

Error Handling

Issue Cause Solution
Review not found PR too new Wait 2-5 minutes for review to complete
403 from GitHub API Token missing scopes Ensure repo scope on personal access token
Bot login doesn't match Different app slug Check with coderabbitai[bot] (includes [bot] suffix)
Rate limited by GitHub Too many API calls Use pagination and caching for bulk queries

Examples

Use a scoped GitHub token in a staging workflow to retrieve CodeRabbit’s review state for one disposable pull request, then verify that a requested-changes state fails the intended gate. If the bot review is missing, return a pending result and use bounded polling; do not treat an unknown state as approval or expand token access to bypass the check.

Resources

Next Steps

Apply patterns in coderabbit-core-workflow-a for real-world review workflows.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-coderabbit-sd-a59e36/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-coderabbit-sd-a59e36.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-coderabbit-sd-a59e36",
  "kind": "skill",
  "name": "coderabbit-sdk-patterns",
  "description": "Apply production-ready CodeRabbit automation patterns using GitHub API and PR comments. Use when building automation around CodeRabbit reviews, processing review feedback programmatically, or integrating CodeRabbit into custom workflows. Trigger with phrases like \"coderabbit automation\", \"coderabbit API patterns\", \"automate coderabbit\", \"coderabbit github api\", \"process coderabbit reviews\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "saas",
      "coderabbit",
      "automation",
      "github-api",
      "typescript",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Apply production-ready CodeRabbit automation patterns using GitHub API and PR comments. Use when building automation around CodeRabbit reviews, processing review feedback programmatically, or integrating CodeRabbit into custom workflows. Trigger with phrases like \"coderabbit automation\", \"coderabbit API patterns\", \"automate coderabbit\", \"coderabbit github api\", \"process coderabbit reviews\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "plugins/saas-packs/coderabbit-pack/skills/coderabbit-sdk-patterns/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/plugins/saas-packs/coderabbit-pack/skills/coderabbit-sdk-patterns/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/plugins/saas-packs/coderabbit-pack/skills/coderabbit-sdk-patterns/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Write,",
      "Edit,",
      "Bash(gh:*),",
      "Bash(node:*)"
    ],
    "license": "MIT"
  },
  "instructions": "# CodeRabbit SDK Patterns\n\n## Overview\n\nCodeRabbit does not have a traditional SDK. You interact with it through `.coderabbit.yaml` configuration, PR comment commands (`@coderabbitai`), and the GitHub/GitLab API to process its review output. These patterns show how to automate around CodeRabbit reviews programmatically.\n\n## Prerequisites\n\n- CodeRabbit installed on repository (see `coderabbit-install-auth`)\n- GitHub CLI (`gh`) or GitHub API access via personal access token\n- Node.js 18+ for automation scripts\n\n## Instructions\n\n### Step 1: Fetch CodeRabbit Reviews via GitHub API\n\n```typescript\n/",
  "cost": {
    "context_tokens": 1586
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-coderabbit-sd-a59e36/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.