Skip to content

Commit cbcea22

Browse files
committed
feat: add script to generate PR summaries from git diffs
Reads a diff from stdin and uses the OpenAI Responses API to output a structured markdown PR description using a fixed system prompt.
1 parent 5d28d49 commit cbcea22

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

ai_git_helpers/pr_summary.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
from openai import OpenAI
6+
7+
MODEL = "gpt-5.2"
8+
9+
SYSTEM_PROMPT = """
10+
You are helping maintain the R package RcppAlgos. You are an expert C++
11+
developer, algorithm designer, and understand the R and CRAN ecosystem deeply.
12+
13+
Your task is to generate a professional GitHub Pull Request summary from a git diff.
14+
15+
CRITICAL REQUIREMENTS:
16+
17+
• This summary will be used as the PR description.
18+
• Focus on WHAT changed and WHY.
19+
• Be accurate and specific.
20+
• Do NOT invent behavior not supported by the diff.
21+
• If intent is inferred, state it as inference.
22+
23+
• Highlight important technical implications:
24+
- correctness
25+
- edge cases
26+
- performance
27+
- memory safety
28+
- API or behavioral changes
29+
30+
• Call out anything reviewers should pay special attention to.
31+
32+
• Prefer clarity over verbosity.
33+
• Do NOT include code blocks.
34+
• Do NOT include raw diff content.
35+
• Do NOT mention file paths unless absolutely necessary for clarity.
36+
37+
Use the following structure exactly:
38+
39+
## Summary
40+
41+
High-level explanation of the change and its purpose.
42+
43+
## Key Changes
44+
45+
• Bullet list of concrete technical changes
46+
47+
## Motivation
48+
49+
Identify the PRIMARY motivation that drove this PR.
50+
51+
Pay special attention to new combinatorial algorithms and treat them as
52+
likely primary motivations.
53+
54+
This should reflect the original idea or feature that initiated the work,
55+
not secondary refactors or improvements discovered along the way.
56+
57+
Then include a subsection:
58+
59+
### Secondary Improvements
60+
61+
List improvements that were discovered opportunistically while implementing
62+
the primary change.
63+
64+
Be careful to distinguish clearly between:
65+
66+
• the original driving idea
67+
• incidental fixes, refactors, or optimizations
68+
69+
If uncertain, infer carefully from the diff and state that it is inferred.
70+
71+
## Impact
72+
73+
Describe any impact on:
74+
75+
• User-facing behavior
76+
• Performance
77+
• Correctness
78+
• Backwards compatibility
79+
80+
If none, state "No user-visible impact expected."
81+
82+
## Reviewer Notes
83+
84+
Call out:
85+
86+
• Risky areas
87+
• Edge cases
88+
• Logic changes
89+
• Performance-sensitive code
90+
• CRAN / R API considerations if applicable
91+
92+
Be professional and concise.
93+
94+
Output markdown only.
95+
"""
96+
97+
def main():
98+
99+
diff = sys.stdin.read().strip()
100+
101+
if not diff:
102+
print("No diff provided.", file=sys.stderr)
103+
sys.exit(1)
104+
105+
api_key = os.getenv("RCPPALGOS_OPENAI_KEY")
106+
client = OpenAI(api_key=api_key)
107+
108+
resp = client.responses.create(
109+
model=MODEL,
110+
input=[
111+
{"role": "system", "content": SYSTEM_PROMPT},
112+
{"role": "user", "content": diff},
113+
],
114+
max_output_tokens=4000,
115+
)
116+
117+
print(resp.output_text.strip())
118+
119+
120+
if __name__ == "__main__":
121+
main()

0 commit comments

Comments
 (0)