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)
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):

View file

@ -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):