Skip to content

Commit

Permalink
feat: Add confirmation prompt and logic to comment and close duplicat…
Browse files Browse the repository at this point in the history
…e issues
  • Loading branch information
paul-gauthier committed Sep 20, 2024
1 parent 7dd0a0f commit c111e7a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions scripts/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ def find_oldest_issue(subject, all_issues):
return oldest_issue


def comment_and_close_duplicate(issue, oldest_issue):
comment_url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues/{issue['number']}/comments"
close_url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/issues/{issue['number']}"

comment_body = f"This looks like a duplicate of #{oldest_issue['number']}, so I'm going to close it so discussion can happen there. Please let me know if you think it's actually a distinct issue."

# Post comment
response = requests.post(comment_url, headers=headers, json={"body": comment_body})
response.raise_for_status()

# Close issue
response = requests.patch(close_url, headers=headers, json={"state": "closed"})
response.raise_for_status()

print(f" - Commented and closed issue #{issue['number']}")


def main():
if not TOKEN:
print("Error: Missing GITHUB_TOKEN environment variable. Please check your .env file.")
Expand Down Expand Up @@ -93,6 +110,19 @@ def main():
f" {oldest_issue['created_at']})"
)

# Confirmation prompt
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)

print(f"Oldest issue #{oldest_issue['number']} left open")


if __name__ == "__main__":
main()

0 comments on commit c111e7a

Please sign in to comment.