Skip to content

Commit

Permalink
Merge pull request #83 from mgxd/rf/add-bc
Browse files Browse the repository at this point in the history
ENH: Add dedicated return types for new operations
  • Loading branch information
mgxd authored Nov 6, 2023
2 parents 21da276 + ce0b62c commit 22a7367
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
28 changes: 15 additions & 13 deletions migas/server/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from .models import get_project_tables
from .types import (
AuthenticationResult,
BreadcrumbResult,
CheckProjectResult,
Context,
ContextInput,
DateTime,
Expand All @@ -42,16 +44,16 @@ async def get_projects(self) -> list[str]:
return projs

@strawberry.field
async def check_project(self, project: str, project_version: str | None = None) -> JSON:
'''Check project for latest version, developer notes, etc.'''
async def check_project(self, project: str, project_version: str) -> CheckProjectResult:
'''Check version of project for latest version, developer notes, etc.'''
fetched = await fetch_project_info(project)
return {
'bad_versions': fetched['bad_versions'],
'cached': fetched['cached'],
'latest_version': fetched['version'],
'message': '', # TODO: Allow message for bad_versions
'success': fetched['success'],
}
is_flagged = project_version in fetched['bad_versions']
return CheckProjectResult(
success=fetched['success'],
flagged=is_flagged,
latest=fetched['version'],
# TODO: Parse/relay message
)

@strawberry.field
async def get_usage(
Expand Down Expand Up @@ -125,9 +127,9 @@ async def add_breadcrumb(
language_version: str,
ctx: ContextInput,
proc: ProcessInput,
) -> bool:
) -> BreadcrumbResult:
if not '/' in project:
return False
return BreadcrumbResult(success=False)

context = Context(
user_id=ctx.user_id,
Expand Down Expand Up @@ -155,14 +157,14 @@ async def add_breadcrumb(

bg_tasks = info.context['background_tasks']
bg_tasks.add_task(ingest_project, project)
return True
return BreadcrumbResult(success=True)


@strawberry.field
async def add_project(self, p: ProjectInput, info: Info) -> JSON:
# validate project
if not p.project or '/' not in p.project:
raise Exception("Invalid project specified.")
return {'success': False}

# convert to Project and set defaults
project = Project(
Expand Down
14 changes: 14 additions & 0 deletions migas/server/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ class AuthenticationResult:
message: str


@strawberry.type
class BreadcrumbResult:
success: bool
message: str = ''


@strawberry.type
class CheckProjectResult:
success: bool
latest: str
flagged: bool
message: str = ''


async def serialize(data: dict) -> dict:
"""Serialize data into database-friendly types"""
for k, v in data.items():
Expand Down

0 comments on commit 22a7367

Please sign in to comment.