mumrah commented on code in PR #19168:
URL: https://github.com/apache/kafka/pull/19168#discussion_r1988246558


##########
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", {})

Review Comment:
   To ensure we have an empty line between the body and trailers, let's trim 
the body and add a newline



##########
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
+

Review Comment:
   Let's print what the PR body will be here before the next prompt. E.g., 
   
   ```
   Pull Request (Ctrl+D or Ctrl+C to skip): 19144             
   
   New PR body will be:
   
   ---
   Adds a new ":clients:integration-test" Gradle module. Relocates one example 
test from ":core"
   
   Reviewers: Chia-Ping Tsai <[email protected]>
   ---
   
   Update the body of "KAFKA-18933 Add client integration tests module"? (y/n): 



##########
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'm not sure if it simplifies anything, but `gh pr edit` can take a file for 
the body. 



##########
committer-tools/reviewers.py:
##########
@@ -87,9 +126,11 @@ def prompt_for_user():
             continue
 
     if selected_reviewers:
-        out = "\n\nReviewers: "
-        out += ", ".join([f"{name} <{email}>" for name, email, _ in 
selected_reviewers])
-        out += "\n"
-        print(out)
-
+        reviewer_message = f'Reviewers: {", ".join([f"{name} <{email}>" for 
name, email, _ in selected_reviewers])}'

Review Comment:
   I'm not sure we need to build the reviewers message in a one-liner. I think 
the earlier code is a bit more readable. 



-- 
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]

Reply via email to