Skip to content

LICENSE | UnifAI

LICENSE | UnifAI #488

Workflow file for this run

name: AI Code Review Assistant
on:
pull_request:
types: [opened, reopened]
workflow_dispatch:
issue_comment:
types: [created]
jobs:
review:
# Run if:
# 1. PR opened/reopened
# 2. Manual trigger
# 3. Comment contains /run-cr
# Check if PR or if comment contains the trigger
if: |
github.event_name == 'pull_request' ||
github.event_name == 'workflow_dispatch' ||
(github.event.issue.pull_request && contains(github.event.comment.body, '/run-cr'))
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
issues: write
steps:
- name: Get PR Info
if: github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment'
id: pr_data
run: |
# Add --repo ${{ github.repository }} so gh knows where to look without a .git folder
PR_JSON=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName,baseRefName)
echo "head_ref=$(echo $PR_JSON | jq -r .headRefName)" >> $GITHUB_OUTPUT
echo "base_ref=$(echo $PR_JSON | jq -r .baseRefName)" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0
# Use the fetched head_ref if it's a comment, otherwise standard PR ref
ref: ${{ steps.pr_data.outputs.head_ref || github.event.pull_request.head.ref }}
# -------------------------
# ✅ CodeRabbit AI Reviewer
# -------------------------
- name: Run CodeRabbit AI Code Review
uses: coderabbitai/ai-pr-reviewer@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
debug: false
review_simple_changes: false
review_comment_lgtm: false
# -------------------------
# ✅ Gemini CR agent
# -------------------------
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: pip install google-generativeai
- name: Run CR Assistant
id: run_review
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }}
GITHUB_BASE_REF: ${{ steps.pr_data.outputs.base_ref || github.event.pull_request.base.ref }}
run: |
python scripts/review.py $PR_NUMBER > review_output.txt
- name: Comment on Pull Request
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('review_output.txt', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});