Skip to content

Commit 4c8f451

Browse files
committed
invoke update-changelog now uses ChatGPT to summarize PRs.
1 parent 3d95879 commit 4c8f451

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

docs/CHANGES.md

Lines changed: 16 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tasks.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def update_changelog(ctx: Context, version: str | None = None, dry_run: bool = F
151151
updating the actual change log file. Defaults to False.
152152
"""
153153
version = version or f"{datetime.now(tz=timezone.utc):%Y.%-m.%-d}"
154+
__version__ = "2025.1.9"
154155
print(f"Getting all comments since {__version__}")
155156
output = subprocess.check_output(["git", "log", "--pretty=format:%s", f"v{__version__}..HEAD"])
156157
lines = []
@@ -174,11 +175,29 @@ def update_changelog(ctx: Context, version: str | None = None, dry_run: bool = F
174175
lines += [f" {ll}"]
175176
else:
176177
ignored_commits += [line]
178+
179+
body = "\n".join(lines)
180+
try:
181+
# Use OpenAI to improve changelog. Requires openai to be installed and an OPENAPI_KEY env variable.
182+
from openai import OpenAI
183+
184+
client = OpenAI(api_key=os.environ["OPENAPI_KEY"])
185+
186+
messages = [{"role": "user", "content": f"summarize, include authors: '{body}'"}]
187+
chat = client.chat.completions.create(model="gpt-4o", messages=messages)
188+
189+
reply = chat.choices[0].message.content
190+
body = "\n".join(reply.split("\n")[1:])
191+
body = body.strip()
192+
print(f"ChatGPT Summary of Changes:\n{body}")
193+
194+
except BaseException as ex:
195+
print(f"Unable to use openai due to {ex}")
177196
with open("docs/CHANGES.md", encoding="utf-8") as file:
178197
contents = file.read()
179198
delim = "##"
180199
tokens = contents.split(delim)
181-
tokens.insert(1, f"## v{version}\n\n" + "\n".join(lines) + "\n")
200+
tokens.insert(1, f"## v{version}\n\n{body}\n\n")
182201
if dry_run:
183202
print(tokens[0] + "##".join(tokens[1:]))
184203
else:

0 commit comments

Comments
 (0)