go · github actions · ollama

Reads your diff like a senior engineer. Never leaves your network.

AI Code Reviewer is a GitHub Action that reviews every pull request with a self-hosted Ollama model, with full file context, inline comments on the exact line, and no cloud API bill.

sample.go · pull_request #42 reviewing live
4 findings1 file reviewedmodel: qwen2.5-coder:7b
the repo
PotatoNoodIes/code_reviewer Open repo →

A GitHub Action that reviews pull requests like a senior engineer: bugs, security issues, simplification opportunities, and style, using a self-hosted Ollama model instead of a paid external API.

git clone https://github.com/PotatoNoodIes/code_reviewer.git
what it checks

Four categories, every file, every push.

The same system prompt runs on every changed file: no generic linting rules, no invented nits. If a file is clean, it says so.

bug

Logic & correctness

Off-by-ones, wrong conditionals, mishandled errors: things that will misbehave, crash, or return the wrong answer.

security

Vulnerabilities

Injection, hardcoded secrets, unsafe deserialization, missing auth or validation.

simplification

Reuse & clarity

Code that works but could be clearer, shorter, or shouldn't be duplicated.

style

Naming & idiom

Formatting and naming issues a careful teammate would flag in passing.

how it works

One pull request, six steps.

No polling, no local checkout. Every step reads from the GitHub API directly, driven by the event that triggered the run.

01

Read the trigger

A pull_request event (opened or synchronize) fires the action; it parses the payload for owner, repo, PR number, and head SHA.

02

Select files

Changed files are listed, filtered against ignore-patterns, and capped at max-files, largest diffs reviewed first and the rest reported as skipped.

03

Parse the diff

Each unified-diff patch is parsed to find exactly which line numbers a comment is allowed to land on.

04

Fetch full context

The complete file comes from the Git Blob API at the head commit, so the model reads whole functions, not fragments.

05

Ask the model

File, diff, and a fixed senior-review system prompt go to Ollama, constrained to a JSON schema. Malformed output is retried, then skipped, never allowed to break the run.

06

Validate & post

Every finding is re-checked against the file's real commentable lines before it's trusted. Comments post one GitHub review per file, hashed to skip duplicates on the next push.

setup

Point it at a self-hosted runner.

Ollama needs to be reachable from the machine running the job, realistic for a self-hosted runner, not for GitHub-hosted ones.

.github/workflows/ai-review.yml
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  pull-requests: write  # required, default GITHUB_TOKEN is read-only

jobs:
  review:
    runs-on: self-hosted
    steps:
      - uses: PotatoNoodIes/code_reviewer@v1
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          ollama-url: http://localhost:11434
          ollama-model: qwen2.5-coder:7b
InputDefaultDescription
github-tokenrequiredReads PR data and posts comments.
ollama-urllocalhost:11434Base URL of the Ollama server, see note below.
ollama-modelqwen2.5-coder:7bA code-focused model reviews far better than a general chat model.
ollama-format-modeschemaJSON-schema-constrained decoding; falls back to plain json on older Ollama.
max-files15Cap per PR, largest diffs reviewed first.
ignore-patternsvendor, lockfiles…Comma-separated globs of paths to skip.
review-eventCOMMENTCOMMENT, APPROVE, or REQUEST_CHANGES.
dry-runfalsePrint findings to the log instead of posting.
reviewing the reviewer

This ships as a Docker container action, which runs in its own network namespace: localhost inside the container is not the runner host, even on self-hosted infrastructure.

  • Bind Ollama to all interfaces (OLLAMA_HOST=0.0.0.0) and point ollama-url at the runner's real LAN IP or Docker bridge gateway.
  • Or run the self-hosted runner itself with --network host, so job containers inherit host networking and localhost resolves as expected.
on the pull request

What actually shows up in the PR.

The same sample.go, the same four findings, rendered as the review GitHub would show. Flip review-event below to see how each mode behaves.

Fix user lookup, add password reset support
#42 · fix/user-lookup → main · 1 file changed
sample.go4 comments
7
8const apiKey = "sk-live-abc123secretkey"
9
AI
ai-code-reviewercommentedsecurity · high

Hardcoded secret in source code. Move to environment variables or a secrets manager.

⋮ 1 unchanged line
10func getUser(db *sql.DB, name string) {
11 query := "SELECT * FROM users WHERE name = '" + name + "'"
12 rows, _ := db.Query(query)
AI
ai-code-reviewercommentedbug · high

SQL injection via string concatenation. Use a parameterized query.

⋮ 4 unchanged lines
17 total := 0
18 for i := 0; i <= len(nums); i++ {
19 total += nums[i]
AI
ai-code-reviewercommentedbug · high

Off-by-one: i <= len(nums) reads one index past the end of the slice.

⋮ 4 unchanged lines
24func printAll(items []string) {
25 for i := 0; i < len(items); i++ {
26 fmt.Println(items[i])
AI
ai-code-reviewercommentedsimplification · medium

This loop duplicates the one below it; one pass is enough.

AI
ai-code-reviewer COMMENTED

Left 4 comments across 1 file. A COMMENT review never blocks or requires action before merging.

No review requirement triggered, merge whenever you're ready.
known limits

What v1 doesn't do yet.

run it yourself

No PR required to try it.

Unit tests need no network. The dry run hits a real PR but never posts a comment.

terminal
$ make build test vet
ok   internal/githubapi   0.006s
ok   internal/ollama       0.002s
ok   internal/review       0.006s

$ GITHUB_TOKEN=<token> DRY_RUN=true \
    go run ./cmd/reviewer --owner <owner> --repo <repo> --pr <number>
emulation sandbox

Go ahead, type something.

A live 1977-style terminal. Click in and type HELP to see what it knows.

An interactive retro computer terminal. Focus the terminal and type commands such as HELP, LIST, or REVIEW SAMPLE.GO to run a scripted review and see its output.

MODEL 3070 · INTERACTIVE EMULATION · TRY HELP