@@ -156,20 +156,13 @@ async def fetch_files(client, owner, repo_name, pr_url, file_cursor):
156156import snoop
157157
158158
159- def sync_fork (upstream , fork , branch ):
160- try :
161- print (f"Successfully synced { fork } branch { branch } with { upstream } " )
162- except Exception as error :
163- raise Exception (
164- f"Unable to sync { fork } with { upstream } due to { error } "
165- ) from error
166-
167-
168159@snoop
169160def make_github_operations (
170161 token ,
171162 repo_urls ,
172163 new_branch_name ,
164+ make_commit_message ,
165+ make_pull_request_body ,
173166 transform_file_content ,
174167 fail_on_not_present : bool = True ,
175168):
@@ -183,6 +176,9 @@ def make_github_operations(
183176 repo = g .get_repo (f"{ org } /{ repo_name } " )
184177 fork = user .create_fork (repo )
185178
179+ commit_message = make_commit_message (repo , fork )
180+ pull_request_body = make_pull_request_body (repo , fork )
181+
186182 # Create a new branch from the default branch
187183 fork_default_branch = fork .get_branch (fork .default_branch )
188184 try :
@@ -216,7 +212,7 @@ def make_github_operations(
216212 except GithubException as error :
217213 msg = f"{ file_path } does not exist in { repo_url } "
218214 if fail_on_not_present :
219- raise Exception (f"{ msg } , unable to update. " ) from error
215+ raise Exception (f"{ msg } , unable to update" ) from error
220216 else :
221217 logger .info (msg )
222218
@@ -227,15 +223,15 @@ def make_github_operations(
227223 if old_content :
228224 fork .update_file (
229225 pygithub_fileobj .path ,
230- "Update testing.yml" ,
226+ commit_message ,
231227 content ,
232228 pygithub_fileobj .sha ,
233229 branch = new_branch_name ,
234230 )
235231 else :
236232 fork .create_file (
237233 pygithub_fileobj .path ,
238- "Update testing.yml" ,
234+ commit_message ,
239235 content ,
240236 branch = new_branch_name ,
241237 )
@@ -246,13 +242,16 @@ def make_github_operations(
246242 base = base_repo .default_branch
247243 head = f"{ user .login } :{ fork .name } :{ new_branch_name } "
248244 base_repo .create_pull (
249- title = "Update testing.yml" , body = "" , head = head , base = base
245+ title = commit_message ,
246+ body = pull_request_body ,
247+ head = head ,
248+ base = base ,
250249 )
251250
252- except GithubException as e :
253- print (
254- f"Unable to complete operations for { repo_url } due to { str ( e ) } "
255- )
251+ except GithubException as error :
252+ raise Exception (
253+ f"Unable to complete operations for { repo_url } due to { e } "
254+ ) from error
256255
257256
258257import pathlib
@@ -274,10 +273,16 @@ def make_github_operations(
274273
275274
276275async def main (repos , file_name ):
276+ commit_message = os .environ ["COMMIT_MESSAGE" ]
277+ pull_request_body = os .environ ["PULL_REQUEST_BODY" ]
277278 make_github_operations (
278279 token ,
279280 repo_urls ,
280281 new_branch_name ,
282+ lambda _upstream , fork : commit_message ,
283+ lambda _upstream , fork : pull_request_body .replace (
284+ "REPO_ORG/REPO_NAME" , fork .full_name
285+ ),
281286 lambda content : content .upper ()
282287 if content is not None
283288 else file_content ,
0 commit comments