File tree Expand file tree Collapse file tree 6 files changed +127
-1
lines changed
Expand file tree Collapse file tree 6 files changed +127
-1
lines changed Original file line number Diff line number Diff line change 1+ name : Amp Code Review
2+
3+ on :
4+ pull_request :
5+ types : [opened, reopened, ready_for_review]
6+
7+ jobs :
8+ review :
9+ runs-on : ubuntu-latest
10+
11+ # Ensure only one review runs per PR
12+ concurrency :
13+ group : pr-${{ github.event.pull_request.number }}
14+ cancel-in-progress : true
15+
16+ permissions :
17+ pull-requests : write
18+ checks : write
19+ contents : read
20+
21+ steps :
22+ - name : Run Amp Code Review
23+ uses : docker://ghcr.io/sourcegraph/cra-github:latest
24+ env :
25+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
26+ AMP_SERVER_URL : ${{ vars.AMP_SERVER_URL }}
27+ AMP_API_KEY : ${{ secrets.AMP_API_KEY }}
28+ with :
29+ args : node /app/dist/bin/review-action.js
Original file line number Diff line number Diff line change @@ -32,4 +32,9 @@ COPY config.yml ./
3232
3333EXPOSE 5053
3434
35+ # Ensure container runs from /app regardless of external --workdir overrides
36+ ENTRYPOINT ["sh" , "-c" , "cd /app && exec \" $@\" " , "--" ]
37+
38+ # Default: start webhook server for Docker deployments
39+ # Note: GitHub Actions overrides this CMD with review-action.js
3540CMD ["node" , "dist/server.js" ]
Original file line number Diff line number Diff line change @@ -15,6 +15,37 @@ A GitHub App for automated code reviews using Hono.js and Amp.
1515
1616## Quick Start
1717
18+ ### GitHub Actions (Recommended)
19+
20+ The simplest way to add code reviews to any repository:
21+
22+ 1 . ** Copy the workflow file** to your repo:
23+ ``` bash
24+ mkdir -p .github/workflows
25+ # Copy review.yml from this repo to .github/workflows/
26+ ```
27+
28+ 2 . ** Configure repository settings** :
29+ - Go to your repo → Settings → Secrets and variables → Actions
30+ - Add ** Variable** : ` AMP_SERVER_URL ` = ` https://ampcode.com `
31+ - Add ** Secret** : ` AMP_API_KEY ` = your Amp API key
32+
33+ 3 . ** Create a pull request** - reviews will run automatically!
34+
35+ ### Docker Image (For Actions)
36+
37+ To build and publish the Docker image:
38+
39+ ``` bash
40+ # Build for GitHub Actions (linux/amd64)
41+ podman build --platform linux/amd64 -t ghcr.io/your-username/cra-github:latest .
42+
43+ # Push to GitHub Container Registry
44+ podman push ghcr.io/your-username/cra-github:latest
45+ ```
46+
47+ Update the workflow file to use your image: ` docker://ghcr.io/your-username/cra-github:latest `
48+
1849### Local Development
1950
20511 . ** Clone and Install**
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ import { readFileSync } from 'fs' ;
4+ import { processReview } from '../github/process-review.js' ;
5+ import { GitHubPullRequestEvent } from '../github/types.js' ;
6+
7+ async function main ( ) {
8+ try {
9+ // GitHub Actions provides the event payload via GITHUB_EVENT_PATH
10+ const eventPath = process . env . GITHUB_EVENT_PATH ;
11+ if ( ! eventPath ) {
12+ throw new Error ( 'GITHUB_EVENT_PATH environment variable not set' ) ;
13+ }
14+
15+ // Read and parse the GitHub event payload
16+ const eventData = JSON . parse ( readFileSync ( eventPath , 'utf8' ) ) ;
17+
18+ // Validate this is a pull request event
19+ if ( ! eventData . pull_request ) {
20+ console . log ( 'Not a pull request event, skipping review' ) ;
21+ return ;
22+ }
23+
24+ const payload = eventData as GitHubPullRequestEvent ;
25+
26+ // Generate a job ID for this review run
27+ const jobId = `action-${ Date . now ( ) } -${ payload . pull_request . number } ` ;
28+
29+ console . log ( `Starting review for PR #${ payload . pull_request . number } ` ) ;
30+ console . log ( `Repository: ${ payload . repository . full_name } ` ) ;
31+ console . log ( `Action: ${ payload . action } ` ) ;
32+
33+ // Call the existing review logic
34+ // Note: installationId is not used when using GITHUB_TOKEN auth
35+ await processReview ( jobId , 0 , payload ) ;
36+
37+ console . log ( 'Review completed successfully' ) ;
38+
39+ } catch ( error ) {
40+ console . error ( 'Review failed:' , error ) ;
41+ process . exit ( 1 ) ;
42+ }
43+ }
44+
45+ main ( ) ;
Original file line number Diff line number Diff line change @@ -36,6 +36,17 @@ export class GitHubClient {
3636 return new GitHubClient ( config ) ;
3737 }
3838
39+ static forToken ( config : Config , token : string ) : GitHubClient {
40+ const configWithToken = {
41+ ...config ,
42+ github : {
43+ ...config . github ,
44+ token
45+ }
46+ } ;
47+ return new GitHubClient ( configWithToken ) ;
48+ }
49+
3950 private async getAuthHeaders ( ) : Promise < Record < string , string > > {
4051 const headers = {
4152 'Accept' : 'application/vnd.github.v3+json' ,
Original file line number Diff line number Diff line change @@ -9,7 +9,12 @@ export async function processReview(
99 payload : GitHubPullRequestEvent
1010) : Promise < void > {
1111 const config = await getConfig ( ) ;
12- const githubClient = GitHubClient . forInstallation ( config , installationId ) ;
12+
13+ // Use GITHUB_TOKEN from Actions environment if available, otherwise use GitHub App
14+ const githubToken = process . env . GITHUB_TOKEN ;
15+ const githubClient = githubToken
16+ ? GitHubClient . forToken ( config , githubToken )
17+ : GitHubClient . forInstallation ( config , installationId ) ;
1318
1419 try {
1520 // Extract PR information
You can’t perform that action at this time.
0 commit comments