From 70994cfc5b318e0b0f4b5e5b5ecfff43af321ba2 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 4 Sep 2024 10:08:16 -0700 Subject: [PATCH] feat: add confirm parameter to report_github_issue function --- aider/commands.py | 4 ++-- aider/report.py | 43 ++++++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index 1afa67148..76640d0e7 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1136,12 +1136,12 @@ class Commands: self.io.tool_output(settings) def cmd_report(self, args): - "Report an problem by opening a GitHub Issue" + "Report a problem by opening a GitHub Issue" from aider.report import report_github_issue announcements = "\n".join(self.coder.get_announcements()) issue_text = f"User report:\n\n{args}\n\nAnnouncements:\n{announcements}" - report_github_issue(issue_text) + report_github_issue(issue_text, confirm=True) def expand_subdir(file_path): diff --git a/aider/report.py b/aider/report.py index c23e9909c..b8fd13aeb 100644 --- a/aider/report.py +++ b/aider/report.py @@ -34,13 +34,14 @@ def get_git_info(): return "Git information unavailable" -def report_github_issue(issue_text, title=None): +def report_github_issue(issue_text, title=None, confirm=True): """ Compose a URL to open a new GitHub issue with the given text prefilled, and attempt to launch it in the default web browser. :param issue_text: The text of the issue to file :param title: The title of the issue (optional) + :param confirm: Whether to ask for confirmation before opening the browser (default: True) :return: None """ version_info = f"Aider version: {__version__}\n" @@ -61,31 +62,35 @@ def report_github_issue(issue_text, title=None): params["title"] = title issue_url = f"{github_issues}?{urllib.parse.urlencode(params)}" - print(f"\n# {title}\n") - print(issue_text.strip()) - print() - print("Please consider reporting this bug to help improve aider!") - prompt = "Open a GitHub Issue pre-filled with the above error in your browser? (Y/n) " - confirmation = input(prompt).strip().lower() + if confirm: + print(f"\n# {title}\n") + print(issue_text.strip()) + print() + print("Please consider reporting this bug to help improve aider!") + prompt = "Open a GitHub Issue pre-filled with the above error in your browser? (Y/n) " + confirmation = input(prompt).strip().lower() - yes = not confirmation or confirmation.startswith("y") - if not yes: - return + yes = not confirmation or confirmation.startswith("y") + if not yes: + return - print("Attempting to open the issue URL in your default web browser...") + if confirm: + print("Attempting to open the issue URL in your default web browser...") try: if webbrowser.open(issue_url): - print("Browser window should be opened.") + if confirm: + print("Browser window should be opened.") except Exception: pass - print() - print() - print("You can also use this URL to file the GitHub Issue:") - print() - print(issue_url) - print() - print() + if confirm: + print() + print() + print("You can also use this URL to file the GitHub Issue:") + print() + print(issue_url) + print() + print() def exception_handler(exc_type, exc_value, exc_traceback):