mingyen066 commented on code in PR #19168:
URL: https://github.com/apache/kafka/pull/19168#discussion_r1988295503
##########
committer-tools/reviewers.py:
##########
@@ -35,6 +39,41 @@ def prompt_for_user():
return clean_input
+def update_trailers(body, trailer):
+ with tempfile.NamedTemporaryFile() as fp:
+ fp.write(body.encode())
+ fp.flush()
+ cmd = f"git interpret-trailers --if-exists replace --trailer
'{trailer}' {fp.name} "
+ p = subprocess.run(shlex.split(cmd), capture_output=True, text=True)
+ fp.close()
+
+ return p.stdout
+
+
+def append_message_to_pr_body(pr: int , message: str):
+ try:
+ pr_url = f"https://github.com/apache/kafka/pull/{pr}"
+ cmd_get_pr = shlex.split(f"gh pr view {pr_url} --json title,body")
+ result = subprocess.run(cmd_get_pr, capture_output=True, text=True,
check=True)
+ current_pr_body = json.loads(result.stdout).get("body", {})
+ pr_title = json.loads(result.stdout).get("title", {})
+ updated_pr_body = update_trailers(current_pr_body, message)
+ except subprocess.CalledProcessError as e:
+ print("Failed to retrieve PR body:", e.stderr)
+ return
+
+ choice = input(f'Update the body of "{pr_title}"? (y/n): ').strip().lower()
+ if choice in ['n', 'no']:
+ return
+
+ try:
+ cmd_edit_body = shlex.split(f"gh pr edit {pr_url} --body
{shlex.quote(updated_pr_body)}")
Review Comment:
I think no. but I let shlex.split run in subprocess to add a little bit
readability.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]