Webhooks and Event Triggers
Relevant source files
The following files were used as context for generating this wiki page:
Webhooks and event triggers facilitate autonomous code review and repair actions within the PR-Agent ecosystem. The system reacts to GitHub Pull Request events, such as comments or CI failures, to trigger specific automation scripts or reusable workflows.
This infrastructure enables two primary modes of operation: interactive command-driven review via comments and autonomous repair triggered by review findings or build failures.
Event Interaction Model
The system responds to various interaction points on a Pull Request. Users trigger specific tools by posting comments, while the autofix.py script monitors for review findings left by the AI agent or system-generated test failures.
Interactive Command Triggers
Users initiate PR-Agent tools by commenting specific slash commands on a Pull Request.
| Command | Action |
|---|---|
/review | Performs 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> | Allows specific questions regarding PR changes. |
Sources: README.md:20-24
Autonomous Trigger Flow
The autofix.py script serves as the primary engine for event-driven repairs. It determines the execution mode based on the current state of the Pull Request and previous event outputs.
The diagram shows the decision logic used by the autonomous fixer to select between review-based or CI-based repair modes.
Sources: scripts/autofix.py:27-38, scripts/autofix.py:382-411
Automated Repair Modes
The system distinguishes between events triggered by human/AI review feedback and events triggered by technical environment failures.
Review-Fix Mode
This mode activates when the GitHub API returns existing review comments or summaries. The script fetches these findings and transmits them along with file context to the LLM.
- Trigger Condition: Presence of inline review comments or issue comments from
github-actions[bot]. - Data Retrieval: Fetches comments via
/repos/{repo}/pulls/{pr_number}/comments. - Logic: Filters out
/autofixcommands and style nitpicks to focus on genuine bugs.
Sources: scripts/autofix.py:186-218, scripts/autofix.py:326-335
CI-Fix Mode
This mode triggers when no review findings exist but the local validation command fails.
- Trigger Condition: Non-zero exit code from the detected test runner.
- Context Extraction: Parsed from compiler or runtime error logs using regex patterns.
- Environment Detection: Automatically identifies
cargo,npm,pytest, orgo testbased on repository files.
Sources: scripts/autofix.py:365-380, scripts/autofix.py:73-100
GitHub API Integration
The system utilizes the GitHub REST API to monitor PR state and post feedback. It requires a GH_TOKEN for authentication and the REPO and PR_NUMBER environment variables to target specific events.
The sequence shows the interaction between the script, GitHub's event data, and the AI repair generation.
Sources: scripts/autofix.py:146-173, scripts/autofix.py:284-323
Configuration and Inheritance
Event behavior is governed by the .pr_agent.toml file. This configuration is inherited globally across all repositories owned by the user, but can be overridden at the repository level.
- Global Settings: Loaded from
JWEB0689/pr-agent-settingsfor every PR. - Reusable Workflow: Located at
.github/workflows/pr_agent.yml, allowing repositories to centralize event handling logic.
Sources: README.md:7-18
Webhooks and event triggers ensure that every Pull Request is automatically analyzed and, if necessary, repaired without manual intervention, provided the validation checks pass. Sources: [scripts/autofix.py:40-42](https://github.com/JWEB0689/pr-agent-settings/blob/77673a6aec8dfebe47356feb0668fd817c06dba6/scripts/autofix.py#L40-L42)