Event-Driven Trigger Architecture
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- scripts/autofix.py
- .github/workflows/pr_agent.yml (Inferred from README.md)
- .pr_agent.toml (Inferred from README.md)
- package.json (Referenced for test runner logic in scripts/autofix.py)
The Event-Driven Trigger Architecture manages the automated interaction between GitHub Pull Requests, the PR-Agent tool, and autonomous repair scripts. This system executes code reviews, documentation generation, and proactive bug fixing based on repository events such as PR comments or CI failures. The architecture centralizes global configurations while allowing repository-level overrides to tailor tool behavior for specific environments.
Sources: README.md:1-10, scripts/autofix.py:5-20
Trigger Mechanisms
The system responds to various event triggers to initiate automated workflows. These triggers fall into two primary categories: manual interactive commands and automated CI/CD state changes.
Interactive Command Triggers
Users initiate specific PR-Agent tools by posting comments on a Pull Request. The pr_agent.yml workflow processes these comments and executes the corresponding tool.
| Command | Action Performed |
|---|---|
/review | Executes full code review, including security and test analysis. |
/describe | Generates a comprehensive PR description and changelog. |
/improve | Provides commit-ready inline code suggestions. |
/ask <question> | Provides AI-driven answers to specific questions about PR changes. |
/autofix | Triggers the autonomous repair script to resolve review findings. |
Sources: README.md:20-27, scripts/autofix.py:155-165
Autonomous State Triggers
The autofix.py script operates in two distinct modes based on the current state of the Pull Request and CI pipeline:
- review-fix mode: Triggered when PR-Agent leaves review findings (inline comments or summaries) on a PR.
- ci-fix mode: Triggered as a fallback when no review findings exist but the repository's test or build check command fails.
Sources: scripts/autofix.py:10-15, scripts/autofix.py:273-300
Workflow Coordination
The coordination logic determines how the system fetches context, invokes Large Language Models (LLMs), and applies changes to the codebase.
Event Processing Flow
The following diagram illustrates the decision logic within the autonomous trigger system:
The workflow ensures that any AI-generated change is validated by the local test runner before it is committed to the branch.
Sources: scripts/autofix.py:340-365, scripts/autofix.py:228-250
Component Interaction
The system integrates several components to complete a trigger-action cycle:
- GitHub API: Used to fetch review comments, issue comments, and modified file lists.
- Gemini API: Acts as the reasoning engine to generate code repairs based on review findings or error logs.
- Git CLI: Handles branch diffing, committing, and pushing updated code.
- Test Runners: Automatically detected (e.g.,
npm test,cargo check,pytest) to verify fixes.
Sources: scripts/autofix.py:55-80, scripts/autofix.py:116-140, scripts/autofix.py:143-160
Configuration Inheritance
The trigger architecture follows a hierarchical configuration model defined in .pr_agent.toml. This allows for standardized behavior across a fleet of repositories while maintaining flexibility for individual projects.
The global settings are loaded automatically for every Pull Request in the organization unless a local configuration file provides specific overrides.
Sources: README.md:5-15
Data Extraction and Context Handling
To provide accurate fixes, the architecture extracts relevant context from the event that triggered the operation.
Review Finding Extraction
In review-fix mode, the system collects data from multiple GitHub sources:
- Inline Comments: Extracts path, line number, and body of comments made by reviewers.
- Review Summaries: Scrapes comments posted by
github-actions[bot]to identify high-level issues.
Sources: scripts/autofix.py:186-215
Error Log Extraction
In ci-fix mode, the system parses the output of the failed test command to identify specific files mentioned in compiler or runtime errors.
# From scripts/autofix.py:304-312
def extract_relevant_files_from_error(error_log):
"""File paths mentioned in compiler/runtime errors."""
extracted = set()
for m in re.finditer(r"-->\s+([a-zA-Z0-9_\-/\.]+\.\w+):(\d+)", error_log):
if os.path.isfile(m.group(1).strip()):
extracted.add(m.group(1).strip())
return list(extracted)
Sources: scripts/autofix.py:304-312
Summary
The Event-Driven Trigger Architecture leverages GitHub events and PR-Agent's diagnostic capabilities to automate the software development lifecycle. By combining manual command triggers with autonomous CI-failure repairs, the system reduces the manual effort required to address code review feedback and build errors. The architecture's robustness is maintained through a strict "verify-before-push" logic and a centralized configuration management system.