mumrah commented on code in PR #19168:
URL: https://github.com/apache/kafka/pull/19168#discussion_r1987435500
##########
committer-tools/reviewers.py:
##########
@@ -35,6 +37,30 @@ def prompt_for_user():
return clean_input
+def append_message_to_pr_body(pr_url, message):
Review Comment:
Let's have this method accept the PR number as an int.
Can we use the type hints here as well?
##########
committer-tools/reviewers.py:
##########
@@ -87,9 +113,12 @@ 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'\n\nReviewers: {", ".join([f"{name} <{email}>"
for name, email, _ in selected_reviewers])}\n'
+ print(reviewer_message)
+ try:
+ pr_number = input("\nEnter the Pull Request number to append
reviewer message to body (Ctrl+D or Ctrl+C to skip): ")
Review Comment:
This prompt is a bit long. How about "Pull Request (Ctrl+D or Ctrl+C to
skip):" ?
##########
committer-tools/reviewers.py:
##########
@@ -35,6 +37,30 @@ def prompt_for_user():
return clean_input
+def append_message_to_pr_body(pr_url, message):
+ try:
+ cmd_get_pr = ["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", {})
+ escaped_message = message.replace("<", "\\<").replace(">", "\\>")
Review Comment:
If a PR already has "Reviewers" we need to parse that here so we can replace
it. I can think of two ways we can do this
1) Parse the body with Python. Find a line at the end of the body starting
with "Reviewers" and replace it.
2) Use `git interpret-trailers` to parse and even update the message (see
https://github.com/apache/kafka/blob/trunk/.github/scripts/pr-format.py#L54 for
example)
Also, we should not escape the brackets around the email. It indeed renders
a bit funny in the PR, but when auto-filling the commit message, it appears as
it should.
##########
committer-tools/reviewers.py:
##########
@@ -35,6 +37,30 @@ def prompt_for_user():
return clean_input
+def append_message_to_pr_body(pr_url, message):
+ try:
+ cmd_get_pr = ["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", {})
+ escaped_message = message.replace("<", "\\<").replace(">", "\\>")
+ updated_pr_body = f"{current_pr_body}{escaped_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 = ["gh", "pr", "edit", pr_url, "--body", updated_pr_body]
Review Comment:
See `shlex` comment above
##########
committer-tools/reviewers.py:
##########
@@ -35,6 +37,30 @@ def prompt_for_user():
return clean_input
+def append_message_to_pr_body(pr_url, message):
+ try:
+ cmd_get_pr = ["gh", "pr", "view", pr_url, "--json", "title,body"]
Review Comment:
You can use shlex to make this a bit more readable.
```python
shlex.split(f"gh pr view {pr} --json title,body")
```
--
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]