diff options
| author | Christian Cleberg <[email protected]> | 2026-04-09 19:45:45 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-09 19:45:45 -0500 |
| commit | acbff854f2da96bddcaede1385e7fefeba0fb34b (patch) | |
| tree | 48d4707cd3276d2825370f0793008a6ffcfff936 /src/srht_contrib/schemas.py | |
| download | hutch-stats-acbff854f2da96bddcaede1385e7fefeba0fb34b.tar.gz hutch-stats-acbff854f2da96bddcaede1385e7fefeba0fb34b.tar.bz2 hutch-stats-acbff854f2da96bddcaede1385e7fefeba0fb34b.zip | |
initial commit
Diffstat (limited to 'src/srht_contrib/schemas.py')
| -rw-r--r-- | src/srht_contrib/schemas.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/srht_contrib/schemas.py b/src/srht_contrib/schemas.py new file mode 100644 index 0000000..2a00996 --- /dev/null +++ b/src/srht_contrib/schemas.py @@ -0,0 +1,78 @@ +from __future__ import annotations + +from datetime import date, datetime + +from pydantic import BaseModel, Field, model_validator + + +class NormalizedEvent(BaseModel): + service: str + event_type: str + actor: str + repo_name: str | None = None + resource_id: str + external_uid: str + occurred_at: datetime + weight: float + raw_payload_json: dict | None = None + + +class ContributionDay(BaseModel): + date: date + count: int + score: float + + +class ContributionCalendarResponse(BaseModel): + actor: str + from_date: date = Field(alias="from") + to_date: date = Field(alias="to") + days: list[ContributionDay] + + model_config = {"populate_by_name": True} + + +class ContributionStatsResponse(BaseModel): + actor: str + from_date: date = Field(alias="from") + to_date: date = Field(alias="to") + total_events: int + total_score: float + active_days: int + longest_streak: int + current_streak: int + + model_config = {"populate_by_name": True} + + +class HealthResponse(BaseModel): + status: str + + +class PollResponse(BaseModel): + actor: str + inserted_events: int + services: list[str] + + +class TrackedRepositoryCreateRequest(BaseModel): + actor: str + repo_name: str + + +class TrackedRepositoryUpdateRequest(BaseModel): + actor: str | None = None + repo_name: str | None = None + + @model_validator(mode="after") + def validate_any_field_present(self) -> "TrackedRepositoryUpdateRequest": + if self.actor is None and self.repo_name is None: + raise ValueError("Provide `actor`, `repo_name`, or both.") + return self + + +class TrackedRepositoryResponse(BaseModel): + id: int + service: str + actor: str + repo_name: str |
