mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 04:14:59 +00:00
refactor: extract issue handling into dedicated functions
This commit is contained in:
parent
e8c153f72f
commit
17351e8f91
1 changed files with 45 additions and 43 deletions
|
@ -130,53 +130,33 @@ def find_unlabeled_with_paul_comments(issues):
|
|||
return unlabeled_issues
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Handle duplicate GitHub issues")
|
||||
parser.add_argument(
|
||||
"--yes", action="store_true", help="Automatically close duplicates without prompting"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--find-unlabeled",
|
||||
action="store_true",
|
||||
help="Find unlabeled issues with paul-gauthier comments",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
def handle_unlabeled_issues(all_issues, auto_yes):
|
||||
print("\nFinding unlabeled issues with paul-gauthier comments...")
|
||||
unlabeled_issues = find_unlabeled_with_paul_comments(all_issues)
|
||||
|
||||
if not TOKEN:
|
||||
print("Error: Missing GITHUB_TOKEN environment variable. Please check your .env file.")
|
||||
if not unlabeled_issues:
|
||||
print("No unlabeled issues with paul-gauthier comments found.")
|
||||
return
|
||||
|
||||
all_issues = get_issues("all")
|
||||
print(f"\nFound {len(unlabeled_issues)} unlabeled issues with paul-gauthier comments:")
|
||||
for issue in unlabeled_issues:
|
||||
print(f" - #{issue['number']}: {issue['title']} {issue['html_url']}")
|
||||
|
||||
if args.find_unlabeled:
|
||||
#ai refactor this into a function...
|
||||
print("\nFinding unlabeled issues with paul-gauthier comments...")
|
||||
unlabeled_issues = find_unlabeled_with_paul_comments(all_issues)
|
||||
|
||||
if not unlabeled_issues:
|
||||
print("No unlabeled issues with paul-gauthier comments found.")
|
||||
if not auto_yes:
|
||||
confirm = input("\nDo you want to add the 'question' label to these issues? (y/n): ")
|
||||
if confirm.lower() != "y":
|
||||
print("Skipping labeling.")
|
||||
return
|
||||
|
||||
print(f"\nFound {len(unlabeled_issues)} unlabeled issues with paul-gauthier comments:")
|
||||
for issue in unlabeled_issues:
|
||||
print(f" - #{issue['number']}: {issue['title']} {issue['html_url']}")
|
||||
print("\nAdding 'question' label to issues...")
|
||||
for issue in unlabeled_issues:
|
||||
url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues/{issue['number']}"
|
||||
response = requests.patch(url, headers=headers, json={"labels": ["question"]})
|
||||
response.raise_for_status()
|
||||
print(f" - Added 'question' label to #{issue['number']}")
|
||||
|
||||
if not args.yes:
|
||||
confirm = input("\nDo you want to add the 'question' label to these issues? (y/n): ")
|
||||
if confirm.lower() != "y":
|
||||
print("Skipping labeling.")
|
||||
return
|
||||
|
||||
print("\nAdding 'question' label to issues...")
|
||||
for issue in unlabeled_issues:
|
||||
url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues/{issue['number']}"
|
||||
response = requests.patch(url, headers=headers, json={"labels": ["question"]})
|
||||
response.raise_for_status()
|
||||
print(f" - Added 'question' label to #{issue['number']}")
|
||||
return
|
||||
# ... to here
|
||||
|
||||
# ai also refactor this into its own function...
|
||||
def handle_duplicate_issues(all_issues, auto_yes):
|
||||
open_issues = [issue for issue in all_issues if issue["state"] == "open"]
|
||||
grouped_open_issues = group_issues_by_subject(open_issues)
|
||||
|
||||
|
@ -202,21 +182,43 @@ def main():
|
|||
f" {oldest_issue['html_url']} ({oldest_issue['state']})"
|
||||
)
|
||||
|
||||
if not args.yes:
|
||||
# Confirmation prompt
|
||||
if not auto_yes:
|
||||
confirm = input("Do you want to comment and close duplicate issues? (y/n): ")
|
||||
if confirm.lower() != "y":
|
||||
print("Skipping this group of issues.")
|
||||
continue
|
||||
|
||||
# Comment and close duplicate issues
|
||||
for issue in issues:
|
||||
if issue["number"] != oldest_issue["number"]:
|
||||
comment_and_close_duplicate(issue, oldest_issue)
|
||||
|
||||
if oldest_issue["state"] == "open":
|
||||
print(f"Oldest issue #{oldest_issue['number']} left open")
|
||||
# ai ... to here!
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Handle duplicate GitHub issues")
|
||||
parser.add_argument(
|
||||
"--yes", action="store_true", help="Automatically close duplicates without prompting"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--find-unlabeled",
|
||||
action="store_true",
|
||||
help="Find unlabeled issues with paul-gauthier comments",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not TOKEN:
|
||||
print("Error: Missing GITHUB_TOKEN environment variable. Please check your .env file.")
|
||||
return
|
||||
|
||||
all_issues = get_issues("all")
|
||||
|
||||
if args.find_unlabeled:
|
||||
handle_unlabeled_issues(all_issues, args.yes)
|
||||
return
|
||||
|
||||
handle_duplicate_issues(all_issues, args.yes)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue