|
| 1 | +--- |
| 2 | +title: Use Self-Hosted CodeRabbit With GitHub |
| 3 | +sidebar_label: GitHub |
| 4 | +description: Instructions to self-host CodeRabbit and integrate it with GitHub. |
| 5 | +sidebar_position: 1 |
| 6 | +--- |
| 7 | + |
| 8 | +## Create a GitHub App |
| 9 | + |
| 10 | +Set the following Repository permissions: |
| 11 | + |
| 12 | +* Checks: Read-only |
| 13 | +* Contents: Read and write |
| 14 | +* Commit statuses: Read and write |
| 15 | +* Discussions: Read-only |
| 16 | +* Issues: Read & write |
| 17 | +* Metadata: Read-only |
| 18 | +* Pull requests: Read & write |
| 19 | + |
| 20 | +Set the following Organization permissions: |
| 21 | + |
| 22 | +* Members: Read-only |
| 23 | + |
| 24 | +Set the following events: |
| 25 | + |
| 26 | +* Meta |
| 27 | +* Issue comment |
| 28 | +* Issues |
| 29 | +* Label |
| 30 | +* Public |
| 31 | +* Pull request |
| 32 | +* Pull request review |
| 33 | +* Pull request review comment |
| 34 | +* Pull request review thread |
| 35 | +* Push |
| 36 | +* Release |
| 37 | + |
| 38 | +## Gather information from the GitHub App |
| 39 | + |
| 40 | +* App ID |
| 41 | +* Client ID |
| 42 | +* Client Secret |
| 43 | +* Webhook Secret |
| 44 | + |
| 45 | +## Prepare an `.env` file |
| 46 | + |
| 47 | +```bash |
| 48 | +# if using OpenAI |
| 49 | +LLM_PROVIDER=openai |
| 50 | +LLM_TIMEOUT=360000 |
| 51 | +OPENAI_API_KEYS=<openai-key> |
| 52 | +OPENAI_BASE_URL=[<openai-base-url>] |
| 53 | +OPENAI_ORG_ID=[<openai-org-id>] |
| 54 | +OPENAI_PROJECT_ID=[<openai-project-id>] |
| 55 | + |
| 56 | +# if using Azure OpenAI |
| 57 | +LLM_PROVIDER=azure-openai |
| 58 | +LLM_TIMEOUT=360000 |
| 59 | +AZURE_OPENAI_ENDPOINT=<azure-openai-endpoint> |
| 60 | +AZURE_OPENAI_API_KEY=<key> |
| 61 | +AZURE_GPT4OMINI_DEPLOYMENT_NAME=<gpt-4o-mini-deployment-name> |
| 62 | +AZURE_GPT4O_DEPLOYMENT_NAME=<gpt-4o-deployment-name, modelVersion: 2024-08-06> |
| 63 | +## o1-mini is optional |
| 64 | +AZURE_O1_MINI_DEPLOYMENT_NAME=[<o1-mini-deployment-name>] |
| 65 | +## o1-preview is optional: it’s very expensive but provides best reviews |
| 66 | +AZURE_O1_DEPLOYMENT_NAME=[<o1-preview-deployment-name>] |
| 67 | +## gpt-4-turbo is optional: it’s expensive but provides better reviews than gpt-4o |
| 68 | +AZURE_GPT4TURBO_DEPLOYMENT_NAME=[<gpt-4-turbo-deployment-name, modelVersion: turbo-2024-04-09>] |
| 69 | + |
| 70 | +# if using Anthropic |
| 71 | +LLM_PROVIDER=anthropic |
| 72 | +LLM_TIMEOUT=360000 |
| 73 | +ANTHROPIC_API_KEYS=<anthropic-key> |
| 74 | +ANTHROPIC_BASE_URL=[<anthropic-base-url>] |
| 75 | + |
| 76 | +TEMP_PATH=/cache |
| 77 | + |
| 78 | +AST_GREP_RULES_PATH=/home/jailuser/ast-grep-rules |
| 79 | +AST_GREP_ESSENTIALS=ast-grep-essentials |
| 80 | + |
| 81 | +SELF_HOSTED=github |
| 82 | + |
| 83 | +GH_WEBHOOK_SECRET=<webhook-secret> |
| 84 | +GITHUB_HOSTNAME=[<github-hostname>] |
| 85 | +GITHUB_APP_CLIENT_ID=<github-app-client-id> |
| 86 | +GITHUB_APP_CLIENT_SECRET=<github-app-client-secret> |
| 87 | +GITHUB_APP_ID=<github-app-id> |
| 88 | +GITHUB_APP_PEM_FILE=<flattened-pem-file> |
| 89 | + |
| 90 | +CODERABBIT_LICENSE_KEY=<license-key> |
| 91 | + |
| 92 | +CODERABBIT_API_KEY=[<coderabbitai-api-key>] |
| 93 | +ENABLE_LEARNINGS=[true] |
| 94 | +ENABLE_METRICS=[true] |
| 95 | + |
| 96 | +JIRA_HOST=[<jira-host-url>] |
| 97 | +JIRA_PAT=[<jira-personal-access-token>] |
| 98 | + |
| 99 | +LINEAR_PAT=[<linear-personal-access-token>] |
| 100 | + |
| 101 | +OAUTH2_ENDPOINT=[<endpoint>] |
| 102 | +OAUTH2_CLIENT_ID=[<client-id>] |
| 103 | +OAUTH2_CLIENT_SECRET=[<client-secret>] |
| 104 | +``` |
| 105 | + |
| 106 | +:::note |
| 107 | + |
| 108 | +* If you are using Azure OpenAI, verify that the model deployment names are in the .env file. |
| 109 | +* Values marked with [] are optional to provide. |
| 110 | +* For `GITHUB_APP_PEM_FILE`, flatten the PEM file by replacing newlines with `\n`. |
| 111 | +* For `GITHUB_HOSTNAME`, use GitHub Enterprise server's hostname, for example, “github.acme-inc.com” |
| 112 | +* You can generate `CODERABBIT_API_KEY` from CodeRabbit UI -> Organizations Settings -> API Keys. |
| 113 | + |
| 114 | +::: |
| 115 | + |
| 116 | +## Pull the CodeRabbit Docker image |
| 117 | + |
| 118 | +Using the credentials file shared with you, first authenticate and then pull the image. |
| 119 | + |
| 120 | +```bash |
| 121 | +cat coderabbit.json | docker login -u _json_key --password-stdin us-docker.pkg.dev |
| 122 | +docker pull <docker-registry>/coderabbit-agent:latest |
| 123 | +``` |
| 124 | + |
| 125 | +## Host the image |
| 126 | + |
| 127 | +You can choose to host it on a server, serverless function, or a container environment and expose the port “8080”. Run the Docker image with the equivalent of the following command on the platform of your choice, replacing the “.env” file with the path to your “.env” file: |
| 128 | + |
| 129 | +```bash |
| 130 | +docker run --env-file .env --publish 127.0.0.1:8080:8080 <docker-registry>/coderabbit-agent:latest |
| 131 | +``` |
| 132 | + |
| 133 | +### Verify the image is up |
| 134 | + |
| 135 | +You can query `/health` endpoint to verify that the coderabbit-agent service is up and running. |
| 136 | + |
| 137 | +```bash |
| 138 | +curl 127.0.0.1:8080/health |
| 139 | +``` |
| 140 | + |
| 141 | +## Install the GitHub App |
| 142 | + |
| 143 | +You can install the GitHub App on your GitHub organization or user account and point the Webhook URL to the hosted CodeRabbit instance, for example, `http://127.0.0.1:8080/github_webhooks`. GitHub will send events to the CodeRabbit instance. |
0 commit comments