Add more context to automated reviews (#3891)
This commit is contained in:
30
.github/workflows/pr-review.yml
vendored
30
.github/workflows/pr-review.yml
vendored
@@ -55,7 +55,7 @@ jobs:
|
||||
- id: install-deps
|
||||
name: Install Dependencies
|
||||
run: |
|
||||
pip install google-cloud-aiplatform
|
||||
pip install google-genai
|
||||
|
||||
- id: generate-diff
|
||||
name: Generate PR Diff
|
||||
@@ -70,16 +70,36 @@ jobs:
|
||||
# Generate the diff between the PR base and the PR head
|
||||
git diff "$BASE_SHA"..."$HEAD_SHA" > pr.diff
|
||||
|
||||
- id: fetch-comments
|
||||
name: Fetch PR Comments
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const comments = await github.rest.issues.listComments({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
per_page: 20,
|
||||
sort: 'created',
|
||||
direction: 'desc'
|
||||
});
|
||||
const fs = require('fs');
|
||||
fs.writeFileSync('pr_comments.json', JSON.stringify(comments.data));
|
||||
|
||||
- id: run-review
|
||||
name: Run Gemini PR Review
|
||||
env:
|
||||
VERTEX_PROJECT: ${{ vars.REVIEWS_VERTEX_PROJECT }}
|
||||
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||||
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
run: |
|
||||
# The script prints the review to stdout, which we capture into a file
|
||||
|
||||
python3 tools/pr_review.py \
|
||||
--project "$VERTEX_PROJECT" \
|
||||
--diff-file pr.diff > review_output.md
|
||||
--diff-file pr.diff \
|
||||
--comments-file pr_comments.json \
|
||||
--base-sha "$BASE_SHA" \
|
||||
--head-sha "$HEAD_SHA" > review_output.md
|
||||
|
||||
- id: pr-comment
|
||||
name: Post comment to Pull Request
|
||||
uses: actions/github-script@v7
|
||||
@@ -87,7 +107,7 @@ jobs:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const reviewContent = fs.readFileSync('review_output.md', 'utf8');
|
||||
const output = `### Automated PR Review 🤖\n\n${reviewContent}`;
|
||||
const output = `### Automated PR Review 🤖\n*(Reviewed commit: ${context.payload.pull_request.head.sha})*\n\n${reviewContent}`;
|
||||
|
||||
github.rest.issues.createComment({
|
||||
issue_number: context.issue.number,
|
||||
|
||||
Reference in New Issue
Block a user