1
- name : PR Summary and Code Review
1
+ name : PR summary by AI
2
2
3
3
on :
4
4
pull_request :
@@ -14,47 +14,49 @@ permissions:
14
14
15
15
jobs :
16
16
pr_summary :
17
+ name : PR Summary
17
18
runs-on : ubuntu-latest
18
19
steps :
19
- # Checkout repository
20
20
- name : Checkout Code
21
21
uses : actions/checkout@v3
22
22
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
+
24
29
- name : Set Up Python
25
30
uses : actions/setup-python@v4
26
31
with :
27
32
python-version : ' 3.9'
28
33
29
- # Install Python dependencies
30
34
- name : Install Python Dependencies
31
35
run : |
32
36
python -m pip install --upgrade pip
33
37
pip install requests
34
38
35
- # Run AI Analysis (PR Summary Only)
36
- - name : Generate PR Summary
39
+ - name : PR Summary
37
40
env :
38
41
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
39
42
GITHUB_TOKEN : ${{ secrets.G_TOKEN }}
43
+ README_CONTENT : ${{ steps.read_readme.outputs.README }}
40
44
run : |
41
45
python - <<EOF
42
46
import os
43
47
import requests
44
48
import json
45
49
46
- # Gather GitHub event details
47
50
event_path = os.environ.get('GITHUB_EVENT_PATH')
48
51
with open(event_path, 'r') as f:
49
52
event = json.load(f)
50
53
51
- # Extract PR and repo details
52
54
pr_number = event['pull_request']['number']
53
55
repo_full_name = event['repository']['full_name']
54
56
token = os.environ.get('GITHUB_TOKEN')
55
57
openai_key = os.environ.get('OPENAI_API_KEY')
58
+ readme_content = os.environ.get('README_CONTENT')
56
59
57
- # Get PR diff
58
60
headers = {
59
61
'Authorization': f'token {token}',
60
62
'Accept': 'application/vnd.github.v3.diff',
@@ -65,11 +67,29 @@ jobs:
65
67
diff_text = ""
66
68
for fdata in pr_files:
67
69
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
+ )
70
92
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}"
73
93
ai_headers = {"Content-Type": "application/json", "Authorization": f"Bearer {openai_key}"}
74
94
data_summary = {
75
95
"model": "gpt-4o-mini",
@@ -80,29 +100,34 @@ jobs:
80
100
summary_response.raise_for_status()
81
101
summary = summary_response.json()['choices'][0]['message']['content'].strip()
82
102
83
- # Post AI Pull Request Summary
84
103
comment_url = f"https://api.github.com/repos/{repo_full_name}/issues/{pr_number}/comments"
85
104
summary_comment = {
86
- "body": f"**AI Pull Request Summary:**\\ n{summary}"
105
+ "body": f"**AI Pull Request Summary:**\n{summary}"
87
106
}
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)
90
108
91
109
print("PR Summary posted successfully.")
92
110
EOF
93
111
94
112
code_review :
113
+ name : AI Code Review
95
114
runs-on : ubuntu-latest
96
115
steps :
97
- # Checkout repository
98
116
- name : Checkout Repository
99
117
uses : actions/checkout@v4
100
118
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
103
126
uses : PierreGode/GPTcode-reviewer@main
104
127
with :
105
128
GITHUB_TOKEN : ${{ secrets.G_TOKEN }}
106
129
OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
107
130
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