Skip to content

Commit 56bd8e0

Browse files
authored
Merge pull request #2 from xinbenlv/feat/generalized-cli-args
feat: add generalized cli_args input to action, move CLI docs to CLI.…
2 parents 5ba67fc + a16f658 commit 56bd8e0

5 files changed

Lines changed: 207 additions & 7 deletions

File tree

.github/workflows/review.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test OpenHands AI Action
1+
name: Review Pull Request
22

33
on:
44
pull_request:
@@ -7,7 +7,7 @@ on:
77
- 'action.yml'
88

99
jobs:
10-
test-action:
10+
review-pr:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout repository
@@ -19,19 +19,38 @@ jobs:
1919
run: git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > pr_diff.txt
2020

2121
- name: Upload PR Diff Artifact
22-
uses: actions/upload-artifact@v3
22+
uses: actions/upload-artifact@v4
2323
with:
2424
name: pr-diff
2525
path: pr_diff.txt
2626

27+
- name: Validate GitHub Token
28+
env:
29+
REVIEW_BOT_GITHUB_TOKEN: ${{ secrets.REVIEW_BOT_GITHUB_TOKEN }}
30+
shell: bash
31+
run: |
32+
if [ -z "$REVIEW_BOT_GITHUB_TOKEN" ]; then
33+
echo "::error::REVIEW_BOT_GITHUB_TOKEN secret is not set or is empty. Please configure it in repository/organization secrets."
34+
exit 1
35+
else
36+
echo "REVIEW_BOT_GITHUB_TOKEN is set."
37+
fi
38+
2739
- name: Automatically Review Pull Request
2840
id: openhands_valid
2941
uses: ./
3042
with:
31-
prompt: Review the pull request using the diff found in `pr_diff.txt` and provide a summary of the changes. Ensure the changes align with the repository's goals.
43+
prompt: |
44+
You are a coding expert that reviews pull requests and provides feedback.
45+
Please execute the following steps:
46+
1. Verify that the environment variable GITHUB_TOKEN is set, if not stop and report an error.
47+
2. Review the current pull request ${{ github.event.pull_request.number }}
48+
3. if the PR needs code changes,send an overall PR review comment and each individual line-level comment to Github using Github REST API.
49+
or else if the PR is overall good without needing any code changes,
50+
just send an overall comment and a PR approval to Github using Github REST API.
3251
llm_api_key: ${{ secrets.LLM_API_KEY }}
3352
log_all_events: "true"
34-
github_token: ${{ secrets.MY_GITHUB_TOKEN }}
53+
github_token: ${{ secrets.REVIEW_BOT_GITHUB_TOKEN }}
3554
additional_env: |
3655
{
3756
"SELECTED_REPO": "${{ github.repository }}"
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
name: review_pr
3+
type: task
4+
version: 1.0.1
5+
agent: CodeActAgent
6+
triggers:
7+
- review pr
8+
- review pull request
9+
- pr review
10+
- code review
11+
inputs:
12+
- name: PR_NUMBER
13+
description: 'The number of the pull request to review (e.g., 158)'
14+
required: true
15+
---
16+
17+
# PR Review Task
18+
19+
This task guides you through reviewing pull requests in ${{ SELECTED_REPO }} according to project standards.
20+
21+
## Finding file changes
22+
When reviewing file changes, instead of diffing with default branch such as `main` please diff against the base branch of the PR.
23+
24+
## Review Steps and Guidelines for Each Step
25+
26+
A high quality code review addresses 3 aspects:
27+
28+
1. is it the appropriate problem (goal)? (Pass 1)
29+
2. is it the concise and optimal solution? (Pass 2)
30+
3. is it the high quality implementation? (Pass 3)
31+
32+
For each pass, if needed, you will submit a PR-level comment and multiple line-level suggested changes via Github API.
33+
34+
When everything is done, you will submit a Github pull request review to approve the PR via Github API.
35+
36+
### **Review Pass 1: Is it the appropriate problem (goal)?**:
37+
- Review the PR description and linked issues,
38+
- Summarize the files changes and see if the PR description matches the changes
39+
- If the PR description is not aligned with the changes, ask the author to clarify the goal of the PR
40+
- If the PR description is aligned with the changes, proceed based on the understanding of the goal and the overall repository,
41+
comment on whether the goal is the right goal. The right goal of a PR should be
42+
- aligned with the overall repository goals,
43+
- not duplicating an existing functionality
44+
- should leverage the existing code and architecture unless it's intended for a upgrade/replacement/refactor
45+
- should not reinvent the wheel: suggest using popular open source libraries if they exist
46+
- should not over engineer: suggest using simple solutions if they exist
47+
- should not over generalize such as extracting a piece of code logic into a library / component when they are only being used in one place
48+
- should have proper sizing (not too big, not too small).
49+
50+
Send *PR-level comment* to ask for clarification on the goal of the PR. ONLY proceed to next Review Pass if the goal is appropriate, otherwise wait for the author to respond.
51+
52+
### **Review Pass 2: Is it the concise and optimal solution?**:
53+
- Understand whether the commit is a small change that fixes a bug or a larger change that implements a new feature/component or refactors code.
54+
- If it's a small change, skip architectural feedback, proceed to next step.
55+
- If it's a larger change, provide feedback on the architectural choices made.
56+
- Summarize the key goal and the solution to that key goal implemented in the PR
57+
- Check if the author provided documentations about major design decisions
58+
- Summarize the design decisions made by author
59+
- Check completenesss: suggest alternative approaches if applicable, and create a table to compare the pros and cons of each approach
60+
61+
Send *PR-level comment* to ask for clarification on the solution of the PR. ONLY proceed to next Review Pass if the solution is concise and optimal, otherwise wait for the author to respond.
62+
63+
### **Review Pass 3: Is it the high quality implementation?**:
64+
- Verify changes follow `.coderabbit.yaml` rules
65+
- Suggest the right implementation if the current implementation is not the right one
66+
- Suggest improvements to the code structure, naming conventions, and documentation
67+
- Check for proper error handling
68+
- Ensure consistent formatting
69+
- Check completeness: suggest other part of the code that needs to be updated to complete the implementation.
70+
71+
- **Documentation**:
72+
- Verify README/docstring updates
73+
- Check for new configuration needs
74+
75+
- **Testing**:
76+
- Confirm adequate test coverage
77+
- If unit tests should be added, suggest the right tests to add
78+
- Verify tests pass
79+
80+
Send *line-level suggested change* to ask for fixing the implementation of the PR. ONLY proceed to next Review Pass if the implementation is high quality, otherwise wait for the author to respond.
81+
82+
## Using Github API
83+
84+
Please note: use markdown in the comment or reply for better readability if it's more than a plain text.
85+
86+
### This is how you send *PR-level comment* with Github API
87+
88+
```bash
89+
curl -L \
90+
-X POST \
91+
-H "Accept: application/vnd.github+json" \
92+
-H "Authorization: Bearer <YOUR-TOKEN>" \
93+
-H "X-GitHub-Api-Version: 2022-11-28" \
94+
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments \
95+
-d '{ "body": "[COMMENT]", "commit_id": "'$(git rev-parse HEAD)'", "path": "[FILE_PATH]", "start_line": [START_LINE_NUMBER],"start_side":"[START_SIDE]","line": [LINE_NUMBER],"side":"[SIDE]"}'
96+
```
97+
98+
Note: even for PR-level comment, you still need to provide the `commit_id`, `path`, and `line` to specify the comment location so that the comment will be shown in the PR page in the most relevant location.
99+
100+
### This is how you send a *line-level suggested change* with github API
101+
102+
```bash
103+
curl -L \
104+
-X POST \
105+
-H "Accept: application/vnd.github+json" \
106+
-H "Authorization: Bearer <YOUR-TOKEN>" \
107+
-H "X-GitHub-Api-Version: 2022-11-28" \
108+
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments \
109+
-d '{ "body": "suggestion\n[SUGGESTED_CODE_WITH_ESCAPED_NEWLINES]\n", "commit_id": "'$(git rev-parse HEAD)'", "path": "[FILE_PATH]", "start_line": [START_LINE_NUMBER],"start_side":"[START_SIDE]","line": [LINE_NUMBER],"side":"[SIDE]"}'
110+
```
111+
112+
### This is how you make a reply to a review comment
113+
114+
```bash
115+
curl -L \
116+
-X POST \
117+
-H "Accept: application/vnd.github+json" \
118+
-H "Authorization: Bearer <YOUR-TOKEN>" \
119+
-H "X-GitHub-Api-Version: 2022-11-28" \
120+
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments/COMMENT_ID/replies \
121+
-d '{"body":"[REPLY]"}'
122+
```
123+
124+
### This is how you request changes to a PR
125+
126+
```bash
127+
# Example, use your own data
128+
curl -L \
129+
-X POST \
130+
-H "Accept: application/vnd.github+json" \
131+
-H "Authorization: Bearer <YOUR-TOKEN>" \
132+
-H "X-GitHub-Api-Version: 2022-11-28" \
133+
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/reviews \
134+
-d '{"commit_id":"ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091","body":"This is close to perfect! Please address the suggested inline change.","event":"REQUEST_CHANGES","comments":[{"path":"file.md","position":6,"body":"Please add more information here, and fix this typo."}]}'
135+
```
136+
137+
### This is how you approve a PR
138+
139+
```bash
140+
# Example, use your own data
141+
curl -L \
142+
-X POST \
143+
-H "Accept: application/vnd.github+json" \
144+
-H "Authorization: Bearer <YOUR-TOKEN>" \
145+
-H "X-GitHub-Api-Version: 2022-11-28" \
146+
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/reviews \
147+
-d '{"commit_id":"ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091","body":"Great stuff!","event":"APPROVE","comments":[...]}'
148+
```
149+
150+
## Reference Documents
151+
- `./coderabbit.yaml` for review standards
152+
- [Github API: Create a review comment](https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment)
153+
- [Github API: Create a reply for a review comment](https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-reply-for-a-review-comment)
154+
- [Create a review](https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review)

.openhands/microagents/repo.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: repo
3+
type: repo
4+
agent: CodeActAgent
5+
---
6+
7+
This repo contains the code for the Namefi Astra project. It is a web application that allows users to manage their domains and subdomains. Read ./README.md for more information.
8+
9+
## Interacting with Github: use the Github API and GITHUB_TOKEN
10+
11+
When interacting with github, use the github API and GITHUB_TOKEN. Do NOT use the github CLI and do NOT navigate to github.com with the web browser.

.openhands/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
git config --global user.name "D3Serve Dev Team (via OpenHands)"
3+
git config --global user.email "dev-team@d3serve.xyz"

action.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ inputs:
4343
description: 'Additional CLI arguments to pass to the OpenHands agent'
4444
required: false
4545
default: ''
46+
github_token:
47+
description: 'GitHub token for API access (will be passed as GITHUB_TOKEN env var)'
48+
required: false
49+
default: ''
4650

4751
runs:
4852
using: 'composite'
@@ -69,6 +73,7 @@ runs:
6973
ADDITIONAL_ENV: ${{ inputs.additional_env }}
7074
PROMPT: ${{ inputs.prompt }}
7175
CLI_ARGS: ${{ inputs.cli_args }}
76+
GITHUB_TOKEN: ${{ inputs.github_token }}
7277
run: |
7378
# Parse additional environment variables from JSON
7479
if [ "$ADDITIONAL_ENV" != "{}" ]; then
@@ -80,11 +85,19 @@ runs:
8085
echo "No additional environment variables provided"
8186
fi
8287
88+
# Add GITHUB_TOKEN to EXTRA_ENV_ARGS if provided
89+
if [ ! -z "$GITHUB_TOKEN" ]; then
90+
EXTRA_ENV_ARGS="$EXTRA_ENV_ARGS -e GITHUB_TOKEN=$GITHUB_TOKEN"
91+
echo "GITHUB_TOKEN will be passed to the container."
92+
else
93+
echo "GITHUB_TOKEN was not provided or is empty, not adding to EXTRA_ENV_ARGS."
94+
fi
95+
8396
# Run Docker command with all environment variables
97+
echo "Final EXTRA_ENV_ARGS (including GITHUB_TOKEN if set): $EXTRA_ENV_ARGS"
8498
echo "Running OpenHands with the following environment variables:"
8599
echo "- LLM_MODEL: $LLM_MODEL"
86100
echo "- LOG_ALL_EVENTS: $LOG_ALL_EVENTS"
87-
echo "- Additional variables: $EXTRA_ENV_ARGS"
88101
echo "- Prompt: $PROMPT"
89102
echo "- CLI Arguments: $CLI_ARGS"
90103
@@ -101,4 +114,4 @@ runs:
101114
-v /var/run/docker.sock:/var/run/docker.sock \
102115
--add-host host.docker.internal:host-gateway \
103116
${{ inputs.openhands_image }} \
104-
python -m openhands.core.main -t "${PROMPT}" $CLI_ARGS
117+
python -m openhands.core.main -t "Run export GITHUB_TOKEN=$GITHUB_TOKEN and then ${PROMPT}" $CLI_ARGS

0 commit comments

Comments
 (0)