Skip to content

Commit cc4fdd2

Browse files
authored
🐛 Fix datetime comparison (#19)
1 parent 62a7f8e commit cc4fdd2

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
FROM python:3.7
1+
FROM python:3.10
22

3-
RUN pip install "PyGithub>=1.55,<2.0" "pydantic>=v1.8.2,<2.0"
3+
COPY ./requirements.txt /code/requirements.txt
44

5-
COPY ./app /app
5+
RUN pip install -r /code/requirements.txt
66

7-
CMD ["python", "/app/main.py"]
7+
COPY ./app /code/app
8+
9+
ENV PYTHONPATH=/code/app
10+
11+
CMD ["python", "/code/app/main.py"]

app/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime, timedelta, timezone
22
import logging
33
from pathlib import Path
44
from typing import Dict, List, Optional, Set
@@ -7,7 +7,8 @@
77
from github.Issue import Issue
88
from github.IssueComment import IssueComment
99
from github.IssueEvent import IssueEvent
10-
from pydantic import BaseModel, BaseSettings, SecretStr, validator
10+
from pydantic import BaseModel, SecretStr, validator
11+
from pydantic_settings import BaseSettings
1112

1213

1314
class KeywordMeta(BaseModel):
@@ -92,11 +93,12 @@ def process_issue(*, issue: Issue, settings: Settings) -> None:
9293
events = list(issue.get_events())
9394
labeled_events = get_labeled_events(events)
9495
last_comment = get_last_comment(issue)
96+
now = datetime.now(timezone.utc)
9597
for keyword, keyword_meta in settings.input_config.items():
9698
# Check closable delay, if enough time passed and the issue could be closed
9799
closable_delay = (
98100
last_comment is None
99-
or (datetime.utcnow() - keyword_meta.delay) > last_comment.created_at
101+
or (now - keyword_meta.delay) > last_comment.created_at
100102
)
101103
# Check label, optionally removing it if there's a comment after adding it
102104
if keyword in label_strs:

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PyGithub
2+
pydantic>=2.5.3,<3.0.0
3+
pydantic-settings>=2.1.0,<3.0.0

0 commit comments

Comments
 (0)