Skip to content

Commit 0c97dbf

Browse files
committed
run forreal (fingers crossed)
1 parent 5b1103d commit 0c97dbf

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import requests
3-
from datetime import datetime, timedelta
3+
from datetime import datetime
44

55
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
66
REPO = os.environ['GITHUB_REPOSITORY']
@@ -10,8 +10,11 @@
1010
"Accept": "application/vnd.github.v3+json"
1111
}
1212

13-
STALE_LABEL = "Stale"
13+
STALE_LABEL = "stale"
1414
STALE_COMMENT = "This discussion has been marked as stale due to inactivity for 90 days. If there is no further activity, it will be closed in 14 days."
15+
TIME_TIL_STALE = 90 # days
16+
TIME_TIL_CLOSE = 14 # days
17+
1518

1619
def get_discussions():
1720
discussions = []
@@ -27,52 +30,58 @@ def get_discussions():
2730
page += 1
2831
return discussions
2932

33+
3034
def get_comments(discussion_number):
3135
url = f"{API_URL}/{discussion_number}/comments"
3236
resp = requests.get(url, headers=HEADERS)
3337
if resp.status_code != 200:
3438
return []
3539
return resp.json()
3640

41+
3742
def add_label(discussion_number, label):
3843
print(f"Adding label '{label}' to discussion #{discussion_number}")
39-
# url = f"{API_URL}/{discussion_number}/labels"
40-
# requests.post(url, headers=HEADERS, json={"labels": [label]})
44+
url = f"{API_URL}/{discussion_number}/labels"
45+
requests.post(url, headers=HEADERS, json={"labels": [label]})
46+
4147

4248
def post_comment(discussion_number, body):
4349
print(f"Posting comment to discussion #{discussion_number}")
44-
# url = f"{API_URL}/{discussion_number}/comments"
45-
# requests.post(url, headers=HEADERS, json={"body": body})
50+
url = f"{API_URL}/{discussion_number}/comments"
51+
requests.post(url, headers=HEADERS, json={"body": body})
52+
4653

4754
def close_and_lock(discussion_number):
4855
print(f"Closing and locking discussion #{discussion_number}")
49-
# url = f"{API_URL}/{discussion_number}"
50-
# requests.patch(url, headers=HEADERS, json={"state": "closed", "locked": True})
56+
url = f"{API_URL}/{discussion_number}"
57+
requests.patch(url, headers=HEADERS, json={"state": "closed", "locked": True})
58+
5159

5260
def main():
53-
now = datetime.utcnow()
61+
now = datetime.datetime.now(datetime.UTC)
5462
discussions = get_discussions()
5563
for d in discussions:
5664
number = d['number']
57-
labels = [l['name'] for l in d.get('labels', [])]
65+
labels = [label['name'] for label in d.get('labels', [])]
5866
last_updated = datetime.strptime(d['updated_at'], "%Y-%m-%dT%H:%M:%SZ")
5967
comments = get_comments(number)
6068
stale_comment = next((c for c in comments if STALE_COMMENT in c['body']), None)
6169

6270
# Mark as stale after 90 days
63-
if (now - last_updated).days >= 90 and STALE_LABEL not in labels:
71+
if (now - last_updated).days >= TIME_TIL_STALE and STALE_LABEL not in labels:
6472
add_label(number, STALE_LABEL)
6573
post_comment(number, STALE_COMMENT)
6674
continue
6775

6876
# Close and lock after 14 days of being stale
6977
if STALE_LABEL in labels and stale_comment:
7078
stale_time = datetime.strptime(stale_comment['created_at'], "%Y-%m-%dT%H:%M:%SZ")
71-
if (now - stale_time).days >= 14:
79+
if (now - stale_time).days >= TIME_TIL_CLOSE:
7280
# Check for any comments after stale comment
7381
recent_comments = [c for c in comments if datetime.strptime(c['created_at'], "%Y-%m-%dT%H:%M:%SZ") > stale_time]
7482
if not recent_comments:
7583
close_and_lock(number)
7684

85+
7786
if __name__ == "__main__":
7887
main()

0 commit comments

Comments
 (0)