init
This commit is contained in:
32
backend/app/schemas/__init__.py
Normal file
32
backend/app/schemas/__init__.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""Pydantic schemas for API"""
|
||||
|
||||
from app.schemas.repository import (
|
||||
RepositoryCreate,
|
||||
RepositoryUpdate,
|
||||
RepositoryResponse,
|
||||
RepositoryList
|
||||
)
|
||||
from app.schemas.review import (
|
||||
ReviewResponse,
|
||||
ReviewList,
|
||||
CommentResponse
|
||||
)
|
||||
from app.schemas.webhook import (
|
||||
GiteaWebhook,
|
||||
GitHubWebhook,
|
||||
BitbucketWebhook
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"RepositoryCreate",
|
||||
"RepositoryUpdate",
|
||||
"RepositoryResponse",
|
||||
"RepositoryList",
|
||||
"ReviewResponse",
|
||||
"ReviewList",
|
||||
"CommentResponse",
|
||||
"GiteaWebhook",
|
||||
"GitHubWebhook",
|
||||
"BitbucketWebhook",
|
||||
]
|
||||
|
||||
49
backend/app/schemas/repository.py
Normal file
49
backend/app/schemas/repository.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Repository schemas"""
|
||||
|
||||
from pydantic import BaseModel, Field, HttpUrl
|
||||
from typing import Optional, Dict, Any, List
|
||||
from datetime import datetime
|
||||
from app.models.repository import PlatformEnum
|
||||
|
||||
|
||||
class RepositoryBase(BaseModel):
|
||||
"""Base repository schema"""
|
||||
name: str = Field(..., description="Repository name")
|
||||
platform: PlatformEnum = Field(..., description="Git platform")
|
||||
url: str = Field(..., description="Repository URL")
|
||||
config: Optional[Dict[str, Any]] = Field(default_factory=dict, description="Review configuration")
|
||||
|
||||
|
||||
class RepositoryCreate(RepositoryBase):
|
||||
"""Schema for creating repository"""
|
||||
api_token: Optional[str] = Field(None, description="API token for Git platform (optional, uses master token if not set)")
|
||||
webhook_secret: Optional[str] = Field(None, description="Webhook secret (generated if not provided)")
|
||||
|
||||
|
||||
class RepositoryUpdate(BaseModel):
|
||||
"""Schema for updating repository"""
|
||||
name: Optional[str] = None
|
||||
url: Optional[str] = None
|
||||
api_token: Optional[str] = None
|
||||
webhook_secret: Optional[str] = None
|
||||
config: Optional[Dict[str, Any]] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
|
||||
class RepositoryResponse(RepositoryBase):
|
||||
"""Schema for repository response"""
|
||||
id: int
|
||||
is_active: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
webhook_url: str = Field(..., description="Webhook URL for this repository")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class RepositoryList(BaseModel):
|
||||
"""Schema for repository list response"""
|
||||
items: List[RepositoryResponse]
|
||||
total: int
|
||||
|
||||
70
backend/app/schemas/review.py
Normal file
70
backend/app/schemas/review.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""Review schemas"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, List
|
||||
from datetime import datetime
|
||||
from app.models.review import ReviewStatusEnum
|
||||
from app.models.comment import SeverityEnum
|
||||
|
||||
|
||||
class CommentResponse(BaseModel):
|
||||
"""Schema for comment response"""
|
||||
id: int
|
||||
file_path: str
|
||||
line_number: int
|
||||
content: str
|
||||
severity: SeverityEnum
|
||||
posted: bool
|
||||
posted_at: Optional[datetime] = None
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class PullRequestInfo(BaseModel):
|
||||
"""Schema for pull request information"""
|
||||
id: int
|
||||
pr_number: int
|
||||
title: str
|
||||
author: str
|
||||
source_branch: str
|
||||
target_branch: str
|
||||
url: str
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class ReviewResponse(BaseModel):
|
||||
"""Schema for review response"""
|
||||
id: int
|
||||
pull_request_id: int
|
||||
pull_request: PullRequestInfo
|
||||
status: ReviewStatusEnum
|
||||
started_at: datetime
|
||||
completed_at: Optional[datetime] = None
|
||||
files_analyzed: int
|
||||
comments_generated: int
|
||||
error_message: Optional[str] = None
|
||||
comments: Optional[List[CommentResponse]] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class ReviewList(BaseModel):
|
||||
"""Schema for review list response"""
|
||||
items: List[ReviewResponse]
|
||||
total: int
|
||||
|
||||
|
||||
class ReviewStats(BaseModel):
|
||||
"""Schema for review statistics"""
|
||||
total_reviews: int
|
||||
active_reviews: int
|
||||
completed_reviews: int
|
||||
failed_reviews: int
|
||||
total_comments: int
|
||||
avg_comments_per_review: float
|
||||
|
||||
68
backend/app/schemas/webhook.py
Normal file
68
backend/app/schemas/webhook.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""Webhook payload schemas"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
class GiteaPullRequest(BaseModel):
|
||||
"""Gitea pull request data"""
|
||||
id: int
|
||||
number: int
|
||||
title: str
|
||||
body: Optional[str] = None
|
||||
state: str
|
||||
user: Dict[str, Any]
|
||||
head: Dict[str, Any]
|
||||
base: Dict[str, Any]
|
||||
html_url: str
|
||||
|
||||
|
||||
class GiteaWebhook(BaseModel):
|
||||
"""Gitea webhook payload"""
|
||||
action: str = Field(..., description="Action type: opened, synchronized, closed, etc.")
|
||||
number: int = Field(..., description="Pull request number")
|
||||
pull_request: GiteaPullRequest
|
||||
repository: Dict[str, Any]
|
||||
sender: Dict[str, Any]
|
||||
|
||||
|
||||
class GitHubPullRequest(BaseModel):
|
||||
"""GitHub pull request data"""
|
||||
id: int
|
||||
number: int
|
||||
title: str
|
||||
body: Optional[str] = None
|
||||
state: str
|
||||
user: Dict[str, Any]
|
||||
head: Dict[str, Any]
|
||||
base: Dict[str, Any]
|
||||
html_url: str
|
||||
|
||||
|
||||
class GitHubWebhook(BaseModel):
|
||||
"""GitHub webhook payload"""
|
||||
action: str
|
||||
number: int
|
||||
pull_request: GitHubPullRequest
|
||||
repository: Dict[str, Any]
|
||||
sender: Dict[str, Any]
|
||||
|
||||
|
||||
class BitbucketPullRequest(BaseModel):
|
||||
"""Bitbucket pull request data"""
|
||||
id: int
|
||||
title: str
|
||||
description: Optional[str] = None
|
||||
state: str
|
||||
author: Dict[str, Any]
|
||||
source: Dict[str, Any]
|
||||
destination: Dict[str, Any]
|
||||
links: Dict[str, Any]
|
||||
|
||||
|
||||
class BitbucketWebhook(BaseModel):
|
||||
"""Bitbucket webhook payload"""
|
||||
pullrequest: BitbucketPullRequest
|
||||
repository: Dict[str, Any]
|
||||
actor: Dict[str, Any]
|
||||
|
||||
Reference in New Issue
Block a user