### Install and Start Development Server - pnpm Source: https://context7.com/coderabbitai/coderabbit-docs/llms.txt Installs project dependencies using pnpm and starts a local development server for previewing documentation changes with hot reload support. The server typically runs on http://localhost:3000. ```bash # Install dependencies first pnpm install # Start the development server pnpm start # The server starts at http://localhost:3000 with live reload # Most changes are reflected immediately without server restart ``` -------------------------------- ### GitHub Integration Quickstart with CodeRabbit Source: https://context7.com/coderabbitai/coderabbit-docs/llms.txt Guides through setting up CodeRabbit integration with a GitHub repository. It involves creating a test repository, authorizing CodeRabbit, adding the repository to the CodeRabbit dashboard, and creating a pull request to trigger automated code review features. ```bash # 1. Create a test repository on GitHub # Repository name: coderabbit-test (private) # 2. Visit CodeRabbit login page # https://app.coderabbit.ai/login?free-trial # Click "Login with GitHub" # Click "Authorize coderabbitai" # 3. Add repository on CodeRabbit dashboard # Click "Add Repositories" # Select "Only select repositories" # Choose "coderabbit-test" # Click "Install & Authorize" # 4. Create a test pull request git checkout -b add-utils # Create simple_utils.py cat > simple_utils.py << 'EOF' # simple_utils.py - A tiny utility library def reverse_string(text): """Reverses the characters in a string.""" return text[::-1] def count_words(sentence): return len(sentence.split()) def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 EOF git add simple_utils.py git commit -m "Add utility functions" git push origin add-utils # 5. Create pull request on GitHub # CodeRabbit automatically: # - Adds PR summary if missing # - Posts "Walkthrough" analysis comment # - Attaches detailed code review # - Identifies issues (missing docstrings, no input validation) # 6. Interact with CodeRabbit # Comment on PR: # @coderabbitai Why do all of these functions need docstrings? # @coderabbitai generate docstrings # CodeRabbit creates new branch with improvements # Opens new PR with generated docstrings ``` -------------------------------- ### Ask CodeRabbit about Docstrings Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/getting-started/quickstart.md This command allows you to ask CodeRabbit for clarification on its review comments, specifically regarding the necessity of docstrings. CodeRabbit will provide a detailed explanation and offer to adjust its review approach based on your project's coding style and requirements. ```text @coderabbitai Why do all of these functions need docstrings? Isn't it obvious enough what they do? ``` -------------------------------- ### Repository Configuration File Example - YAML Source: https://context7.com/coderabbitai/coderabbit-docs/llms.txt Provides an example structure for the `.coderabbit.yaml` configuration file, which is used to define CodeRabbit's behavior within a repository. This file should be placed in the root directory of the project. ```yaml # .coderabbit.yaml - CodeRabbit configuration file ``` -------------------------------- ### Composite Rule Example: 'all' sub-rules match Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/guides/review-instructions.md Illustrates the 'all' composite rule, which requires all provided sub-rules to match for the overall rule to succeed. This example checks for 'console.log('Hello World');' and ensures it is an 'expression_statement'. ```yaml rule: all: - pattern: console.log('Hello World'); - kind: expression_statement ``` -------------------------------- ### Command CodeRabbit to Generate Docstrings Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/getting-started/quickstart.md This command instructs CodeRabbit to automatically generate docstrings for your code. Upon receiving this command, CodeRabbit will create a new branch, add the suggested docstrings, and open a new pull request for your review. ```text @coderabbitai generate docstrings ``` -------------------------------- ### Configure Path Instructions with YAML Example Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/reference/configuration.md Path instructions allow you to provide natural language guidance for reviewing specific files. Associate instructions with file paths using extended glob patterns. This YAML example sets instructions for all TypeScript, TSX, and JavaScript files within the 'src' directory, focusing on best practices and security vulnerabilities. ```yaml path_instructions: - path: src/**/*.{ts,tsx,js} instructions: | - Review the React.js/TypeScript/JavaScript code for best practices - Check for common security vulnerabilities such as: - SQL Injection - Insecure dependencies - Sensitive data exposure ``` -------------------------------- ### Installing GitHub App Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/self-hosted/github.md Install the CodeRabbit GitHub App on your organization or user account. Configure the Webhook URL to point to your hosted CodeRabbit instance to receive GitHub events. ```bash # Example Webhook URL: http://127.0.0.1:8080/github_webhooks ``` -------------------------------- ### Global Utility Rule Configuration in .coderabbit.yml Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/guides/review-instructions.md Configures ast-grep to use global utility rules by specifying the directories containing utility files. It also lists packages to be installed. This setup allows utility rules defined in external files (like 'utils/is-literal.yml') to be accessible across projects. ```yaml #... reviews: #... tools: ast-grep: essential_rules: true rule_dirs: - "rules" util_dirs: - "utils" packages: - "my-awesome-org/my-awesome-package" # public repository that contains ast-grep rules #... ``` -------------------------------- ### Example AST Review Instructions in CodeRabbit Configuration Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/guides/review-instructions.md This YAML configuration demonstrates how to define path-specific review instructions for JavaScript and test files using glob patterns. It specifies the path and the corresponding instructions for CodeRabbit to follow during code review. ```yaml #... reviews: #... path_instructions: - path: "**/*.js" instructions: | Review the JavaScript code against the Google JavaScript style guide and point out any mismatches - path: "tests/**.* instructions: | Review the following unit test code written using the Mocha test library. Ensure that: - The code adheres to best practices associated with Mocha. - Descriptive test names are used to clearly convey the intent of each test. ``` -------------------------------- ### Composite Rule Example: 'any' sub-rule matches Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/guides/review-instructions.md Shows the 'any' composite rule, which succeeds if at least one of the specified sub-rules matches. This example matches variable declarations using 'var', 'const', or 'let' with the pattern 'var a = $A'. ```yaml rule: any: - pattern: var a = $A - pattern: const a = $A - pattern: let a = $A ``` -------------------------------- ### Clone CodeRabbit Docs Repository (Shell) Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/CONTRIBUTING.md This snippet shows how to clone the CodeRabbit documentation repository to your local machine. Ensure you replace YOUR_USERNAME with your actual GitHub username. This is the first step in making contributions. ```shell git clone git@github.com:YOUR_USERNAME/coderabbit-docs.git ``` -------------------------------- ### Python Code for Utility Library Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/getting-started/quickstart.md This Python code defines a simple utility library with functions to reverse strings, count words, and convert Celsius to Fahrenheit. It serves as an example for triggering a code review by CodeRabbit. ```python # simple_utils.py - A tiny utility library def reverse_string(text): """Reverses the characters in a string.""" return text[::-1] def count_words(sentence): return len(sentence.split()) def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 ``` -------------------------------- ### Configure CodeRabbit using YAML file Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/getting-started/configure-coderabbit.md This snippet demonstrates how to set up a `.coderabbit.yaml` file to configure CodeRabbit. It can be placed in the root of your repository and is used to define various review parameters. For a complete template, refer to the documentation. ```yaml remote_config: url: "https://your-config-location/.coderabbit.yaml" ``` -------------------------------- ### Composite Rule Example: 'not' a specific pattern Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/guides/review-instructions.md Demonstrates the 'not' composite rule, which negates the result of its sub-rule. This example matches 'console.log($GREETING)' only if it is NOT 'console.log('Hello World')'. ```yaml rule: pattern: console.log($GREETING) not: pattern: console.log('Hello World') ``` -------------------------------- ### Set Path Instructions for CodeRabbit Reviews Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/guides/initial-configuration.md Provide CodeRabbit with specific review instructions for different files or locations using path instructions in a .coderabbit.yaml file. This allows for tailored reviews based on file types or directory contents, such as focusing on best practices and security for JavaScript/TypeScript code. ```yaml path_instructions: - path: "src/**/*.{ts,tsx,js}" instructions: "Review the React.js, TypeScript, JavaScript code for best practices. Check for common security vulnerabilities, such as SQL injection, insecure dependencies, and sensitive data exposure." ``` -------------------------------- ### Build and Serve Production Build - pnpm Source: https://context7.com/coderabbitai/coderabbit-docs/llms.txt Generates static production-ready files (HTML, CSS, JavaScript) for deployment and serves the built site locally for testing. This process validates links, images, and markdown syntax, failing on errors. ```bash # Build the production-ready static site pnpm build # Output is generated in the ./build directory # This validates all links, images, and markdown syntax # Build will fail on broken links or invalid configurations # Serve the production build locally for testing pnpm serve ``` -------------------------------- ### Prepare .env file for CodeRabbit Configuration (Bash/Environment) Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/self-hosted/gitlab.md Example content for a .env file used to configure the CodeRabbit agent. It includes settings for different LLM providers (OpenAI, Azure OpenAI, AWS Bedrock), proxy configurations, and OAuth2 details. Ensure sensitive information like API keys are kept secure. ```dotenv # if using OpenAI LLM_PROVIDER=openai LLM_TIMEOUT=360000 OPENAI_API_KEYS= OPENAI_BASE_URL=[] OPENAI_ORG_ID=[] OPENAI_PROJECT_ID=[] # if using Azure OpenAI LLM_PROVIDER=azure-openai LLM_TIMEOUT=360000 AZURE_OPENAI_ENDPOINT= AZURE_OPENAI_API_KEY= # it is recommended to deploy text-embedding-3-large, gpt-4.1-mini, o4-mini, o3, gpt-4.1 (optionally). AZURE_TEXT_EMBEDDING_3_LARGE_DEPLOYMENT_NAME= AZURE_GPT41MINI_DEPLOYMENT_NAME= AZURE_O4MINI_DEPLOYMENT_NAME= AZURE_O3_DEPLOYMENT_NAME= AZURE_GPT41_DEPLOYMENT_NAME=[] # optionally, deploy gpt-4o-mini instead of gpt-4.1-mini AZURE_GPT4OMINI_DEPLOYMENT_NAME=[] # optionally, deploy o3-mini instead of o4-mini AZURE_O3MINI_DEPLOYMENT_NAME=[] # optionally, deploy o1 instead of o3 AZURE_O1_DEPLOYMENT_NAME=[] # OAuth2 Configuration (optional) # This will use client_credentials flow to get an access token, # and use it to make requests to the LLM provider. # Here is more information on this flow: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow#first-case-access-token-request-with-a-shared-secret # It is expected that the response from the OAuth2 server will be in the format # { # "access_token": "", # "token_type": "Bearer", # "expires_in": 3599, # } OAUTH2_ENDPOINT=[] OAUTH2_CLIENT_ID=[] OAUTH2_CLIENT_SECRET=[] OAUTH2_SCOPE=[] HTTP_PROXY=[] HTTPS_PROXY=[] NO_PROXY=[] # if using AWS Bedrock # it is required to have access to claude-3-haiku, claude-3-5-haiku, claude-sonnet-4, claude-opus-4. LLM_PROVIDER=bedrock-anthropic LLM_TIMEOUT=360000 AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_REGION= ``` -------------------------------- ### Configure Path Filters with Bash Example Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/reference/configuration.md Path filters specify which parts of your repository CodeRabbit analyzes for code reviews. You can define include and exclude paths using glob patterns. This example demonstrates setting filters to include files in the 'src' directory while excluding '.bin' and '.csv' files. These filters are passed to 'git sparse-checkout'. ```bash src/** !**/*.{bin,csv} ``` -------------------------------- ### Optimize Database Inserts: Sequential vs. Batch Processing (TypeScript) Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/overview/why-coderabbit.md Compares two TypeScript code snippets for inserting multiple records into a database using Prisma. The 'Before' snippet shows sequential processing with Promise.all and individual 'create' calls, while the 'After' snippet demonstrates optimized batch processing using 'createMany'. This optimization reduces database round trips and improves performance. ```typescript const createdTools = await Promise.all( tools.map(async (tool) => { return prisma.tool.create({ data: { name: tool.name, description: tool.description, headline: tool.headline, features: tool.features, logo: tool.name, categories: tool.categories || [], tags: tool.tags || [], stars: tool.stars || 0, forks: tool.forks || 0, lastUpdated: new Date(), websiteUrl: tool.websiteUrl, githubUrl: tool?.githubUrl, documentation: tool?.documentation }, }); }) ); ``` ```typescript const createdTools = await prisma.tool.createMany({ data: tools.map((tool) => ({ name: tool.name, description: tool.description, headline: tool.headline, features: tool.features, logo: tool.name, categories: tool.categories || [], tags: tool.tags || [], stars: tool.stars || 0, forks: tool.forks || 0, lastUpdated: new Date(), websiteUrl: tool.websiteUrl, githubUrl: tool?.githubUrl, documentation: tool?.documentation })) }); ``` -------------------------------- ### Verify CodeRabbit Service Health Source: https://github.com/coderabbitai/coderabbit-docs/blob/main/docs/self-hosted/azure-devops.md Sends a GET request to the /health endpoint of the CodeRabbit agent to confirm it is running and accessible. This is a basic health check to ensure the service is operational. ```bash curl 127.0.0.1:8080/health ```