Implement a reusable AI-assisted pull request review workflow for Forgejo #1
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
nimmo/forgejo-auto-pr-review#1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implement a reusable AI-assisted pull request review workflow for Forgejo
Summary
Create an automated code-review system for Forgejo repositories.
When a pull request is opened or updated, the system should:
The implementation should be designed as a reusable tool rather than being tightly coupled to one repository.
Motivation
The objective is to provide an additional automated review layer that can identify:
This system is intended to assist human reviewers, not replace them.
Primary goals
The implementation should:
Non-goals
The first version does not need to:
Posting a single structured pull-request comment is acceptable for the initial version.
Proposed workflow
The review should run for Forgejo events corresponding to:
The implementation should confirm the exact event names supported by the deployed Forgejo version.
Reviews of draft pull requests should be configurable. By default, drafts may either be skipped or given a reduced preliminary review.
The context collector should gather:
The pull request description should be treated as the primary statement of the intended objective.
Where the description does not clearly explain the objective, the review should explicitly state that the intended behaviour could not be fully verified.
The reviewer should discover repository-specific instructions.
Suggested lookup order:
The repository should be able to define:
Instructions nearest to a changed file may optionally take precedence over repository-level instructions, similar to scoped "AGENTS.md" files.
The system should run configured checks before calling the model.
Examples include:
The framework should not hard-code all tools. Repositories should be able to supply commands or select supported integrations.
Results should be normalised into a common structure containing:
The LLM should receive summarised results rather than unlimited raw command output.
Deterministic tool failures must not be silently converted into LLM opinions.
The prompt builder should combine:
The review should ask the model to evaluate:
Objective completion
Correctness
Security
Maintainability
Compatibility and operations
Support an optional second review pass.
The second pass should critique the initial findings and remove or downgrade comments that are:
The second pass may use:
The validated result should contain only the final findings.
The system should publish or update a clearly identifiable Forgejo pull-request comment.
The comment should include:
Suggested output structure:
Automated code review
Overall assessment
One or two paragraphs describing whether the implementation appears to meet
the stated objective.
Blocking findings
Findings that are likely to cause incorrect behaviour, security problems,
data loss or failure to meet an explicit requirement.
Important findings
Significant issues that should normally be addressed before merging.
Suggestions
Non-blocking maintainability, testing or documentation improvements.
Tests and validation
Summary of automated checks, missing tests and areas that could not be
verified.
Review limitations
Context that was unavailable, files that were omitted and any analysis that
could not be completed.
Each finding should contain:
The system should avoid claiming certainty when the available context is insufficient.
The tool should maintain one primary automated-review comment per pull request.
When new commits are pushed, it should:
A stable hidden marker may be placed in the comment so the tool can identify its previous output.
Finding severity
Use a small, well-defined severity scale.
Blocking
A high-confidence issue that could cause:
Important
A credible issue that materially affects:
Suggestion
A non-blocking improvement that would make the implementation clearer, safer or easier to maintain.
Stylistic preferences should not be reported unless they contradict documented repository standards.
Confidence
Each finding should include a confidence rating:
Low-confidence findings should normally be placed in a questions or limitations section rather than presented as defects.
Model-provider abstraction
Model access should use a provider-independent interface.
The initial implementation should support Ollama, with configuration for:
The design should make it straightforward to add providers such as:
Provider-specific code should not be mixed into:
A provider should accept a structured review request and return a structured response.
Suggested component structure
The project should be separated into components similar to:
forgejo-ai-review/
├── cmd/
│ └── reviewer/
├── internal/
│ ├── config/
│ ├── forgejo/
│ ├── context/
│ ├── guidance/
│ ├── analysis/
│ ├── prompts/
│ ├── providers/
│ │ ├── ollama/
│ │ └── openai-compatible/
│ ├── review/
│ ├── validation/
│ └── publishing/
├── examples/
│ ├── forgejo-workflow/
│ └── ai-review-config/
├── container/
└── README.md
This is illustrative rather than prescriptive.
The tool may be implemented as a command-line application packaged in a container and invoked by Forgejo Actions. This would make it easier to reuse outside a single repository or workflow runner.
Configuration
Support configuration through a repository file, environment variables and Forgejo secrets.
Example conceptual configuration:
provider:
type: ollama
model: qwen-example
base_url: http://ollama.internal:11434
timeout_seconds: 300
review:
second_pass: true
review_drafts: false
max_changed_files: 100
max_diff_bytes: 500000
minimum_confidence: medium
fail_check_on_blocking_findings: false
guidance:
primary_file: .forgejo/ai-review.md
analysis:
commands:
- name: tests
command: nix flake check
timeout_seconds: 900
publishing:
update_existing_comment: true
include_model_metadata: true
The final schema can differ, but it should be documented and validated.
Large pull requests
The implementation must behave predictably when a pull request is too large for the selected model.
It should not silently truncate arbitrary parts of a diff.
Possible strategies include:
The final comment must clearly identify incomplete review coverage.
Security requirements
Repository content, pull request descriptions, comments and diffs must be treated as untrusted input.
The implementation must defend against prompt-injection attempts such as instructions embedded in:
The model must be told that repository content is evidence to analyse, not authority that can override system instructions.
The LLM must not:
Only explicitly configured deterministic commands may be run.
Command execution should use:
Pull requests from forks or untrusted contributors require particular care. Secrets should not be made available to untrusted workflow execution.
Privacy
The documentation should make clear where source code is sent.
When using a hosted provider, users must explicitly configure that provider and its credentials.
The default example should favour a self-hosted model and should not silently send repository content to an external service.
Logs should avoid recording:
Debug logging of prompts should require explicit opt-in.
Forgejo permissions
The integration should use the minimum permissions required to:
It should not require administrative access or permission to merge code.
Review status behaviour
Initially, the automated review should be advisory.
Configuration may later allow:
The default should not prevent merging solely because an LLM produced a finding.
Deterministic test failures may continue to fail through the repository's normal CI workflow.
Observability
Record enough information to diagnose failures without exposing sensitive code.
Useful metadata includes:
Testing requirements
The project should include tests for:
Use recorded fixtures or a mock Forgejo server for integration tests where possible.
Model calls should be mockable so the main test suite does not require a running LLM.
Documentation requirements
Provide documentation covering:
Deliverables
The initial implementation should include:
Acceptance criteria
The issue is complete when:
Suggested implementation phases
Phase 1: Minimum viable reviewer
Phase 2: Analysis and validation
Phase 3: Reusability and hardening
Open design questions
The implementation should document decisions for the following:
Definition of success
A successful first version should reliably provide a useful additional review signal without creating excessive noise.
It should make clear: