Verified Commit 59e1519f authored by Jakob Moser's avatar Jakob Moser
Browse files

Fetch agenda from Taiga

parent b175099c
Loading
Loading
Loading
Loading
+35 −0
Changes for alembic/versions/6c174457829c_add_taigauserstoryprovider.py: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
"""Add TaigaUserStoryProvider

Revision ID: 6c174457829c
Revises: 2a60cb3fb390
Create Date: 2024-06-03 18:50:22.330381

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

from portal.model import Uuid


# revision identifiers, used by Alembic.
revision: str = "6c174457829c"
down_revision: Union[str, None] = "2a60cb3fb390"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "taiga_user_story_provider",
        sa.Column("url", sa.String(), nullable=False),
        sa.Column("authorization", sa.String(), nullable=False),
        sa.Column("uuid", Uuid(), nullable=False),
        sa.PrimaryKeyConstraint("uuid"),
    )


def downgrade() -> None:
    op.drop_table("taiga_user_story_provider")
+11 −7
Changes for portal/api/agenda.py: 11 added lines, 7 removed lines.
Original line number Diff line number Diff line
from portal.model import TaigaUserStoryProvider

from .blueprint import bp


@bp.get("/agendas/-/items")
def the_agenda_items():
    # TODO Return actual items
    return [
        {"name": "Tagesordnung"},
        {"name": "Gremienberichte"},
        {"name": "Posteingang und Kummerkasten"},
        {"name": "fsco.li/portal zum Laufen bekommen"},
        {"name": "Sonstiges"},
    tasks = TaigaUserStoryProvider.get_the_one().fetch_user_stories()

    item_names = [
        "Tagesordnung",
        "Gremienberichte",
        *(task["subject"] for task in tasks),
        "Sonstiges",
    ]

    return [{"name": name} for name in item_names]
+29 −0
Changes for portal/model/TaigaUserStoryProvider.py: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
from sqlalchemy.orm import Mapped
from typing import Any, Self

import requests


from portal.model.Base import Base


class TaigaUserStoryProvider(Base):
    """
    Fetches a list of "user stories" (i.e., tasks) from the project management tool Taiga.
    """

    url: Mapped[str]
    authorization: Mapped[str]

    def fetch_user_stories(self) -> list[dict[str, Any]]:
        return requests.get(self.url, headers={"Authorization": self.authorization}).json()

    @classmethod
    def get_the_one(cls) -> Self:
        instances = cls.get_all()
        if len(instances) != 1:
            raise ValueError(
                f"Expected there to be exactly 1 instance of {cls.__name__}, but there were {len(instances)}"
            )

        return instances[0]
+1 −0
Changes for portal/model/__init__.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,3 +6,4 @@ from .User import User
from .Uuid import Uuid
from .Key import Key
from .UtcDateTime import UtcDateTime
from .TaigaUserStoryProvider import TaigaUserStoryProvider