From 149a2c60fe283ee125adcf1fae2e45fab6aafeaf Mon Sep 17 00:00:00 2001 From: Lysandre Date: Tue, 10 Oct 2023 10:40:06 +0200 Subject: [PATCH] Fix stale bot for locked issues --- scripts/stale.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/stale.py b/scripts/stale.py index 81b608f1e2027d..c7fc6aa221a77b 100644 --- a/scripts/stale.py +++ b/scripts/stale.py @@ -18,6 +18,7 @@ from datetime import datetime as dt import os +import github.GithubException from github import Github @@ -36,8 +37,8 @@ def main(): repo = g.get_repo("huggingface/transformers") open_issues = repo.get_issues(state="open") - for issue in open_issues: - print(issue) + for i, issue in enumerate(open_issues): + print(i, issue) comments = sorted([comment for comment in issue.get_comments()], key=lambda i: i.created_at, reverse=True) last_comment = comments[0] if len(comments) > 0 else None if ( @@ -47,20 +48,26 @@ def main(): and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()) ): # print(f"Would close issue {issue.number} since it has been 7 days of inactivity since bot mention.") - issue.edit(state="closed") + try: + issue.edit(state="closed") + except github.GithubException as e: + print("Couldn't close the issue:", repr(e)) elif ( (dt.utcnow() - issue.updated_at.replace(tzinfo=None)).days > 23 and (dt.utcnow() - issue.created_at.replace(tzinfo=None)).days >= 30 and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()) ): # print(f"Would add stale comment to {issue.number}") - issue.create_comment( - "This issue has been automatically marked as stale because it has not had " - "recent activity. If you think this still needs to be addressed " - "please comment on this thread.\n\nPlease note that issues that do not follow the " - "[contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) " - "are likely to be ignored." - ) + try: + issue.create_comment( + "This issue has been automatically marked as stale because it has not had " + "recent activity. If you think this still needs to be addressed " + "please comment on this thread.\n\nPlease note that issues that do not follow the " + "[contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) " + "are likely to be ignored." + ) + except github.GithubException as e: + print("Couldn't create comment:", repr(e)) if __name__ == "__main__":