from typing import Any from gitea.client import GiteaClient class FileTools: """Tools for Gitea file/content operations.""" def __init__(self, client: GiteaClient) -> None: self._client = client def get_file_content(self, owner: str, repo: str, path: str) -> str: try: content = self._client.get_file_content(owner, repo, path) if isinstance(content, list): return "\n".join(content) return content except Exception as e: return f"Error getting file content: {str(e)}" def get_file_content_with_ref(self, owner: str, repo: str, path: str, ref: str = "master") -> str: try: content = self._client.get_file_content(owner, repo, path, ref) if isinstance(content, list): return "\n".join(content) return content except Exception as e: return f"Error getting file content: {str(e)}" def commit_file(self, owner: str, repo: str, path: str, message: str, content: str, branch: str) -> str: try: self._client.update_file(owner, repo, path, message, content, branch) return f"File '{path}' committed successfully to {owner}/{repo}." except Exception as e: return f"Error committing file: {str(e)}" def update_file(self, owner: str, repo: str, path: str, message: str, content: str, branch: str) -> str: try: self._client.update_file(owner, repo, path, message, content, branch) return f"File '{path}' updated in {owner}/{repo}." except Exception as e: return f"Error updating file: {str(e)}"