tsi-org/tango
0
1# Copyright 2023 The HuggingFace Team, the AllenNLP library authors. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""15Script to close stale issue. Taken in part from the AllenNLP repository.16https://github.com/allenai/allennlp.17"""18import os19from datetime import datetime as dt20 21from github import Github22 23 24LABELS_TO_EXEMPT = [25 "good first issue",26 "good second issue",27 "good difficult issue",28 "enhancement",29 "new pipeline/model",30 "new scheduler",31 "wip",32]33 34 35def main():36 g = Github(os.environ["GITHUB_TOKEN"])37 repo = g.get_repo("huggingface/diffusers")38 open_issues = repo.get_issues(state="open")39 40 for issue in open_issues:41 comments = sorted(issue.get_comments(), key=lambda i: i.created_at, reverse=True)42 last_comment = comments[0] if len(comments) > 0 else None43 if (44 last_comment is not None45 and last_comment.user.login == "github-actions[bot]"46 and (dt.utcnow() - issue.updated_at).days > 747 and (dt.utcnow() - issue.created_at).days >= 3048 and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())49 ):50 # Closes the issue after 7 days of inactivity since the Stalebot notification.51 issue.edit(state="closed")52 elif (53 "stale" in issue.get_labels()54 and last_comment is not None55 and last_comment.user.login != "github-actions[bot]"56 ):57 # Opens the issue if someone other than Stalebot commented.58 issue.edit(state="open")59 issue.remove_from_labels("stale")60 elif (61 (dt.utcnow() - issue.updated_at).days > 2362 and (dt.utcnow() - issue.created_at).days >= 3063 and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())64 ):65 # Post a Stalebot notification after 23 days of inactivity.66 issue.create_comment(67 "This issue has been automatically marked as stale because it has not had "68 "recent activity. If you think this still needs to be addressed "69 "please comment on this thread.\n\nPlease note that issues that do not follow the "70 "[contributing guidelines](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md) "71 "are likely to be ignored."72 )73 issue.add_to_labels("stale")74 75 76if __name__ == "__main__":77 main()78 