Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging in apply_patch() and text copy in pull_request_completed() #192

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions utils/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def apply_patch(original_text: str, diff_text: str) -> str:
subprocess.run(
args=["patch", "-u", "--fuzz=3", org_fname],
input=diff.read(),
text=True,
check=True,
text=True, # If True, input and output are strings
# capture_output=True, # Redundant so commented out
check=True, # If True, raise a CalledProcessError if the return code is non-zero
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
Expand All @@ -56,20 +57,23 @@ def apply_patch(original_text: str, diff_text: str) -> str:
cmd, code = " ".join(e.cmd), e.returncode

# Get the original, diff, and reject file contents for debugging
original_text_repr: str = repr(original_text).replace(" ", "·")
with open(file=org_fname, mode="r", encoding=UTF8, newline="") as modified_file:
modified_text: str = modified_file.read()
modified_text_repr: str = repr(modified_text).replace(" ", "·")
with open(file=diff_fname, mode="r", encoding=UTF8, newline="") as diff_file:
diff_text: str = diff_file.read()
diff_text_repr: str = repr(diff_text).replace(" ", "·")
rej_f_name: str = f"{org_fname}.rej"
reject_text = None
if os.path.exists(path=rej_f_name):
with open(file=rej_f_name, mode="r", encoding=UTF8, newline="") as rej_file:
reject_text = rej_file.read()
reject_text_repr: str = repr(reject_text).replace(" ", "·")

# Log the error and return an empty string not to break the flow
msg = f"Failed to apply patch. stdout: {stdout}\n\nDiff content: {diff_text}\n\nReject content: {reject_text}\n\nOriginal content: {original_text}"
msg = f"Failed to apply patch. stdout: {stdout}\n\nDiff content: {diff_text_repr}\n\nReject content: {reject_text_repr}\n\nOriginal content: {original_text_repr}\n\nModified content: {modified_text_repr}\n\nstderr: {stderr}\n\nCommand: {cmd}\n\nReturn code: {code}"
logging.error(msg=msg)
logging.info("stderr: %s\nCommand: %s\nReturn code: %s", stderr, cmd, code)
return modified_text

except Exception as e: # pylint: disable=broad-except
Expand Down
4 changes: 2 additions & 2 deletions utils/text_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def pull_request_completed(

# For user triggers
if not is_automation:
return f"{user_part}Pull request completed! Check it out here {pr_url} 🚀"
return f"{user_part}Pull request completed! Check it out here {pr_url} 🚀\nShould you have any questions or wish to change settings or limits, please feel free to contact {EMAIL_LINK} or invite us to Slack Connect."

# For automation triggers
return f"{user_part}Pull request completed! Check it out here {pr_url} 🚀\n\nNote: I automatically create a pull request for an unassigned and open issue in order from oldest to newest once a day at 00:00 UTC, as long as you have remaining automation usage. Should you have any questions or wish to change settings or limits, please feel free to contact {EMAIL_LINK}."
return f"{user_part}Pull request completed! Check it out here {pr_url} 🚀\n\nNote: I automatically create a pull request for an unassigned and open issue in order from oldest to newest once a day at 00:00 UTC, as long as you have remaining automation usage. Should you have any questions or wish to change settings or limits, please feel free to contact {EMAIL_LINK} or invite us to Slack Connect."


def request_issue_comment(requests_left: int, end_date: datetime.datetime):
Expand Down