Skip to content

Commit c0fc81f

Browse files
committed
Working on GH
0 parents  commit c0fc81f

32 files changed

+6792
-0
lines changed

.env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# GitHub App Configuration
2+
GITHUB_APP_ID=your_github_app_id
3+
GITHUB_APP_NAME=your-app-name
4+
GITHUB_APP_CLIENT_ID=your_github_app_client_id
5+
GITHUB_APP_CLIENT_SECRET=your_github_app_client_secret
6+
GITHUB_APP_PRIVATE_KEY=your_github_app_private_key_base64_encoded
7+
GITHUB_APP_PRIVATE_KEY_PATH=./private-key.pem
8+
GITHUB_WEBHOOK_SECRET=your_webhook_secret
9+
GITHUB_REDIRECT_URI=http://localhost:5053/github/callback
10+
GITHUB_BASE_URL=https://github.com
11+
12+
# Server Configuration
13+
PORT=5053
14+
DEBUG=true
15+
APP_BASE_URL=http://localhost:5053
16+
17+
# Amp Configuration
18+
AMP_TIMEOUT=60000
19+
AMP_SERVER_URL=ws://localhost:3001
20+
AMP_URL=http://localhost:3001

.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Production builds
8+
dist/
9+
build/
10+
11+
# Environment variables
12+
.env
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
# IDE and editor files
19+
.vscode/
20+
.idea/
21+
*.swp
22+
*.swo
23+
*~
24+
25+
# OS generated files
26+
.DS_Store
27+
.DS_Store?
28+
._*
29+
.Spotlight-V100
30+
.Trashes
31+
ehthumbs.db
32+
Thumbs.db
33+
34+
# Logs
35+
logs
36+
*.log
37+
38+
# Data directory
39+
data/
40+
41+
# Temporary files
42+
*.tmp
43+
*.temp
44+
45+
# Keys
46+
*.pem
47+
*.key

README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# GitHub Code Review Agent
2+
3+
A GitHub App for automated code reviews using Hono.js and Amp.
4+
5+
## Features
6+
7+
- **GitHub App Integration**: Secure GitHub App installation and authentication
8+
- **Webhook Processing**: Automatic pull request event handling
9+
- **Queue Management**: Efficient job queuing and processing
10+
- **Code Review**: AI-powered code analysis and feedback
11+
- **Check Runs**: Integration with GitHub's check runs API for status reporting
12+
13+
## Quick Start
14+
15+
1. **Clone and Install**
16+
```bash
17+
cd cra-github
18+
npm install
19+
```
20+
21+
2. **Environment Setup**
22+
```bash
23+
cp .env.example .env
24+
# Edit .env with your GitHub app credentials
25+
```
26+
27+
3. **Start Development Server**
28+
```bash
29+
npm run dev
30+
```
31+
32+
4. **Install the App**
33+
- Visit `http://localhost:5053/github/install`
34+
- Follow the GitHub App installation flow
35+
- Select repositories to enable code reviews
36+
37+
## Configuration
38+
39+
### GitHub App Setup
40+
41+
1. **Create a GitHub App** in your GitHub settings (`Settings > Developer settings > GitHub Apps`)
42+
2. **Set the following permissions:**
43+
- Repository: Pull requests (Read & Write)
44+
- Repository: Checks (Write)
45+
- Repository: Contents (Read)
46+
- Repository: Metadata (Read)
47+
3. **Configure webhook settings:**
48+
- Webhook URL: `https://your-domain.com/github/webhook`
49+
- Subscribe to: Pull request events
50+
4. **Generate and download a private key** from the app settings page
51+
52+
### Environment Variables
53+
54+
#### GitHub App Configuration (Required)
55+
```env
56+
# GitHub App ID (found in app settings)
57+
GITHUB_APP_ID=123456
58+
59+
# GitHub App name (used in installation URL)
60+
GITHUB_APP_NAME=your-app-name
61+
62+
# GitHub App Client ID and Secret
63+
GITHUB_APP_CLIENT_ID=Iv1.abc123def456
64+
GITHUB_APP_CLIENT_SECRET=your_app_client_secret
65+
66+
# Private Key Setup (choose one option)
67+
# Option 1: Private key file path
68+
GITHUB_APP_PRIVATE_KEY_PATH=./private-key.pem
69+
70+
# Option 2: Private key as environment variable (base64 encoded)
71+
GITHUB_APP_PRIVATE_KEY=LS0tLS1CRUdJTi...your_base64_encoded_key
72+
73+
# Webhook secret (optional but recommended)
74+
GITHUB_WEBHOOK_SECRET=your_webhook_secret
75+
```
76+
77+
#### Server Configuration
78+
```env
79+
# Server settings
80+
PORT=5053
81+
DEBUG=true
82+
APP_BASE_URL=http://localhost:5053
83+
84+
# Amp Configuration
85+
AMP_TIMEOUT=60000
86+
AMP_SERVER_URL=ws://localhost:3001
87+
AMP_URL=http://localhost:3001
88+
```
89+
90+
### Private Key Setup
91+
92+
The GitHub App requires a private key for authentication. You have two options:
93+
94+
#### Option 1: File-based (Recommended for development)
95+
1. Download the `.pem` file from your GitHub App settings
96+
2. Place it in your project root as `private-key.pem`
97+
3. Set `GITHUB_APP_PRIVATE_KEY_PATH=./private-key.pem`
98+
4. Add `*.pem` to your `.gitignore` to avoid committing the key
99+
100+
#### Option 2: Environment Variable (Recommended for production)
101+
1. Convert your private key to base64:
102+
```bash
103+
cat private-key.pem | base64 -w 0
104+
```
105+
2. Set the result as `GITHUB_APP_PRIVATE_KEY` in your environment
106+
3. The application will automatically decode and format the key
107+
108+
**Security Notes:**
109+
- Never commit private keys to version control
110+
- Use secure secret management in production
111+
- Restrict file permissions: `chmod 600 private-key.pem`
112+
113+
## API Endpoints
114+
115+
- `GET /` - Service information
116+
- `GET /health` - Health check
117+
- `POST /github/webhook` - GitHub webhook endpoint
118+
- `GET /github/install` - Start GitHub App installation
119+
- `GET /github/callback` - GitHub App installation callback
120+
- `GET /github/dashboard/:installationId` - Installation dashboard
121+
- `GET /queue/status` - Queue status information
122+
123+
## Development
124+
125+
### Build
126+
```bash
127+
npm run build
128+
```
129+
130+
### Type Check
131+
```bash
132+
npm run type-check
133+
```
134+
135+
### Lint
136+
```bash
137+
npm run lint
138+
```
139+
140+
## Architecture
141+
142+
- **Hono.js**: Fast web framework for the server
143+
- **GitHub API**: Integration with GitHub's REST API
144+
- **GitHub Apps**: Secure app installation and JWT authentication
145+
- **Job Queue**: Background processing for code reviews
146+
- **Amp**: AI-powered code analysis engine
147+
148+
## License
149+
150+
MIT License

config.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
github:
2+
base_url: "https://api.github.com"
3+
check_name: "Amp Code Review"
4+
development_mode: true
5+
bot_username: "amp-code-review-agent"
6+
7+
queue:
8+
max_workers: 20
9+
max_queue_size: 100
10+
retry_after_seconds: 60
11+
12+
# Diff splitting configuration
13+
diff_splitting:
14+
max_chunk_size: 500000 # 500k characters per chunk
15+
max_concurrent: 3
16+
17+
server:
18+
port: "${PORT:-5053}"
19+
debug: "${DEBUG:-false}"
20+
21+
amp:
22+
timeout: "${AMP_TIMEOUT}"
23+
command: "npx --yes @sourcegraph/amp@latest"
24+
server_url: "${AMP_SERVER_URL}"
25+
settings:
26+
amp.url: "${AMP_SERVER_URL}"
27+
amp.mcpServers:
28+
github:
29+
command: "sh"
30+
args:
31+
- "-c"
32+
- "cd ${GITHUB_APP_CWD} && pnpm run mcp"
33+
env:
34+
GITHUB_APP_CWD: "${GITHUB_APP_CWD}"
35+
GITHUB_APP_ID: "${GITHUB_APP_ID}"
36+
GITHUB_APP_PRIVATE_KEY_PATH: "${GITHUB_APP_PRIVATE_KEY_PATH}"
37+
38+
prompt_template: |
39+
Review this code diff as a senior developer. Look for bugs, clear logic errors, and code quality problems.
40+
Flag significant security concerns (leaked credentials, SQL injection, etc.), but do not mark minor concerns as issues.
41+
Likewise, flag significant performance concerns (memory leaks, deadlocks, long-lived requests), but do not mark minor concerns as issues. Do not use the oracle to review code.
42+
43+
Focus on:
44+
- Logic errors
45+
- Bug-prone patterns
46+
- Code quality issues
47+
- Significant security and performance problems
48+
- Obvious typos/misspellings
49+
50+
Pull request details:
51+
__PR_DETAILS_CONTENT__
52+
53+
Diff to review:
54+
__DIFF_CONTENT__
55+
56+
When reviewing code:
57+
1. Look at the pull request details to fetch the context before reviewing.
58+
2. Review the diff content to identify issues.
59+
3. Leave specific inline comments or code suggestions for each issue found.
60+
4. Create check run status when the code review is complete.
61+
62+
Always leave actionable, specific comments with suggested fixes.
63+
64+
Suggestions are optional snippets of code that can directly replace the full line the indicated issue is on. If provided, the suggestion should be just code-- no thought process included.
65+
If there is no simple code suggestion you can provide to fix the issue succinctly, provide null as the suggestion value instead.
66+
Suggestions can only be left on "new" line_type issues, not on "old" issues. For "old" issues, the suggestion should be null.
67+
68+
Tools available to complete the code review process:
69+
__TOOL_CONTENT__
70+
71+
After you have completed the code review process:
72+
IMPORTANT: If you find any issues, include all of them in a JSON block at the end with the following format:
73+
```json
74+
[
75+
{
76+
"path": "filename.ext",
77+
"line": 42,
78+
"line_type": "new"|"old",
79+
"message": "Description of the issue",
80+
"suggested_fix": "if (user == \"admin\") {"|null
81+
}
82+
]
83+
```
84+
85+
line_type must be one of "new" or "old". This is because in a diff view, the same line number can exist on both sides:
86+
Line 15 in the source (old)
87+
Line 15 in the destination (new)
88+
89+
A suggested_fix is an optional short snippet of code that will directly replace the single full line of code the indicated issue is on in order to fix the issue.
90+
Because the suggested_fix will only overwrite the single line of code with the issue (the issue line), the suggested_fix can be either:
91+
1. One line of code that will replace the issue line directly to address the issue. Here's an example where we fix a typo in the method invocation:
92+
Issue line:
93+
System.out.printl(foo);
94+
95+
suggested_fix:
96+
System.out.println(foo);
97+
98+
2. Multiple lines of code where the first line is the issue line and all subsequent lines are net new lines to be inserted after the issue line.
99+
Because the first line in this multi-line suggested_fix will directly replace the existing issue line, the first line can be unchanged if the suggested_fix is a pure insertion after the issue line,
100+
or the first line can differ from the issue line if the goal is to edit the issue line AND insert net new lines directly below it. Here's a pure insertion example where we add an auth check:
101+
Issue line:
102+
def access_data(user):
103+
104+
suggested_fix:
105+
def access_user_data(user):\n\n if not user: return\n
106+
107+
Any other cases are too complex to provide a simple suggested_fix for, so provide null as the suggested_fix value.
108+
109+
tools:
110+
- name: leave_general_comment
111+
description: Leave general comments on pull requests
112+
instructions:
113+
- "Use this tool to leave general comments on the pull request"
114+
- "This will post your comment to the overall pull request discussion"
115+
- "Use for summary comments, overall feedback, or general observations"
116+
- "Required: message, owner, repo, pr_number"
117+
- "Example: 'Overall the code looks good, just a few minor suggestions'"
118+
- name: leave_inline_comment
119+
description: Leave inline comments on specific lines in pull requests
120+
instructions:
121+
- "Use this tool to leave comments on specific lines of code"
122+
- "This will post your comment directly on the line in the diff view via PR review"
123+
- "Required: message, owner, repo, pr_number, path, line"
124+
- "Optional: commit_sha (will be fetched from PR if not provided)"
125+
- "Example: Comment on line 25 of src/auth.js about missing error handling"
126+
- name: create_check_run
127+
description: Create or update GitHub check run status
128+
instructions:
129+
- "Use to mark review completion with check run status"
130+
- "Required: owner, repo, commit_sha, status ('queued', 'in_progress', 'completed')"
131+
- "Optional: conclusion ('success', 'failure', 'neutral'), title, summary, details_url"
132+
- "Use 'completed' status with 'success' conclusion when review is done"
133+
- "Use 'completed' status with 'failure' conclusion for critical issues"
134+
- name: get_pr_info
135+
description: Get pull request details
136+
instructions:
137+
- "Use to understand context about the pull request before reviewing the diff"
138+
- "Required: owner, repo, pr_number"
139+
- "Optional: include_diff (boolean) to also fetch the diff content"
140+
- "Returns PR info, repository info, and optionally diff content"
141+
- name: trigger_review
142+
description: Start code review process
143+
instructions:
144+
- "Usually called automatically, but available if needed to retrigger code review"
145+
- "Required: owner, repo, pr_number"
146+
- "Optional: commit_sha, force (boolean)"
147+
- "Creates check run and initiates review process"
148+
- name: get_pr_comments
149+
description: Get all comments on a pull request
150+
instructions:
151+
- "Use to retrieve existing comments on the pull request"
152+
- "Required: owner, repo, pr_number"
153+
- "Returns array of comments and total count"
154+
- "Helpful to see what feedback has already been given before adding new comments"

0 commit comments

Comments
 (0)