Debian Codegraph @

utils/stale.py

raw
1 # Copyright 2022 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
19 import os
20 from datetime import datetime as dt
21 from datetime import timezone
22
23 from github import Github
24
25
26 LABELS_TO_EXEMPT = [
27 "good first issue",
28 "feature request",
29 "wip",
30 ]
31
32
33 def main():
34 g = Github(os.environ["GITHUB_TOKEN"])
35 repo = g.get_repo("huggingface/accelerate")
36 open_issues = repo.get_issues(state="open")
37
38 for issue in open_issues:
39 comments = sorted([comment for comment in issue.get_comments()], key=lambda i: i.created_at, reverse=True)
40 last_comment = comments[0] if len(comments) > 0 else None
41 current_time = dt.now(timezone.utc)
42 days_since_updated = (current_time - issue.updated_at).days
43 days_since_creation = (current_time - issue.created_at).days
44 if (
45 last_comment is not None
46 and last_comment.user.login == "github-actions[bot]"
47 and days_since_updated > 7
48 and days_since_creation >= 30
49 and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
50 ):
51 # Close issue since it has been 7 days of inactivity since bot mention.
52 issue.edit(state="closed")
53 elif (
54 days_since_updated > 23
55 and days_since_creation >= 30
56 and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
57 ):
58 # Add stale comment
59 issue.create_comment(
60 "This issue has been automatically marked as stale because it has not had "
61 "recent activity. If you think this still needs to be addressed "
62 "please comment on this thread.\n\nPlease note that issues that do not follow the "
63 "[contributing guidelines](https://github.com/huggingface/accelerate/blob/main/CONTRIBUTING.md) "
64 "are likely to be ignored."
65 )
66
67
68 if __name__ == "__main__":
69 main()