Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CLAUDE.md — reviewd

Local AI code review daemon for GitHub/BitBucket PRs. See README.md for full docs.
Local AI code review daemon for GitHub/GitLab/BitBucket PRs. See README.md for full docs.

## Project Conventions

Expand Down Expand Up @@ -28,6 +28,7 @@ Local AI code review daemon for GitHub/BitBucket PRs. See README.md for full doc
| `src/reviewd/providers/base.py` | Abstract GitProvider ABC |
| `src/reviewd/providers/bitbucket.py` | BitBucket 2.0 API (httpx, pagination with ID dedup, inline comments) |
| `src/reviewd/providers/github.py` | GitHub REST API v3 (httpx, Link header pagination, review comments) |
| `src/reviewd/providers/gitlab.py` | GitLab REST API v4 (httpx, self-hosted `url`, MR notes + diff discussions) |

## Releasing

Expand All @@ -50,6 +51,7 @@ rm -rf dist && uv build && uv publish
- Claude CLI rejects nested sessions — must unset `CLAUDECODE` env var in subprocess
- Gemini CLI loads global extensions by default — use `-e none` to disable
- Codex CLI outputs raw JSON (no markdown fences) — extract_json falls back to raw JSON object parsing
- GitLab inline comments anchor only on lines shown in the MR diff; findings on other lines (or in files GitLab collapsed) become file-level comments that name the line. `critical_task` is BitBucket-only
- Inline suggestions are single-line only (TODO: multi-line support)
- AI may hallucinate line numbers — prompt instructs to double-check but not guaranteed
- `cli: claude_interactive` drives an *interactive* Claude session over a pexpect PTY (no `--print`, no tmux), to bill against the subscription instead of API credits. The prompt tells Claude to write the review JSON to a temp file via `Write` + atomic `mv`; reviewd waits for that file (watching the PTY stream for usage/login errors + an overall timeout). Requires `claude` logged in via `/login`; if `ANTHROPIC_API_KEY` is exported it may still be used. Runs with `--dangerously-skip-permissions` so Write/Bash run unattended in the worktree.
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![CI](https://github.com/simion/reviewd/actions/workflows/ci.yml/badge.svg)](https://github.com/simion/reviewd/actions/workflows/ci.yml)

**Your local code review assistant** — review GitHub and BitBucket pull requests from your terminal, powered by Claude Code / Gemini / Codex CLI.
**Your local code review assistant** — review GitHub, GitLab and BitBucket pull requests from your terminal, powered by Claude Code / Gemini / Codex CLI.

https://github.com/user-attachments/assets/e99705d6-5595-478e-b5de-f47d3abcfa37

Expand Down Expand Up @@ -67,7 +67,7 @@ Requires Python 3.12+. You also need `claude`, `gemini`, or `codex` CLI installe
reviewd init # interactive wizard — detects repos, guides token creation, writes config
```

The wizard scans your repos, detects GitHub/BitBucket remotes, validates credentials, and writes both global and per-project configs. Prefer YAML? Choose "Sample config file" to get an annotated template instead.
The wizard scans your repos, detects GitHub/GitLab/BitBucket remotes, validates credentials, and writes both global and per-project configs. Prefer YAML? Choose "Sample config file" to get an annotated template instead.

<details>
<summary><b>GitHub setup</b></summary>
Expand Down Expand Up @@ -124,7 +124,29 @@ repos:

</details>

Both providers can be used in the same config. Tokens support `${ENV_VAR}` substitution.
<details>
<summary><b>GitLab setup</b></summary>

1. Create a [Personal Access Token](https://gitlab.com/-/user_settings/personal_access_tokens) (or a project/group access token) with the **api** scope.
2. Config:

```yaml
gitlab:
token: glpat-YOUR_TOKEN
# url: https://gitlab.example.com # self-hosted instance (default: https://gitlab.com)

repos:
- name: my-repo
repo_slug: group/subgroup/my-repo # full project path
path: ~/repos/my-repo
provider: gitlab
```

A repo on a different GitLab instance can set its own `gitlab:` block (`token` + `url`) to override the global one.

</details>

GitHub, GitLab and BitBucket repos can be mixed in the same config. Tokens support `${ENV_VAR}` substitution.

### 3. Review

Expand All @@ -140,7 +162,7 @@ reviewd watch -v # continuous review loop
Check API -> State Check (SQLite) -> Fetch & Worktree -> AI Review (Claude/Gemini/Codex) -> Parse JSON -> Post Comments -> Cleanup
```

1. Fetches open PRs from GitHub/BitBucket
1. Fetches open PRs from GitHub/GitLab/BitBucket
2. Skips already-reviewed commits, drafts, cooldowns, and small diffs
3. Creates a git worktree, runs configured test commands
4. Invokes the AI CLI with a structured prompt and JSON output schema
Expand All @@ -157,6 +179,10 @@ max_concurrent_reviews: 4
github:
token: ${GITHUB_TOKEN}

gitlab:
token: ${GITLAB_TOKEN}
# url: https://gitlab.example.com

bitbucket:
your-workspace: you@example.com:${BB_API_TOKEN}
other-workspace: other@example.com:${OTHER_BB_TOKEN}
Expand Down Expand Up @@ -185,6 +211,11 @@ repos:
workspace: your-workspace
cli: gemini # or "codex"
model: gemini-2.5-pro

- name: gl-service
repo_slug: group/gl-service
path: ~/repos/gl-service
provider: gitlab
```

### Per-project (`.reviewd.yaml` in repo root)
Expand Down Expand Up @@ -283,7 +314,7 @@ reviewd status <repo> # review history
- **Full AI tool access** — the AI reads files, runs commands, explores code in the worktree
- **JSON schema** — structured findings, the tool just parses and posts
- **SQLite state** — WAL mode, thread-safe, tracks `(repo, pr_id, commit)` to avoid duplicates
- **Provider abstraction** — GitHub and BitBucket, extensible
- **Provider abstraction** — GitHub, GitLab and BitBucket, extensible

## Security

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "reviewd"
version = "0.7.2"
description = "Local AI code reviewer for GitHub and BitBucket PRs — uses Claude, Gemini, or Codex CLI to review pull requests and post structured comments"
description = "Local AI code reviewer for GitHub, GitLab and BitBucket PRs — uses Claude, Gemini, or Codex CLI to review pull requests and post structured comments"
readme = "README.md"
license = "MIT"
requires-python = ">=3.12"
authors = [{name = "Simion Agavriloaei", email = "hi@simion.cv"}]
keywords = ["code-review", "ai", "github", "bitbucket", "pull-request", "claude", "gemini", "codex", "automation"]
keywords = ["code-review", "ai", "github", "gitlab", "bitbucket", "pull-request", "claude", "gemini", "codex", "automation"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
Expand Down
15 changes: 14 additions & 1 deletion src/reviewd/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Run `reviewd init` to copy this file to the right location.
# Uncomment and customize the settings you need.

# --- Provider credentials (configure one or both) ---
# --- Provider credentials (configure the ones you need) ---

# GitHub (requires a Personal Access Token with `repo` scope)
# github:
Expand All @@ -30,6 +30,14 @@
# my-workspace: ${BB_WORKSPACE_TOKEN} # workspace token (Bearer)
# # or: my-workspace: ${BB_EMAIL}:${BB_USER_TOKEN} # user token (Basic)

# GitLab (Personal/Project/Group Access Token with `api` scope)
# Create at: https://gitlab.com/-/user_settings/personal_access_tokens
# url defaults to https://gitlab.com — set it for self-hosted instances.
# A repo can override this with its own `gitlab:` block (token + url).
# gitlab:
# token: ${GITLAB_TOKEN}
# # url: https://gitlab.example.com

# --- AI CLI settings ---

# AI CLI to use: "claude" or "gemini" (default: claude)
Expand Down Expand Up @@ -141,6 +149,11 @@ repos: []
# path: ~/repos/my-bb-project
# provider: bitbucket
# workspace: my-workspace # must match a key in bitbucket section
#
# - name: my-gl-project
# repo_slug: group/subgroup/my-gl-project # full project path for GitLab API
# path: ~/repos/my-gl-project
# provider: gitlab
# # cli: gemini # override per repo
# # model: gemini-2.5-pro # override per repo

Expand Down
26 changes: 26 additions & 0 deletions src/reviewd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SEVERITY_ORDER,
AutoApproveConfig,
GithubConfig,
GitlabConfig,
GlobalConfig,
ProjectConfig,
RepoConfig,
Expand Down Expand Up @@ -43,6 +44,13 @@ def _parse_github_config(data: dict) -> GithubConfig:
)


def _parse_gitlab_config(data: dict) -> GitlabConfig:
return GitlabConfig(
token=_resolve_env_vars(str(data['token'])),
url=_resolve_env_vars(str(data.get('url', GitlabConfig.url))),
)


def _parse_cli(value: str, repo_name: str | None = None) -> CLI:
value = str(value).strip()
if ' ' in value:
Expand Down Expand Up @@ -148,6 +156,8 @@ def load_global_config(path: str | Path | None = None) -> GlobalConfig:
if 'github' in data:
global_gh = _parse_github_config(data['github'])

global_gl = _parse_gitlab_config(data['gitlab']) if 'gitlab' in data else None

global_cli = _parse_cli(data.get('cli', 'claude'))

repos = []
Expand All @@ -159,6 +169,7 @@ def load_global_config(path: str | Path | None = None) -> GlobalConfig:
repo_gh = None
if 'github' in repo_data:
repo_gh = _parse_github_config(repo_data['github'])
repo_gl = _parse_gitlab_config(repo_data['gitlab']) if 'gitlab' in repo_data else None

repo_cli = _parse_cli(repo_data['cli'], repo_data['name']) if 'cli' in repo_data else global_cli
repos.append(
Expand All @@ -169,6 +180,7 @@ def load_global_config(path: str | Path | None = None) -> GlobalConfig:
repo_slug=repo_data.get('repo_slug'),
workspace=repo_data.get('workspace'),
github=repo_gh,
gitlab=repo_gl,
cli=repo_cli,
model=repo_data.get('model', data.get('model')),
)
Expand All @@ -184,6 +196,7 @@ def load_global_config(path: str | Path | None = None) -> GlobalConfig:
repos=repos,
bitbucket=global_bb,
github=global_gh,
gitlab=global_gl,
state_db=state_db,
cli=global_cli,
model=data.get('model'),
Expand Down Expand Up @@ -317,13 +330,26 @@ def resolve_github_config(global_config: GlobalConfig, repo_config: RepoConfig)
raise ValueError(f'No github config found for repo "{repo_config.name}"')


def resolve_gitlab_config(global_config: GlobalConfig, repo_config: RepoConfig) -> GitlabConfig:
if repo_config.gitlab is not None:
return repo_config.gitlab
if global_config.gitlab is not None:
return global_config.gitlab
raise ValueError(f'No gitlab config found for repo "{repo_config.name}"')


def get_provider(global_config: GlobalConfig, repo_config: RepoConfig) -> GitProvider:
if repo_config.provider == 'github':
from reviewd.providers.github import GithubProvider

config = resolve_github_config(global_config, repo_config)
return GithubProvider(config)

if repo_config.provider == 'gitlab':
from reviewd.providers.gitlab import GitlabProvider

return GitlabProvider(resolve_gitlab_config(global_config, repo_config))

from reviewd.providers.bitbucket import BitbucketProvider

workspace, token = resolve_bitbucket_config(global_config, repo_config)
Expand Down
8 changes: 8 additions & 0 deletions src/reviewd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class GithubConfig:
token: str


@dataclass
class GitlabConfig:
token: str
url: str = 'https://gitlab.com'


@dataclass
class AutoApproveConfig:
enabled: bool = False
Expand Down Expand Up @@ -101,6 +107,7 @@ class RepoConfig:
repo_slug: str | None = None
workspace: str | None = None
github: GithubConfig | None = None
gitlab: GitlabConfig | None = None
cli: CLI = CLI.CLAUDE
model: str | None = None

Expand All @@ -114,6 +121,7 @@ class GlobalConfig:
repos: list[RepoConfig]
bitbucket: dict[str, str] = field(default_factory=dict)
github: GithubConfig | None = None
gitlab: GitlabConfig | None = None
state_db: str = ''
cli: CLI = CLI.CLAUDE
model: str | None = None
Expand Down
40 changes: 40 additions & 0 deletions src/reviewd/providers/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
from __future__ import annotations

import logging
import time
from abc import ABC, abstractmethod

import httpx

from reviewd.models import PRInfo

logger = logging.getLogger(__name__)


def parse_next_link(link_header: str) -> str | None:
for part in link_header.split(','):
if 'rel="next"' in part:
url = part.split(';')[0].strip().strip('<>')
return url
return None


class GitProvider(ABC):
client: httpx.Client

def _request(self, method: str, url: str, **kwargs) -> httpx.Response:
max_retries = 3
for attempt in range(max_retries + 1):
resp = self.client.request(method, url, **kwargs)
if resp.status_code != 429 or attempt == max_retries:
resp.raise_for_status()
return resp
retry_after = int(resp.headers.get('Retry-After', 2**attempt))
logger.warning('Rate limited (429), retrying in %ds (attempt %d/%d)', retry_after, attempt + 1, max_retries)
time.sleep(retry_after)
return resp # unreachable, but keeps type checkers happy

def _request_raw(self, method: str, url: str, **kwargs) -> httpx.Response:
"""Like _request but without raise_for_status — caller handles status codes."""
max_retries = 3
for attempt in range(max_retries + 1):
resp = self.client.request(method, url, **kwargs)
if resp.status_code != 429 or attempt == max_retries:
return resp
retry_after = int(resp.headers.get('Retry-After', 2**attempt))
logger.warning('Rate limited (429), retrying in %ds (attempt %d/%d)', retry_after, attempt + 1, max_retries)
time.sleep(retry_after)
return resp # unreachable

@abstractmethod
def list_open_prs(self, repo_slug: str) -> list[PRInfo]: ...

Expand Down
25 changes: 0 additions & 25 deletions src/reviewd/providers/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import re
import time

import httpx

Expand Down Expand Up @@ -38,30 +37,6 @@ def __init__(self, workspace: str, auth_token: str):
timeout=30,
)

def _request(self, method: str, url: str, **kwargs) -> httpx.Response:
max_retries = 3
for attempt in range(max_retries + 1):
resp = self.client.request(method, url, **kwargs)
if resp.status_code != 429 or attempt == max_retries:
resp.raise_for_status()
return resp
retry_after = int(resp.headers.get('Retry-After', 2**attempt))
logger.warning('Rate limited (429), retrying in %ds (attempt %d/%d)', retry_after, attempt + 1, max_retries)
time.sleep(retry_after)
return resp # unreachable, but keeps type checkers happy

def _request_raw(self, method: str, url: str, **kwargs) -> httpx.Response:
"""Like _request but without raise_for_status — caller handles status codes."""
max_retries = 3
for attempt in range(max_retries + 1):
resp = self.client.request(method, url, **kwargs)
if resp.status_code != 429 or attempt == max_retries:
return resp
retry_after = int(resp.headers.get('Retry-After', 2**attempt))
logger.warning('Rate limited (429), retrying in %ds (attempt %d/%d)', retry_after, attempt + 1, max_retries)
time.sleep(retry_after)
return resp # unreachable

def _paginate(self, url: str, params: dict | None = None) -> list[dict]:
results = []
seen_ids: set[int] = set()
Expand Down
Loading