transformers

Форк
0
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
"""
15
Script to close stale issue. Taken in part from the AllenNLP repository.
16
https://github.com/allenai/allennlp.
17
"""
18
import os
19
from datetime import datetime as dt
20

21
import github.GithubException
22
from github import Github
23

24

25
LABELS_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

35
def main():
36
    g = Github(os.environ["GITHUB_TOKEN"])
37
    repo = g.get_repo("huggingface/transformers")
38
    open_issues = repo.get_issues(state="open")
39

40
    for i, issue in enumerate(open_issues):
41
        print(i, issue)
42
        comments = sorted(list(issue.get_comments()), key=lambda i: i.created_at, reverse=True)
43
        last_comment = comments[0] if len(comments) > 0 else None
44
        if (
45
            last_comment is not None and last_comment.user.login == "github-actions[bot]"
46
            and (dt.utcnow() - issue.updated_at.replace(tzinfo=None)).days > 7
47
            and (dt.utcnow() - issue.created_at.replace(tzinfo=None)).days >= 30
48
            and 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.")
51
            try:
52
                issue.edit(state="closed")
53
            except github.GithubException as e:
54
                print("Couldn't close the issue:", repr(e))
55
        elif (
56
            (dt.utcnow() - issue.updated_at.replace(tzinfo=None)).days > 23
57
            and (dt.utcnow() - issue.created_at.replace(tzinfo=None)).days >= 30
58
            and 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}")
61
            try:
62
                issue.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
                )
69
            except github.GithubException as e:
70
                print("Couldn't create comment:", repr(e))
71

72

73
if __name__ == "__main__":
74
    main()
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.