Skip to content

Commit

Permalink
🐛 Fix datetime comparison (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Jan 8, 2024
1 parent 62a7f8e commit cc4fdd2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
FROM python:3.7
FROM python:3.10

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

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

CMD ["python", "/app/main.py"]
COPY ./app /code/app

ENV PYTHONPATH=/code/app

CMD ["python", "/code/app/main.py"]
8 changes: 5 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
import logging
from pathlib import Path
from typing import Dict, List, Optional, Set
Expand All @@ -7,7 +7,8 @@
from github.Issue import Issue
from github.IssueComment import IssueComment
from github.IssueEvent import IssueEvent
from pydantic import BaseModel, BaseSettings, SecretStr, validator
from pydantic import BaseModel, SecretStr, validator
from pydantic_settings import BaseSettings


class KeywordMeta(BaseModel):
Expand Down Expand Up @@ -92,11 +93,12 @@ def process_issue(*, issue: Issue, settings: Settings) -> None:
events = list(issue.get_events())
labeled_events = get_labeled_events(events)
last_comment = get_last_comment(issue)
now = datetime.now(timezone.utc)
for keyword, keyword_meta in settings.input_config.items():
# Check closable delay, if enough time passed and the issue could be closed
closable_delay = (
last_comment is None
or (datetime.utcnow() - keyword_meta.delay) > last_comment.created_at
or (now - keyword_meta.delay) > last_comment.created_at
)
# Check label, optionally removing it if there's a comment after adding it
if keyword in label_strs:
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PyGithub
pydantic>=2.5.3,<3.0.0
pydantic-settings>=2.1.0,<3.0.0

0 comments on commit cc4fdd2

Please sign in to comment.