44from datetime import datetime , timezone
55
66import requests
7+ import re
78import schedule
89from dotenv import load_dotenv
910
1213from github import (
1314 get_prs_waiting_for_review_by_reviewer ,
1415 get_prs_with_changes_requested_by_reviewer ,
16+ get_pr_diff ,
1517)
1618from linear .issues import (
1719 get_completed_issues ,
@@ -64,6 +66,28 @@ def get_slack_markdown_by_linear_username(username):
6466 return "No Assignee"
6567
6668
69+ def _get_pr_diffs (issue ):
70+ """Return a list of diffs for PRs linked in the issue attachments."""
71+ diffs = []
72+ for attachment in issue .get ("attachments" , {}).get ("nodes" , []):
73+ metadata = attachment .get ("metadata" , {})
74+ url = metadata .get ("url" )
75+ if not url :
76+ continue
77+ match = re .search (r"github.com/([^/]+)/([^/]+)/pull/(\d+)" , url )
78+ if not match :
79+ continue
80+ owner , repo , number = match .groups ()
81+ try :
82+ diff = get_pr_diff (owner , repo , int (number ))
83+ diffs .append (diff )
84+ except Exception as e : # pragma: no cover - network errors are ignored
85+ logging .error (
86+ "Failed to fetch diff for %s/%s#%s: %s" , owner , repo , number , e
87+ )
88+ return diffs
89+
90+
6791@with_retries
6892def post_priority_bugs ():
6993 config = load_config ()
@@ -371,13 +395,17 @@ def post_weekly_changelog():
371395 comments = " " .join (
372396 c .get ("body" , "" ) for c in issue .get ("comments" , {}).get ("nodes" , [])
373397 )
374- chunks .append (
375- f"ID: { issue ['id' ]} \n "
376- f"Title: { issue ['title' ]} \n "
377- f"Platform: { issue .get ('platform' , '' )} \n "
378- f"Description: { desc } \n "
379- f"Comments: { comments } "
380- )
398+ diffs = _get_pr_diffs (issue )
399+ chunk_parts = [
400+ f"ID: { issue ['id' ]} " ,
401+ f"Title: { issue ['title' ]} " ,
402+ f"Platform: { issue .get ('platform' , '' )} " ,
403+ f"Description: { desc } " ,
404+ f"Comments: { comments } " ,
405+ ]
406+ if diffs :
407+ chunk_parts .append ("Diff:\n " + "\n " .join (diffs ))
408+ chunks .append ("\n " .join (chunk_parts ))
381409
382410 instructions = (
383411 "Create a short customer-facing changelog from the provided issues. "
@@ -386,6 +414,7 @@ def post_weekly_changelog():
386414 "List each change as a short sentence with no markdown or bullet characters. "
387415 "Ignore technical tasks, internal changes, and unfinished work. "
388416 "Ensure each change appears only once in the changelog. "
417+ "When a chunk includes a 'Diff:' section, use that diff as additional context. "
389418 "Return a JSON object with keys 'New Features', 'Bug Fixes', and 'Improvements'. "
390419 "Each item should be an object with fields 'id' (the issue id)"
391420 "and 'summary' (the changelog text)."
0 commit comments