Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 144cc4b

Browse files
committed
feature: git: github api: Enable create or update logic from title, body, and transform callbacks
Signed-off-by: John Andersen <[email protected]>
1 parent f158f05 commit 144cc4b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

feature/git/dffml_feature_git/github_api.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ def make_github_operations(
198198
logger.error(error)
199199
continue
200200

201-
commit_message = make_commit_message(repo, fork)
202-
pull_request_body = make_pull_request_body(repo, fork)
203-
204201
try:
205202
fork.create_git_ref(
206203
ref="refs/heads/" + new_branch_name,
@@ -236,8 +233,11 @@ def make_github_operations(
236233
else:
237234
logger.info(msg)
238235

236+
commit_message = make_commit_message(repo, fork, old_content)
237+
pull_request_body = make_pull_request_body(repo, fork, old_content)
238+
239239
# Transform the content
240-
content = transform_file_content(old_content)
240+
content = transform_file_content(repo, fork, old_content)
241241

242242
# Update file content
243243
if old_content:
@@ -298,7 +298,7 @@ def make_github_operations(
298298
"workflows",
299299
"pin_downstream.yml",
300300
)
301-
.read_text()
301+
.read_bytes()
302302
)
303303

304304

@@ -309,13 +309,19 @@ async def main(repos, file_name):
309309
token,
310310
repo_urls,
311311
new_branch_name,
312-
lambda _upstream, fork: commit_message,
313-
lambda _upstream, fork: pull_request_body.replace(
314-
"REPO_ORG/REPO_NAME", fork.full_name
312+
lambda _upstream, _fork, _old_content: commit_message,
313+
lambda _upstream, fork, _old_content: pull_request_body.replace(
314+
"REPO_ORG/REPO_NAME",
315+
fork.full_name,
316+
),
317+
lambda upstream, _fork, old_content: (
318+
old_content if old_content is not None else file_content
319+
)
320+
.decode()
321+
.replace(
322+
"- master",
323+
f"- {upstream.default_branch}",
315324
),
316-
lambda content: content.upper()
317-
if content is not None
318-
else file_content,
319325
fail_on_not_present=False,
320326
)
321327
return

0 commit comments

Comments
 (0)