Skip to content

Commit a44f769

Browse files
Add reviewer trigger for PR review workflow (#1037)
Co-authored-by: openhands <[email protected]>
1 parent b0b82bd commit a44f769

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

.github/workflows/pr-review-by-openhands.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
name: PR Review by OpenHands
33

44
on:
5-
# Use pull_request_target to allow fork PRs to access secrets when labeled by maintainers
6-
# Security: This workflow only runs when a maintainer adds the 'review-this' label
5+
# Use pull_request_target to allow fork PRs to access secrets when triggered by maintainers
6+
# Security: This workflow only runs when:
7+
# 1. A maintainer adds the 'review-this' label, OR
8+
# 2. A maintainer requests openhands-agent as a reviewer
9+
# Only users with write access can add labels or request reviews, ensuring security.
710
# The PR code is explicitly checked out for review, but secrets are only accessible
811
# because the workflow runs in the base repository context
912
pull_request_target:
10-
types: [labeled]
13+
types: [labeled, review_requested]
1114

1215
permissions:
1316
contents: read
@@ -16,9 +19,13 @@ permissions:
1619

1720
jobs:
1821
pr-review:
19-
# Security: Only run when 'review-this' label is added by a maintainer
20-
# Maintainers should review PR code before adding this label
21-
if: github.event.label.name == 'review-this'
22+
# Security: Only run when one of the following conditions is met:
23+
# 1. 'review-this' label is added by a maintainer, OR
24+
# 2. openhands-agent is requested as a reviewer by a maintainer
25+
# Maintainers should review PR code before triggering this workflow
26+
if: |
27+
github.event.label.name == 'review-this' ||
28+
github.event.requested_reviewer.login == 'openhands-agent'
2229
runs-on: blacksmith-4vcpu-ubuntu-2404
2330
env:
2431
LLM_MODEL: litellm_proxy/claude-sonnet-4-5-20250929

examples/03_github_workflows/02_pr_review/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PR Review Workflow
22

3-
This example demonstrates how to set up a GitHub Actions workflow for automated pull request reviews using the OpenHands agent SDK. When a PR is labeled with `review-this`, OpenHands will analyze the changes and provide detailed, constructive feedback.
3+
This example demonstrates how to set up a GitHub Actions workflow for automated pull request reviews using the OpenHands agent SDK. When a PR is labeled with `review-this` or when openhands-agent is added as a reviewer, OpenHands will analyze the changes and provide detailed, constructive feedback.
44

55
## Files
66

@@ -11,7 +11,9 @@ This example demonstrates how to set up a GitHub Actions workflow for automated
1111

1212
## Features
1313

14-
- **Automatic Trigger**: Reviews are triggered when the `review-this` label is added to a PR
14+
- **Automatic Trigger**: Reviews are triggered when:
15+
- The `review-this` label is added to a PR, OR
16+
- openhands-agent is requested as a reviewer
1517
- **Comprehensive Analysis**: Analyzes code changes in context of the entire repository
1618
- **Detailed Feedback**: Provides structured review comments covering:
1719
- Overall assessment of changes
@@ -67,9 +69,21 @@ Create a `review-this` label in your repository:
6769

6870
### Triggering a Review
6971

70-
To trigger an automated review of a pull request:
72+
There are two ways to trigger an automated review of a pull request:
73+
74+
#### Option 1: Using Labels
7175

7276
1. Open the pull request you want reviewed
7377
2. Add the `review-this` label to the PR
7478
3. The workflow will automatically start and analyze the changes
7579
4. Review comments will be posted to the PR when complete
80+
81+
#### Option 2: Requesting a Reviewer (Recommended)
82+
83+
1. Open the pull request you want reviewed
84+
2. Click on "Reviewers" in the right sidebar
85+
3. Search for and select "openhands-agent" as a reviewer
86+
4. The workflow will automatically start and analyze the changes
87+
5. Review comments will be posted to the PR when complete
88+
89+
**Note**: Both methods require write access to the repository, ensuring only authorized users can trigger the AI review.

examples/03_github_workflows/02_pr_review/workflow.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# 1. Copy this file to .github/workflows/pr-review.yml in your repository
44
# 2. Add your LLM_API_KEY to the repository secrets
55
# 3. Commit this file to your repository
6-
# 4. Add the "review-this" label to any PR to trigger the review
6+
# 4. Trigger the review by either:
7+
# - Adding the "review-this" label to any PR, OR
8+
# - Requesting openhands-agent as a reviewer
79
name: PR Review by OpenHands
810

911
on:
10-
# Trigger when a label is added to a pull request
12+
# Trigger when a label is added or a reviewer is requested
1113
pull_request:
12-
types: [labeled]
14+
types: [labeled, review_requested]
1315

1416
permissions:
1517
contents: read
@@ -18,7 +20,10 @@ permissions:
1820

1921
jobs:
2022
pr-review:
21-
if: github.event.label.name == 'review-this'
23+
# Run when review-this label is added OR openhands-agent is requested as reviewer
24+
if: |
25+
github.event.label.name == 'review-this' ||
26+
github.event.requested_reviewer.login == 'openhands-agent'
2227
runs-on: ubuntu-latest
2328
env:
2429
# Configuration (modify these values as needed)

0 commit comments

Comments
 (0)