Skip to content

Commit b264388

Browse files
authored
Add review workflow
1 parent bc1b074 commit b264388

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/pull-request.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,54 @@ on:
88
- '*'
99

1010
jobs:
11+
review:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v3
19+
- name: Set up Node
20+
uses: actions/setup-node@v3
21+
- name: Install GoogleGenerativeAI
22+
run: |
23+
npm install @google/generative-ai
24+
- name: Get git diff
25+
run: |
26+
git fetch origin "${{ github.event.pull_request.base.ref }}"
27+
git fetch origin "${{ github.event.pull_request.head.ref }}"
28+
git diff --unified=0 "origin/${{ github.event.pull_request.base.ref }}" > "diff.txt"
29+
- name: Run Gemini-1.5-flash
30+
uses: actions/github-script@v7
31+
with:
32+
script: |
33+
const fs = require("fs");
34+
const diff_output = fs.readFileSync("diff.txt",'utf8');
35+
36+
const { GoogleGenerativeAI } = require("@google/generative-ai");
37+
const genAI = new GoogleGenerativeAI("${{ secrets.GEMINI_API_KEY }}");
38+
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash"});
39+
40+
const prompt = `You are a senior software engineer and need to perform a code review based on the results of a given git diff. Review the changed code from different perspectives and let us know if there are any changes that need to be made. If you see any code that needs to be fixed in the result of the git diff, you need to calculate the exact line number by referring to the “@@ -0,0 +0,0 @@” part. The output format is \[{“path”:“{ filepath }”, “line”: { line }, “text”: { review comment }, “side”: “RIGHT"}\] format must be respected.\n<git diff>${diff_output}</git diff>`;
41+
const result = await model.generateContent(prompt);
42+
const response = await result.response;
43+
const text = response.text();
44+
45+
fs.writeFileSync('res.txt',text);
46+
console.log('Save Results!')
47+
- name: output
48+
id: store
49+
run: |
50+
COMMENT=$(sed '/^```/d' res.txt | jq -c .)
51+
echo "comment=$COMMENT" >> $GITHUB_OUTPUT
52+
- name: Add Pull Request Review Comment
53+
uses: nbaztec/[email protected]
54+
with:
55+
comments: ${{ steps.store.outputs.comment }}
56+
repo-token: ${{ secrets.GITHUB_TOKEN }}
57+
repo-token-user-login: 'github-actions[bot]' # The user.login for temporary GitHub tokens
58+
allow-repeats: false # This is the default
1159
check-commit-message:
1260
uses: fosslight/.github/.github/workflows/base-check-commit-message.yml@main
1361
secrets:

0 commit comments

Comments
 (0)