Webhook-driven pipeline system for AI-powered code review on GitLab Merge Requests and Issues.
Pipeline architecture is in place. The system receives webhooks, detects commands (/oc_review, /oc_ask, /oc_test), and executes multi-stage pipelines. However, OpenCode agent integration is not yet implemented - the AgentExecutorStage currently returns placeholder results.
oc_hooks/
├── app.py # FastAPI webhook handler (async → sync bridge)
├── src/
│ ├── app_old.py # Original app (for post_gitlab_note helper)
│ └── pipelines/
│ ├── base.py # Pipeline, Stage, Context, Result classes
│ ├── registry.py # Command detection and pipeline factory
│ ├── stages/
│ │ ├── hook_resolver.py # Detect commands, post "started" note
│ │ ├── snapshot_resolver.py # Resolve SHA/branch from MR
│ │ ├── context_builder.py # Clone repo to temp directory
│ │ ├── agent_executor.py # TODO: Run OpenCode agent
│ │ └── note_updater.py # Post results or errors
│ └── commands/
│ ├── base.py # Command base class
│ ├── oc_review.py # /oc_review pipeline
│ ├── oc_ask.py # /oc_ask pipeline
│ └── oc_test.py # /oc_test pipeline
└── tests/ # Unit tests (13 passing)
/oc_review- Review code in the merge request/oc_ask- Answer questions about the code/oc_test- Run tests or analyze test coverage
uv run python app.pyOr with hot reload:
uv run uvicorn app:app --reload --host 0.0.0.0 --port 8585Problem: When the bot posts a note with results, GitLab sends another webhook event, triggering the pipeline again → infinite loop.
Current Hack Fix: The HookResolverStage filters out notes starting with "🤖 OpenCode".
Real Fix (TODO): When using a dedicated bot account, filter by user_id instead of message content. This requires:
- A GitLab bot account with its own PAT
- Checking
payload.get("user_id")against the bot's user ID - Removing the "🤖 OpenCode" string check
The AgentExecutorStage (src/pipelines/stages/agent_executor.py) currently returns placeholder results:
result = AgentResult(
content=f"Agent result for {self.agent_type}: {prompt[:100]}...",
format="markdown",
)This needs to be replaced with actual OpenCode agent invocation.
-
Configure
.env:GITLAB_URL- GitLab instance URLGITLAB_PAT- Personal Access TokenHOST/PORT- Server binding
-
Add webhook in GitLab project:
- URL:
http://your-server:8585/webhook - Trigger: Comments events
- URL:
uv run pytest tests/ -v