11import os
22import requests
33
4- def get_github_prs (token , owner , repo , label , state ):
4+ def get_github_prs (token , owner , repo , label = "" , state = "all" ):
55 """
66 Fetches pull requests from a GitHub repository that match a given milestone and label.
77
@@ -79,6 +79,25 @@ def get_github_prs(token, owner, repo, label, state):
7979
8080 return all_prs
8181
82+ def get_prs (pull_request_items , label = "" , state = "all" ):
83+ pr_list = []
84+ count = 0
85+ for pr in pull_request_items :
86+ if pr ["state" ] == state and [item for item in pr ["labels" ] if item ["name" ] == label ]:
87+ pr_list .append (pr )
88+ count += 1
89+
90+ print (f"Found { count } PRs with { label if label else "no" } label and state as { state } " )
91+
92+ return pr_list
93+
94+ def get_pr_descriptions (pull_request_items ):
95+ description_content = ""
96+ for pr in pull_request_items :
97+ description_content += f"- { pr ['title' ]} #{ pr ['number' ]} \n "
98+
99+ return description_content
100+
82101def update_pull_request_description (token , owner , repo , pr_number , new_description ):
83102 """
84103 Updates the description (body) of a GitHub Pull Request.
@@ -108,7 +127,6 @@ def update_pull_request_description(token, owner, repo, pr_number, new_descripti
108127
109128 print (f"Attempting to update PR #{ pr_number } in { owner } /{ repo } ..." )
110129 print (f"URL: { url } " )
111- # print(f"Payload: {payload}") # Uncomment for detailed payload debug
112130
113131 try :
114132 response = requests .patch (url , headers = headers , json = payload )
@@ -136,44 +154,41 @@ def update_pull_request_description(token, owner, repo, pr_number, new_descripti
136154 repository_owner = "flow-launcher"
137155 repository_name = "flow.launcher"
138156 target_label = "enhancement"
139- state = "closed "
157+ state = "all "
140158
141159 print (f"Fetching PRs for { repository_owner } /{ repository_name } with label '{ target_label } '..." )
142160
143161 pull_requests = get_github_prs (
144162 github_token ,
145163 repository_owner ,
146- repository_name ,
147- target_label ,
148- state
164+ repository_name
149165 )
150166
151167 if not pull_requests :
152168 print ("No matching pull requests found" )
153169 exit (1 )
154170
155- print (f"\n Found { len (pull_requests )} pull requests: " )
171+ print (f"\n Found total of { len (pull_requests )} pull requests" )
156172
157- description_content = ""
158- for pr in pull_requests :
159- description_content += f"- { pr ['title' ]} #{ pr ['number' ]} \n "
160-
161- returned_pr = pull_requests = get_github_prs (
162- github_token ,
163- repository_owner ,
164- repository_name ,
173+ release_pr = get_prs (
174+ pull_requests ,
165175 "release" ,
166176 "open"
167177 )
168178
169- if len (returned_pr ) != 1 :
170- print (f"Unable to find the exact release PR. Returned result: { returned_pr } " )
179+ if len (release_pr ) != 1 :
180+ print (f"Unable to find the exact release PR. Returned result: { release_pr } " )
171181 exit (1 )
172182
173- release_pr = returned_pr [0 ]
183+ print (f"Found release PR: { release_pr [0 ]['title' ]} " )
184+
185+ enhancement_prs = get_prs (pull_requests , "enhancement" , "closed" )
186+ bug_fix_prs = get_prs (pull_requests , "bug" , "closed" )
174187
175- print (f"Found release PR: { release_pr ['title' ]} " )
188+ description_content = "# Release notes\n "
189+ description_content += f"## Features\n { get_pr_descriptions (enhancement_prs )} " if enhancement_prs else ""
190+ description_content += f"## Bug fixes\n { get_pr_descriptions (bug_fix_prs )} " if bug_fix_prs else ""
176191
177- update_pull_request_description (github_token , repository_owner , repository_name , release_pr ["number" ], description_content )
192+ update_pull_request_description (github_token , repository_owner , repository_name , release_pr [0 ][ "number" ], description_content )
178193
179- print (description_content )
194+ print (f"PR content updated to: \n { description_content } " )
0 commit comments