1
1
import os
2
2
import requests
3
3
4
- def get_github_prs (token , owner , repo , label , state ):
4
+ def get_github_prs (token , owner , repo , label = "" , state = "all" ):
5
5
"""
6
6
Fetches pull requests from a GitHub repository that match a given milestone and label.
7
7
@@ -79,6 +79,25 @@ def get_github_prs(token, owner, repo, label, state):
79
79
80
80
return all_prs
81
81
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
+
82
101
def update_pull_request_description (token , owner , repo , pr_number , new_description ):
83
102
"""
84
103
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
108
127
109
128
print (f"Attempting to update PR #{ pr_number } in { owner } /{ repo } ..." )
110
129
print (f"URL: { url } " )
111
- # print(f"Payload: {payload}") # Uncomment for detailed payload debug
112
130
113
131
try :
114
132
response = requests .patch (url , headers = headers , json = payload )
@@ -136,44 +154,41 @@ def update_pull_request_description(token, owner, repo, pr_number, new_descripti
136
154
repository_owner = "flow-launcher"
137
155
repository_name = "flow.launcher"
138
156
target_label = "enhancement"
139
- state = "closed "
157
+ state = "all "
140
158
141
159
print (f"Fetching PRs for { repository_owner } /{ repository_name } with label '{ target_label } '..." )
142
160
143
161
pull_requests = get_github_prs (
144
162
github_token ,
145
163
repository_owner ,
146
- repository_name ,
147
- target_label ,
148
- state
164
+ repository_name
149
165
)
150
166
151
167
if not pull_requests :
152
168
print ("No matching pull requests found" )
153
169
exit (1 )
154
170
155
- print (f"\n Found { len (pull_requests )} pull requests: " )
171
+ print (f"\n Found total of { len (pull_requests )} pull requests" )
156
172
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 ,
165
175
"release" ,
166
176
"open"
167
177
)
168
178
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 } " )
171
181
exit (1 )
172
182
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" )
174
187
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 ""
176
191
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 )
178
193
179
- print (description_content )
194
+ print (f"PR content updated to: \n { description_content } " )
0 commit comments