"""Interfaces for Gitea operations.""" from abc import ABC, abstractmethod from typing import Any from gitea.models import ( IssueModel, PullRequestModel, CommentModel, LabelModel, UserModel, RepositoryModel, PullRequestFileModel, ) class IssuesClient(ABC): """Interface for Gitea issue operations.""" @abstractmethod def list_repo_issues(self, owner: str, repo: str, state: str = "open") -> list[IssueModel]: ... @abstractmethod def get_issue(self, owner: str, repo: str, issue_number: int) -> IssueModel: ... @abstractmethod def close_issue(self, owner: str, repo: str, issue_number: int) -> IssueModel: ... @abstractmethod def get_issue_comments(self, owner: str, repo: str, issue_number: int) -> list[CommentModel]: ... @abstractmethod def list_assigned_issues(self, owner: str, repo: str) -> list[IssueModel]: ... @abstractmethod def create_issue( self, owner: str, repo: str, title: str, body: str, labels: list[str] | None = None, assignees: list[str] | None = None, ) -> IssueModel: ... @abstractmethod def add_comment(self, owner: str, repo: str, issue_number: int, body: str) -> CommentModel: ... @abstractmethod def add_label(self, owner: str, repo: str, issue_number: int, label: str) -> LabelModel: ... class PullRequestsClient(ABC): """Interface for Gitea pull request operations.""" @abstractmethod def list_repo_pull_requests(self, owner: str, repo: str, state: str = "open") -> list[PullRequestModel]: ... @abstractmethod def get_pull_request(self, owner: str, repo: str, pull_number: int) -> PullRequestModel: ... @abstractmethod def close_pull_request(self, owner: str, repo: str, pull_number: int) -> PullRequestModel: ... @abstractmethod def get_pull_request_comments(self, owner: str, repo: str, pull_number: int) -> list[CommentModel]: ... @abstractmethod def get_pr_reviews(self, owner: str, repo: str, pr_number: int) -> list[dict[str, Any]]: ... @abstractmethod def get_pull_request_diff(self, owner: str, repo: str, pull_number: int) -> str: ... @abstractmethod def get_pull_request_patch(self, owner: str, repo: str, pull_number: int) -> str: ... @abstractmethod def get_pull_request_files(self, owner: str, repo: str, pull_number: int) -> list[PullRequestFileModel]: ... @abstractmethod def list_assigned_pull_requests(self, owner: str, repo: str) -> list[PullRequestModel]: ... @abstractmethod def create_pull_request( self, owner: str, repo: str, head: str, base: str, title: str, description: str = "" ) -> PullRequestModel: ... @abstractmethod def update_pull_request( self, owner: str, repo: str, pull_number: int, title: str | None = None, body: str | None = None, state: str | None = None, ) -> PullRequestModel: ... @abstractmethod def approve_pr(self, owner: str, repo: str, pr_number: int, comment: str) -> dict[str, Any]: ... @abstractmethod def request_changes_pr(self, owner: str, repo: str, pr_number: int, comment: str) -> dict[str, Any]: ... @abstractmethod def dismiss_review_pr( self, owner: str, repo: str, pr_number: int, review_id: int, message: str ) -> dict[str, Any]: ... @abstractmethod def assign_issue(self, owner: str, repo: str, issue_number: int, username: str) -> IssueModel: ... class FilesClient(ABC): """Interface for Gitea file/content operations.""" @abstractmethod def get_file_content(self, owner: str, repo: str, path: str, ref: str = "master") -> str | list[str]: ... @abstractmethod def update_file( self, owner: str, repo: str, path: str, message: str, content: str, branch: str ) -> dict[str, Any]: ... class RefsClient(ABC): """Interface for Gitea git ref operations.""" @abstractmethod def update_ref(self, owner: str, repo: str, ref: str, sha: str) -> dict[str, Any]: ... @abstractmethod def create_ref(self, owner: str, repo: str, ref: str, sha: str) -> dict[str, Any]: ... class ReposClient(ABC): """Interface for Gitea repository operations.""" @abstractmethod def list_all_user_repos(self) -> list[RepositoryModel]: ... class Agent(ABC): """Interface for AI agent operations.""" @abstractmethod async def initialize(self) -> None: ... @abstractmethod async def run(self, user_input: str) -> str: ... @abstractmethod async def run_with_tools(self, user_input: str, tools: list[Any]) -> str: ... class Workspace(ABC): """Interface for workspace management.""" @abstractmethod def get_repo_path(self, repo_full_name: str) -> Any: ... @abstractmethod def sanitize_repo(self, repo_path: Any) -> None: ... @abstractmethod def clone_repo(self, repo_full_name: str, clone_url: str) -> Any: ... class MissionBuilder(ABC): """Interface for mission string construction.""" @abstractmethod def build_issue_mission(self, issue_info: dict[str, Any], branch_name: str) -> str: ... @abstractmethod def build_pr_mission(self, pr_info: dict[str, Any]) -> str: ... class BranchStrategy(ABC): """Interface for branch creation strategy.""" @abstractmethod async def create_or_reuse_branch(self, repo_path: Any, branch_name: str, base_branch: str | None = None) -> str: ...