Skip to content

Commit

Permalink
use pydantic to validate output
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed May 16, 2024
1 parent 936b91f commit a1b7468
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions jg/hen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class Status(StrEnum):
DONE = auto()


class RepositoryContext(BaseModel):
repo: FullRepository
readme: str | None
is_profile: bool
pin: int | None


class Outcome(BaseModel):
rule: str
status: Status
Expand All @@ -26,7 +33,7 @@ class Insight(BaseModel):
collect: bool = False


class Project(BaseModel):
class ProjectInfo(BaseModel):
name: str
title: str | None
source_url: str
Expand All @@ -38,10 +45,18 @@ class Project(BaseModel):
topics: list[str]


class Info(BaseModel):
name: str | None
location: str | None
linkedin_url: str | None
avatar_url: str
projects: list[ProjectInfo] = []


class Summary(BaseModel):
username: str
outcomes: list[Outcome]
insights: dict[str, Any]
info: Info
error: Exception | None = None

class Config:
Expand All @@ -58,20 +73,15 @@ def create(
results: list[Outcome | Insight],
error: Exception | None = None,
) -> Self:
outcomes = [result for result in results if isinstance(result, Outcome)]
insights = {
result.name: result.value
for result in results
if isinstance(result, Insight)
}
return cls(
username=username,
outcomes=[result for result in results if isinstance(result, Outcome)],
insights={
result.name: result.value
for result in results
if isinstance(result, Insight)
},
outcomes=outcomes,
info=Info(**insights),
error=error,
)


class RepositoryContext(BaseModel):
repo: FullRepository
readme: str | None
is_profile: bool
pin: int | None

0 comments on commit a1b7468

Please sign in to comment.