1- name : PR Summary and Code Review
1+ name : PR summary by AI
22
33on :
44 pull_request :
@@ -14,47 +14,49 @@ permissions:
1414
1515jobs :
1616 pr_summary :
17+ name : PR Summary
1718 runs-on : ubuntu-latest
1819 steps :
19- # Checkout repository
2020 - name : Checkout Code
2121 uses : actions/checkout@v3
2222
23- # Set up Python for PR summaries
23+ - name : Read README.md
24+ id : read_readme
25+ run : |
26+ README_CONTENT=$(cat README.md)
27+ echo "::set-output name=README::$README_CONTENT"
28+
2429 - name : Set Up Python
2530 uses : actions/setup-python@v4
2631 with :
2732 python-version : ' 3.9'
2833
29- # Install Python dependencies
3034 - name : Install Python Dependencies
3135 run : |
3236 python -m pip install --upgrade pip
3337 pip install requests
3438
35- # Run AI Analysis (PR Summary Only)
36- - name : Generate PR Summary
39+ - name : PR Summary
3740 env :
3841 OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
3942 GITHUB_TOKEN : ${{ secrets.G_TOKEN }}
43+ README_CONTENT : ${{ steps.read_readme.outputs.README }}
4044 run : |
4145 python - <<EOF
4246 import os
4347 import requests
4448 import json
4549
46- # Gather GitHub event details
4750 event_path = os.environ.get('GITHUB_EVENT_PATH')
4851 with open(event_path, 'r') as f:
4952 event = json.load(f)
5053
51- # Extract PR and repo details
5254 pr_number = event['pull_request']['number']
5355 repo_full_name = event['repository']['full_name']
5456 token = os.environ.get('GITHUB_TOKEN')
5557 openai_key = os.environ.get('OPENAI_API_KEY')
58+ readme_content = os.environ.get('README_CONTENT')
5659
57- # Get PR diff
5860 headers = {
5961 'Authorization': f'token {token}',
6062 'Accept': 'application/vnd.github.v3.diff',
@@ -65,11 +67,29 @@ jobs:
6567 diff_text = ""
6668 for fdata in pr_files:
6769 filename = fdata['filename']
68- patch = fdata.get('patch', '')
69- diff_text += f"File: {filename}\\nPatch:\\n{patch}\\n\\n"
70+ patch = fdata.get('patch', 'No changes')
71+ diff_text += f"File: {filename}\nPatch:\n"
72+ for line in patch.split('\n'):
73+ if line.startswith('+'):
74+ diff_text += f"Added: {line[1:]}\n"
75+ elif line.startswith('-'):
76+ diff_text += f"Removed: {line[1:]}\n"
77+ else:
78+ diff_text += f"{line}\n"
79+
80+ summary_prompt = (
81+ f"Based on the following README, provide a comprehensive analysis of the pull request. \n\n"
82+ f"**README Content:**\n{readme_content}\n\n"
83+ f"**Pull Request Diff:**\n{diff_text}\n\n"
84+ f"Please include the following in your summary:\n"
85+ f"- Key files and components modified.\n"
86+ f"- Main purpose of the changes (e.g., bug fixes, feature additions, optimizations).\n"
87+ f"- Specific functionalities introduced, modified, or removed.\n"
88+ f" - Highlight lines added (marked with 'Added:') and lines removed (marked with 'Removed:').\n"
89+ f"- Any potential implications or considerations (e.g., performance impacts, breaking changes, dependencies).\n"
90+ f"Ensure the summary clearly states which version contains corrections or bug fixes."
91+ )
7092
71- # Generate PR summary using OpenAI
72- summary_prompt = f"Summarize the following pull request changes in a concise, technical manner:\\n\\n{diff_text}"
7393 ai_headers = {"Content-Type": "application/json", "Authorization": f"Bearer {openai_key}"}
7494 data_summary = {
7595 "model": "gpt-4o-mini",
@@ -80,29 +100,34 @@ jobs:
80100 summary_response.raise_for_status()
81101 summary = summary_response.json()['choices'][0]['message']['content'].strip()
82102
83- # Post AI Pull Request Summary
84103 comment_url = f"https://api.github.com/repos/{repo_full_name}/issues/{pr_number}/comments"
85104 summary_comment = {
86- "body": f"**AI Pull Request Summary:**\\ n{summary}"
105+ "body": f"**AI Pull Request Summary:**\n{summary}"
87106 }
88- summary_comment_response = requests.post(comment_url, headers={'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'}, json=summary_comment)
89- summary_comment_response.raise_for_status()
107+ requests.post(comment_url, headers={'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'}, json=summary_comment)
90108
91109 print("PR Summary posted successfully.")
92110 EOF
93111
94112 code_review :
113+ name : AI Code Review
95114 runs-on : ubuntu-latest
96115 steps :
97- # Checkout repository
98116 - name : Checkout Repository
99117 uses : actions/checkout@v4
100118
101- # Run GPT Code Reviewer (handles all code review tasks)
102- - name : Run GPT Code Reviewer
119+ - name : Read README.md
120+ id : read_readme_review
121+ run : |
122+ README_CONTENT=$(cat README.md)
123+ echo "::set-output name=README::$README_CONTENT"
124+
125+ - name : AI Code Review
103126 uses : PierreGode/GPTcode-reviewer@main
104127 with :
105128 GITHUB_TOKEN : ${{ secrets.G_TOKEN }}
106129 OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
107130 OPENAI_API_MODEL : " gpt-4o-mini"
108- exclude : " **/*.json, **/*.md"
131+ exclude : " **/*.json,**/*.md"
132+ # Assuming the action allows passing additional context, include README
133+ additional_context : ${{ steps.read_readme_review.outputs.README }}
0 commit comments