From 5d3e15f0f5697b83afdeae7d96eb779d22543387 Mon Sep 17 00:00:00 2001 From: ztimson Date: Sat, 27 Dec 2025 19:53:48 -0500 Subject: [PATCH] Added review --- .github/workflows/review.yml | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 6 +++--- src/review.mjs | 14 +++++--------- 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/review.yml diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml new file mode 100644 index 0000000..a6f1b0a --- /dev/null +++ b/.github/workflows/review.yml @@ -0,0 +1,32 @@ +name: AI Code Review +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + review: + runs-on: ubuntu-latest + steps: + - name: Checkout PR + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Fetch base branch + run: | + git fetch origin ${{ github.event.pull_request.base.ref }} + git branch -r + + - name: Run AI Review + uses: docker://git.zakscode.com/zakscode/ai-reporter:latest + env: + AI_HOST: anthropic + AI_MODEL: claude-sonnet-4-5 + AI_TOKEN: ${{ secrets.ANTHROPIC_TOKEN }} + GIT_HOST: ${{ github.server_url }} + GIT_OWNER: ${{ github.repository_owner }} + GIT_REPO: ${{ github.event.repository.name }} + GIT_TOKEN: ${{ secrets.ASSISTANT_TOKEN }} + GIT_BRANCH: origin/${{ github.event.pull_request.base.ref }} + PULL_REQUEST: ${{ github.event.pull_request.number }} diff --git a/Dockerfile b/Dockerfile index f3ceb18..bfb2063 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM node:22 COPY . /ai -RUN cd /ai && npm ci +RUN cd /ai && npm ci && mkdir -p /github/workspace -WORKDIR /app -ENTRYPOINT ["npx", "--yes", "/ai", "review", "/app"] +WORKDIR /github/workspace +ENTRYPOINT ["npx", "--yes", "/ai", "review", "/github/workspace"] diff --git a/src/review.mjs b/src/review.mjs index 1f00920..e98a248 100644 --- a/src/review.mjs +++ b/src/review.mjs @@ -9,26 +9,22 @@ dotenv.config(); dotenv.config({path: '.env.local', override: true}); (async () => { - const + const root = process.argv[2] || process.cwd(), + branch = process.env['GIT_BRANCH'] || await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`, git = process.env['GIT_HOST'], owner = process.env['GIT_OWNER'], repo = process.env['GIT_REPO'], auth = process.env['GIT_TOKEN'], pr = process.env['PULL_REQUEST'], - root = process.argv[2] || process.cwd(), host = process.env['AI_HOST'], model = process.env['AI_MODEL'], token = process.env['AI_TOKEN']; - const comments = []; const commit = await $`cd ${root} && git log -1 --pretty=format:%H`; - const target = await $`cd ${root} && git rev-parse HEAD`; - const dest = await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`; - const gitDiff = await $`git diff ${dest} ${target}`; - const markdown = !!git; + const gitDiff = await $`cd ${root} && git diff ${branch}`; - console.log(`Inspecting: ${root} (${commit})\n`); + console.log(`Reviewing: ${root}\n`); let options = {ollama: {model, host}}; if(host === 'anthropic') options = {anthropic: {model, token}}; @@ -37,7 +33,7 @@ dotenv.config({path: '.env.local', override: true}); ...options, model: [host, model], path: process.env['path'] || os.tmpdir(), - system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity. After making all recommendations, provide a summary using 100 words or less in ${markdown ? 'markdown' : 'unstyled text'}.`, + system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity. After making all recommendations, provide a brief bullet point summary in markdown.`, tools: [{ name: 'read_file', description: 'Read contents of a file',