@@ -79,6 +79,53 @@ def get_github_prs(token, owner, repo, label, state):
79
79
80
80
return all_prs
81
81
82
+ def update_pull_request_description (token , owner , repo , pr_number , new_description ):
83
+ """
84
+ Updates the description (body) of a GitHub Pull Request.
85
+
86
+ Args:
87
+ token (str): Token.
88
+ owner (str): The owner of the repository.
89
+ repo (str): The name of the repository.
90
+ pr_number (int): The number of the pull request to update.
91
+ new_description (str): The new content for the PR's description.
92
+
93
+ Returns:
94
+ dict or None: The updated PR object (as a dictionary) if successful,
95
+ None otherwise.
96
+ """
97
+ headers = {
98
+ "Authorization" : f"token { token } " ,
99
+ "Accept" : "application/vnd.github.v3+json" ,
100
+ "Content-Type" : "application/json"
101
+ }
102
+
103
+ url = f"https://api.github.com/repos/{ owner } /{ repo } /pulls/{ pr_number } "
104
+
105
+ payload = {
106
+ "body" : new_description
107
+ }
108
+
109
+ print (f"Attempting to update PR #{ pr_number } in { owner } /{ repo } ..." )
110
+ print (f"URL: { url } " )
111
+ # print(f"Payload: {payload}") # Uncomment for detailed payload debug
112
+
113
+ try :
114
+ response = requests .patch (url , headers = headers , json = payload )
115
+ response .raise_for_status ()
116
+
117
+ updated_pr_data = response .json ()
118
+ print (f"Successfully updated PR #{ pr_number } ." )
119
+ return updated_pr_data
120
+
121
+ except requests .exceptions .RequestException as e :
122
+ print (f"Error updating pull request #{ pr_number } : { e } " )
123
+ if response is not None :
124
+ print (f"Response status code: { response .status_code } " )
125
+ print (f"Response text: { response .text } " )
126
+ return None
127
+
128
+
82
129
if __name__ == "__main__" :
83
130
github_token = os .environ .get ("GITHUB_TOKEN" )
84
131
@@ -92,7 +139,7 @@ def get_github_prs(token, owner, repo, label, state):
92
139
state = "closed"
93
140
94
141
print (f"Fetching PRs for { repository_owner } /{ repository_name } with label '{ target_label } '..." )
95
-
142
+
96
143
pull_requests = get_github_prs (
97
144
github_token ,
98
145
repository_owner ,
@@ -101,9 +148,32 @@ def get_github_prs(token, owner, repo, label, state):
101
148
state
102
149
)
103
150
104
- if pull_requests :
105
- print (f"\n Found { len (pull_requests )} pull requests:" )
106
- for pr in pull_requests :
107
- print (f"- { pr ['state' ]} #{ pr ['number' ]} : { pr ['title' ]} (URL: { pr ['html_url' ]} )" )
108
- else :
109
- print ("No matching pull requests found." )
151
+ if not pull_requests :
152
+ print ("No matching pull requests found" )
153
+ exit (1 )
154
+
155
+ print (f"\n Found { len (pull_requests )} pull requests:" )
156
+
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 ,
165
+ "release" ,
166
+ "open"
167
+ )
168
+
169
+ if len (returned_pr ) != 1 :
170
+ print (f"Unable to find the exact release PR. Returned result: { returned_pr } " )
171
+ exit (1 )
172
+
173
+ release_pr = returned_pr [0 ]
174
+
175
+ print (f"Found release PR: { release_pr ['title' ]} " )
176
+
177
+ update_pull_request_description (github_token , repository_owner , repository_name , release_pr ["number" ], description_content )
178
+
179
+ print (description_content )
0 commit comments