Update review.yml #65
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PR Summary and Code Review | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
permissions: | |
contents: read | |
pull-requests: write | |
issues: write | |
jobs: | |
pr_summary: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout repository | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# Set up Python for PR summaries | |
- name: Set Up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
# Install Python dependencies | |
- name: Install Python Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests | |
# Run AI Analysis (PR Summary Only) | |
- name: Generate PR Summary | |
env: | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
GITHUB_TOKEN: ${{ secrets.G_TOKEN }} | |
run: | | |
python - <<EOF | |
import os | |
import requests | |
import json | |
# Gather GitHub event details | |
event_path = os.environ.get('GITHUB_EVENT_PATH') | |
with open(event_path, 'r') as f: | |
event = json.load(f) | |
# Extract PR and repo details | |
pr_number = event['pull_request']['number'] | |
repo_full_name = event['repository']['full_name'] | |
token = os.environ.get('GITHUB_TOKEN') | |
openai_key = os.environ.get('OPENAI_API_KEY') | |
# Get PR diff | |
headers = { | |
'Authorization': f'token {token}', | |
'Accept': 'application/vnd.github.v3.diff', | |
} | |
diff_url = event['pull_request']['url'] + "/files" | |
pr_files = requests.get(diff_url, headers=headers).json() | |
diff_text = "" | |
for fdata in pr_files: | |
filename = fdata['filename'] | |
patch = fdata.get('patch', '') | |
diff_text += f"File: {filename}\\nPatch:\\n{patch}\\n\\n" | |
# Generate PR summary using OpenAI | |
summary_prompt = f"Summarize the following pull request changes in a concise, technical manner:\\n\\n{diff_text}" | |
ai_headers = {"Content-Type": "application/json", "Authorization": f"Bearer {openai_key}"} | |
data_summary = { | |
"model": "gpt-4o-mini", | |
"messages": [{"role": "user", "content": summary_prompt}], | |
"temperature": 0.7 | |
} | |
summary_response = requests.post("https://api.openai.com/v1/chat/completions", headers=ai_headers, json=data_summary) | |
summary_response.raise_for_status() | |
summary = summary_response.json()['choices'][0]['message']['content'].strip() | |
# Post AI Pull Request Summary | |
comment_url = f"https://api.github.com/repos/{repo_full_name}/issues/{pr_number}/comments" | |
summary_comment = { | |
"body": f"**AI Pull Request Summary:**\\n{summary}" | |
} | |
summary_comment_response = requests.post(comment_url, headers={'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'}, json=summary_comment) | |
summary_comment_response.raise_for_status() | |
print("PR Summary posted successfully.") | |
EOF | |
code_review: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout repository | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
# Run GPT Code Reviewer (handles all code review tasks) | |
- name: Run GPT Code Reviewer | |
uses: PierreGode/GPTcode-reviewer@main | |
with: | |
GITHUB_TOKEN: ${{ secrets.G_TOKEN }} | |
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
OPENAI_API_MODEL: "gpt-4o-mini" | |
exclude: "**/*.json, **/*.md" |