refactor: extract issue handling into dedicated functions

This commit is contained in:
Paul Gauthier (aider) 2024-11-05 07:02:24 -08:00
parent e8c153f72f
commit 17351e8f91

View file

@ -130,26 +130,7 @@ 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()
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:
#ai refactor this into a function...
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)
@ -161,7 +142,7 @@ def main():
for issue in unlabeled_issues:
print(f" - #{issue['number']}: {issue['title']} {issue['html_url']}")
if not args.yes:
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.")
@ -173,10 +154,9 @@ def main():
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__":