transformers
74 строки · 3.0 Кб
1# Copyright 2021 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 at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# 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 and
13# limitations under the License.
14"""
15Script to close stale issue. Taken in part from the AllenNLP repository.
16https://github.com/allenai/allennlp.
17"""
18import os
19from datetime import datetime as dt
20
21import github.GithubException
22from github import Github
23
24
25LABELS_TO_EXEMPT = [
26"good first issue",
27"good second issue",
28"good difficult issue",
29"feature request",
30"new model",
31"wip",
32]
33
34
35def main():
36g = Github(os.environ["GITHUB_TOKEN"])
37repo = g.get_repo("huggingface/transformers")
38open_issues = repo.get_issues(state="open")
39
40for i, issue in enumerate(open_issues):
41print(i, issue)
42comments = sorted(list(issue.get_comments()), key=lambda i: i.created_at, reverse=True)
43last_comment = comments[0] if len(comments) > 0 else None
44if (
45last_comment is not None and last_comment.user.login == "github-actions[bot]"
46and (dt.utcnow() - issue.updated_at.replace(tzinfo=None)).days > 7
47and (dt.utcnow() - issue.created_at.replace(tzinfo=None)).days >= 30
48and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
49):
50# print(f"Would close issue {issue.number} since it has been 7 days of inactivity since bot mention.")
51try:
52issue.edit(state="closed")
53except github.GithubException as e:
54print("Couldn't close the issue:", repr(e))
55elif (
56(dt.utcnow() - issue.updated_at.replace(tzinfo=None)).days > 23
57and (dt.utcnow() - issue.created_at.replace(tzinfo=None)).days >= 30
58and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
59):
60# print(f"Would add stale comment to {issue.number}")
61try:
62issue.create_comment(
63"This issue has been automatically marked as stale because it has not had "
64"recent activity. If you think this still needs to be addressed "
65"please comment on this thread.\n\nPlease note that issues that do not follow the "
66"[contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) "
67"are likely to be ignored."
68)
69except github.GithubException as e:
70print("Couldn't create comment:", repr(e))
71
72
73if __name__ == "__main__":
74main()
75