Skip to content

feat(aireview): add AI code review support#38348

Closed
mehrabix wants to merge 35 commits into
go-gitea:mainfrom
mehrabix:feat/ai-code-review
Closed

feat(aireview): add AI code review support#38348
mehrabix wants to merge 35 commits into
go-gitea:mainfrom
mehrabix:feat/ai-code-review

Conversation

@mehrabix

@mehrabix mehrabix commented Jul 6, 2026

Copy link
Copy Markdown

No description provided.

mehrabix added 23 commits July 5, 2026 23:50
Implement AI code review feature for pull requests with provider-agnostic
design supporting any OpenAI-compatible API (OpenRouter, OpenAI, etc.).

- Config: [ai_review] section in app.ini (ENABLED, API_TOKEN, MODEL, etc.)
- Provider interface with OpenAI-compatible implementation
- Async queue-backed notifier hooks on PR open/synchronize
- PR diff fetcher with per-file splitting and language detection
- Review orchestrator that calls AI and posts review via pull_service.SubmitReview()

Assisted-by: AI:opencode
Assisted-by: AI:opencode
Use pull_service.CreateCodeComment() with pendingReview=true for each
AI finding that has a file + line number, then SubmitReview() to publish
all inline comments with an overview summary. Findings without a valid
inline location fall back to the review body.

Assisted-by: AI:opencode
Adds a commit review cache to avoid re-reviewing unchanged PRs
when new commits are pushed. Adds EXCLUDE_PATHS config option with
filepath.Match glob support for skipping vendor, generated, and
lock files.

Assisted-by: AI:opencode
- Change ReviewRequest to accept all changed files in a single API call
- Update buildReviewPrompt for multi-file diffs
- Add SystemPrompt config field in AIRreview settings
- Refactor reviewer.go to send one request with all non-excluded files
- Remove FormatReviewOutput and sortedKeys (no longer used)

Assisted-by: opencode:deepseek-v4-flash-free
- Add WalkthroughSection and Architecture fields to ReviewResponse
- Update system prompt to request structured walkthrough with Mermaid diagrams
- Render walkthrough as collapsible section, architecture as mermaid code block
- Add per-repo config (.gitea/ai-review.yaml) with enabled, system_prompt,
  exclude_paths, and path_instructions settings
- MergeRepoConfig merges per-repo config over global defaults
- Tests for MergeRepoConfig and formatReviewBody

Assisted-by: opencode:deepseek-v4-flash-free
- Add HandlePRComment to detect and respond to @AIReview mentions on PRs
- Add Chat method to OpenAIProvider for conversational (non-JSON) responses
- Store conversation history per PR in-memory for context
- Wire CreateIssueComment notifier to trigger chat responses
- Conversation includes full PR diff context

Assisted-by: opencode:deepseek-v4-flash-free
Assisted-by: opencode:deepseek-v4-flash-free
- Add SuggestedFix struct (old_code / new_code) to ReviewComment
- Update system prompt to request suggested fixes from AI
- Render suggested fixes as collapsible before/after code blocks
- Tests for SuggestedFix parsing and rendering

Assisted-by: opencode:deepseek-v4-flash-free
- Add SortFilesByDependency using Kahn's algorithm on import graph
- Detect Go, JS/TS, Python imports from diff patches
- Import matching handles module paths (e.g. gitea.dev/services/core)
- Files sorted so dependencies come before dependents
- Stable ordering by path depth and alphabetically within same level

Assisted-by: opencode:deepseek-v4-flash-free
- Add in-memory learning store per repo
- Detect feedback patterns in chat messages (ignore, false positive, learn:)
- Inject learnings into system prompt for future reviews
- Wire chat bot to detect and store learnings from user feedback

Assisted-by: opencode:deepseek-v4-flash-free
- Update system prompt to detect missing docstrings on public APIs
- AI provides suggested_fix with docstrings to add
- Reuses existing SuggestedFix infrastructure

Assisted-by: opencode:deepseek-v4-flash-free
- Add StatusStore tracking review state per PR (pending/running/completed/issues_found/error)
- Wire status updates into reviewer.go
- Add GET /ai-review/status endpoint returning JSON with status and issue count

Assisted-by: opencode:deepseek-v4-flash-free
- Chat commands: @AIReview re-run (clears cache and re-triggers review)
- Chat commands: @AIReview dismiss file.go:42 (skips finding in future reviews)
- Add Clear method to commitCache, DismissFinding/IsFindingDismissed to status store
- Filter dismissed findings in reviewer.go before posting comments

Assisted-by: opencode:deepseek-v4-flash-free
- Add BuildCodeGraph to extract exports and cross-file imports from diffs
- Support Go (func/type/var), JS/TS (export), Python (def/class)
- Inject code relationship graph into the review prompt
- Helps AI understand cross-file impact of changes

Assisted-by: opencode:deepseek-v4-flash-free
- Add CustomChecks to per-repo YAML config
- Add CheckResult type to ReviewResponse
- Append checks to user prompt for AI evaluation
- Render pass/fail results in review body
- Tests for custom checks in MergeRepoConfig

Assisted-by: opencode:deepseek-v4-flash-free
Assisted-by: opencode:deepseek-v4-flash-free
- Detect common linter configs (.golangci.yml, .eslintrc, etc.) from repo
- Include detected linter config info in review prompt
- Helps AI align with project linting rules

Assisted-by: opencode:deepseek-v4-flash-free
- Parse PR description for GitHub-style (Fixes go-gitea#123) and Jira-style (PROJ-123) references
- Include referenced issue IDs in the review prompt for context

Assisted-by: opencode:deepseek-v4-flash-free
- Add GenerateSprintReport to list open PRs with AI summarization
- Chat-triggered report generation for quick standup summaries

Assisted-by: opencode:deepseek-v4-flash-free
- Add ai-review CLI subcommand reading from stdin (git diff), file, or diff path
- Uses configured AI provider to review local changes and print results
- Integration with existing urfave/cli v3 framework

Assisted-by: opencode:deepseek-v4-flash-free
Remove comments that merely describe what code does (narrate code)
without explaining why. Keep Go-standard exported symbol docs and
comments that explain rationale.

Also fix indentation bug in reviewer.go and add build artifacts
to .gitignore.

Assisted-by: opencode:deepseek-v4-flash-free
Add provider implementations for:
- Anthropic (Claude) - uses /v1/messages with x-api-key auth
- Google Gemini - uses /v1beta/models with query param auth

Promote Chat to the Provider interface so all providers support
both review and conversational chat. chatMessage type consolidated
into shared ChatMessage in provider.go.

Add auto-detection (PROVIDER=auto) that maps API URLs:
- anthropic.com -> anthropic
- googleapis.com/generativelanguage -> gemini
- anything else -> openai (covers all OpenAI-compatible APIs)

Users can now freely use any provider by setting:
  PROVIDER = anthropic | gemini | openai | openrouter | auto
  API_URL = <provider endpoint>
  API_TOKEN = <your api key>
  MODEL = <model name>

Assisted-by: opencode:deepseek-v4-flash-free
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 6, 2026
@mehrabix mehrabix changed the title Feat/ai code review feat(aireview): add AI code review support Jul 6, 2026
@github-actions github-actions Bot added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jul 6, 2026
@TheFox0x7
TheFox0x7 marked this pull request as draft July 6, 2026 07:13
Assisted-by: opencode:deepseek-v4-flash-free
mehrabix added 6 commits July 6, 2026 11:07
… return

Add blank lines between internal and external import groups in
aireview.go and config.go. Replace bare return with explicit values
in MergeRepoConfig early return.

Assisted-by: opnucp:opencode-v3
Also satisfy golangci-lint fmt requirement that all returns in
named-return functions must be explicit.

Assisted-by: opnucp:opencode-v3
- perfsprint: fmt.Errorf -> errors.New for static strings
- perfsprint: fmt.Sprintf -> string concatenation where simpler
- staticcheck QF1012: WriteString(fmt.Sprintf(...)) -> fmt.Fprintf(...)
- govet: remove trailing newline from Println
- depguard: encoding/json -> gitea.dev/modules/json
- modernize: strings.Split -> strings.SplitSeq
- modernize: string += in loops -> strings.Builder
- modernize: map copy loop -> maps.Copy
- modernize: omitempty on nested struct field
- unused: remove defaultBranchForConfig const
- nilnil: add nolint comments
- errcheck: handle fmt.Sscanf return
- mirror: bytes.HasSuffix -> strings.HasSuffix
- wastedassign: remove unused initial assignment
- staticcheck S1016: type conversion instead of struct literal

Assisted-by: opnucp:opencode-v3
…pic, config

- Replace remaining WriteString(fmt.Sprintf(...)) with fmt.Fprintf(...)
- Replace string += in loop with strings.Builder in anthropic.go
- Add explanations to //nolint: nilnil directives

Assisted-by: opnucp:opencode-v3
@mehrabix
mehrabix marked this pull request as ready for review July 6, 2026 09:44
mehrabix added 3 commits July 6, 2026 14:18
Adds a Vue component (AIRreviewStatus.vue) that fetches review status
from the existing JSON endpoint and displays a compact badge with icon
in the merge box area. Shows pending/running/completed/error states.

Assisted-by: opnucp:opencode-v3
- Replace bare fetch() with GET() import from modules/fetch.ts
- Replace .then() with await (unicorn/prefer-await)
- Fix Tailwind color classes: tw-text-yellow-700 -> tw-text-orange,
  tw-text-gray -> tw-text-secondary

Assisted-by: opencode:deepseek-v4-flash-free
- Add break to each case in iconClass computed to prevent fallthrough
- Add v-if to SvgIcon to avoid passing empty string as SvgName type

Assisted-by: opencode:deepseek-v4-flash-free
@bircni

bircni commented Jul 6, 2026

Copy link
Copy Markdown
Member

Missing Description + UI

@bircni
bircni marked this pull request as draft July 6, 2026 16:44
@techknowlogick

Copy link
Copy Markdown
Member

Thank you for this PR. While some people may benefit from this, it might be better achieved as a Gitea Actions action, since Actions already has status reporting, secrets, queuing, etc..
In addition, this PR also has several inconsistencies with existing approaches, and so I'm going to close this PR, but if you need assistance creating that action please feel free to reach out to me in our chat and I can help out:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants