feat: add confirm parameter to report_github_issue function

This commit is contained in:
Paul Gauthier (aider) 2024-09-04 10:08:16 -07:00
parent c5ac621da1
commit 70994cfc5b
2 changed files with 26 additions and 21 deletions

View file

@ -1136,12 +1136,12 @@ class Commands:
self.io.tool_output(settings) self.io.tool_output(settings)
def cmd_report(self, args): 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 from aider.report import report_github_issue
announcements = "\n".join(self.coder.get_announcements()) announcements = "\n".join(self.coder.get_announcements())
issue_text = f"User report:\n\n{args}\n\nAnnouncements:\n{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): def expand_subdir(file_path):

View file

@ -34,13 +34,14 @@ def get_git_info():
return "Git information unavailable" 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, Compose a URL to open a new GitHub issue with the given text prefilled,
and attempt to launch it in the default web browser. and attempt to launch it in the default web browser.
:param issue_text: The text of the issue to file :param issue_text: The text of the issue to file
:param title: The title of the issue (optional) :param title: The title of the issue (optional)
:param confirm: Whether to ask for confirmation before opening the browser (default: True)
:return: None :return: None
""" """
version_info = f"Aider version: {__version__}\n" version_info = f"Aider version: {__version__}\n"
@ -61,31 +62,35 @@ def report_github_issue(issue_text, title=None):
params["title"] = title params["title"] = title
issue_url = f"{github_issues}?{urllib.parse.urlencode(params)}" issue_url = f"{github_issues}?{urllib.parse.urlencode(params)}"
print(f"\n# {title}\n") if confirm:
print(issue_text.strip()) print(f"\n# {title}\n")
print() print(issue_text.strip())
print("Please consider reporting this bug to help improve aider!") print()
prompt = "Open a GitHub Issue pre-filled with the above error in your browser? (Y/n) " print("Please consider reporting this bug to help improve aider!")
confirmation = input(prompt).strip().lower() 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") yes = not confirmation or confirmation.startswith("y")
if not yes: if not yes:
return 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: try:
if webbrowser.open(issue_url): if webbrowser.open(issue_url):
print("Browser window should be opened.") if confirm:
print("Browser window should be opened.")
except Exception: except Exception:
pass pass
print() if confirm:
print() print()
print("You can also use this URL to file the GitHub Issue:") print()
print() print("You can also use this URL to file the GitHub Issue:")
print(issue_url) print()
print() print(issue_url)
print() print()
print()
def exception_handler(exc_type, exc_value, exc_traceback): def exception_handler(exc_type, exc_value, exc_traceback):