Skip to content

Commit 2603cad

Browse files
add stale bot (#925)
1 parent 8a45bfa commit 2603cad

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.github/stale.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Stale Bot
2+
3+
on:
4+
schedule:
5+
- cron: "0 15 * * *"
6+
7+
jobs:
8+
close_stale_issues:
9+
name: Close Stale Issues
10+
if: github.repository == 'TimDettmers/bitsandbytes'
11+
runs-on: ubuntu-latest
12+
env:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Setup Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: 3.8
21+
22+
- name: Install requirements
23+
run: |
24+
pip install PyGithub
25+
- name: Close stale issues
26+
run: |
27+
python scripts/stale.py

scripts/stale.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 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+
from datetime import timezone
21+
22+
from github import Github
23+
24+
25+
# All labels that we don't want to touch
26+
LABELS_TO_EXEMPT = [
27+
"feature-request",
28+
]
29+
30+
31+
def main():
32+
g = Github(os.environ["GITHUB_TOKEN"])
33+
repo = g.get_repo("TimDettmers/bitsandbytes")
34+
open_issues = repo.get_issues(state="open")
35+
36+
for issue in open_issues:
37+
comments = sorted([comment for comment in issue.get_comments()], key=lambda i: i.created_at, reverse=True)
38+
last_comment = comments[0] if len(comments) > 0 else None
39+
if (
40+
last_comment is not None
41+
and last_comment.user.login == "github-actions[bot]"
42+
and (dt.now(timezone.utc) - issue.updated_at).days > 7
43+
and (dt.now(timezone.utc) - issue.created_at).days >= 30
44+
and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
45+
):
46+
issue.edit(state="closed")
47+
elif (
48+
(dt.now(timezone.utc) - issue.updated_at).days > 23
49+
and (dt.now(timezone.utc) - issue.created_at).days >= 30
50+
and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels())
51+
):
52+
issue.create_comment(
53+
"This issue has been automatically marked as stale because it has not had "
54+
"recent activity. If you think this still needs to be addressed "
55+
"please comment on this thread.\n\n"
56+
)
57+
58+
59+
if __name__ == "__main__":
60+
main()

0 commit comments

Comments
 (0)