Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions invenio_github/alembic/2f62e6442a08_change_datetime_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2018 CERN.
# Copyright (C) 2026 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Change expires_at type to utc aware datetime."""

from invenio_db.utils import (
update_table_columns_column_type_to_datetime,
update_table_columns_column_type_to_utc_datetime,
)

# revision identifiers, used by Alembic.
revision = "2f62e6442a08"
down_revision = "b0eaee37b545"
branch_labels = ()
depends_on = None


def upgrade():
"""Upgrade database."""
for table_name in ["github_repositories", "github_releases"]:
update_table_columns_column_type_to_utc_datetime(table_name, "created")
update_table_columns_column_type_to_utc_datetime(table_name, "updated")


def downgrade():
"""Downgrade database."""
for table_name in ["github_repositories", "github_releases"]:
update_table_columns_column_type_to_datetime(table_name, "created")
update_table_columns_column_type_to_datetime(table_name, "updated")
6 changes: 3 additions & 3 deletions invenio_github/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 CERN.
# Copyright (C) 2026 Graz University of Technology.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -32,7 +33,6 @@
from invenio_i18n import lazy_gettext as _
from invenio_webhooks.models import Event
from sqlalchemy.dialects import postgresql
from sqlalchemy_utils.models import Timestamp
from sqlalchemy_utils.types import ChoiceType, JSONType, UUIDType

RELEASE_STATUS_TITLES = {
Expand Down Expand Up @@ -107,7 +107,7 @@ def color(self):
return RELEASE_STATUS_COLOR[self.name]


class Repository(db.Model, Timestamp):
class Repository(db.Model, db.Timestamp):
"""Information about a GitHub repository."""

__tablename__ = "github_repositories"
Expand Down Expand Up @@ -203,7 +203,7 @@ def __repr__(self):
return "<Repository {self.name}:{self.github_id}>".format(self=self)


class Release(db.Model, Timestamp):
class Release(db.Model, db.Timestamp):
"""Information about a GitHub release."""

__tablename__ = "github_releases"
Expand Down
3 changes: 2 additions & 1 deletion invenio_github/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is part of Invenio.
# Copyright (C) 2023 CERN.
# Copyright (C) 2024 KTH Royal Institute of Technology.
# Copyright (C) 2026 Graz University of Technology.
#
# Invenio is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -154,7 +155,7 @@ def refresh_accounts(expiration_threshold=None):
:param expiration_threshold: Dictionary containing timedelta parameters
referring to the maximum inactivity time.
"""
expiration_date = datetime.datetime.utcnow() - datetime.timedelta(
expiration_date = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(
**(expiration_threshold or {"days": 6 * 30})
)

Expand Down
8 changes: 4 additions & 4 deletions invenio_github/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2023 CERN.
# Copyright (C) 2026 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
Expand All @@ -19,17 +20,16 @@

"""Various utility functions."""

from datetime import datetime
from datetime import datetime, timezone

import dateutil.parser
import pytz
import six
from werkzeug.utils import import_string


def utcnow():
"""UTC timestamp (with timezone)."""
return datetime.now(tz=pytz.utc)
return datetime.now(tz=timezone.utc)


def iso_utcnow():
Expand All @@ -41,7 +41,7 @@ def parse_timestamp(x):
"""Parse ISO8601 formatted timestamp."""
dt = dateutil.parser.parse(x)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=pytz.utc)
dt = dt.replace(tzinfo=timezone.utc)
return dt


Expand Down
Loading