Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/code-review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Code Review

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
pull-requests: write

jobs:
explain-change:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install script deps
run: |
python -m pip install --upgrade pip
pip install git+https://github.com/sbekkerm/llm-code-review.git@main

- name: Gather PR diff
id: diff
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
git diff --unified=0 "$BASE_SHA" "$HEAD_SHA" > pr.diff || true
echo "diff_path=pr.diff" >> "$GITHUB_OUTPUT"

- name: Run LLM review
id: explain
env:
LLM_API_URL: ${{ secrets.LLM_API_URL }}
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
LLM_MODEL_NAME: ${{ secrets.LLM_MODEL_NAME }}
LLM_TIMEOUT_SECONDS: 60
LLM_MAX_TOKENS: 700
LLM_MAX_CHARS_PER_CHUNK: 12000
run: |
llm-code-review --diff "${{ steps.diff.outputs.diff_path }}" --out review.md
echo "review<<EOF" >> $GITHUB_OUTPUT
cat review.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Comment on PR with review
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const body = fs.readFileSync('review.md', 'utf8');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
})
Loading