78 lines
1.8 KiB
Python
78 lines
1.8 KiB
Python
"""Base service for Git platforms"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import List, Dict, Any, Optional
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class FileChange:
|
|
"""Represents a changed file in PR"""
|
|
filename: str
|
|
status: str # added, modified, removed
|
|
additions: int
|
|
deletions: int
|
|
patch: Optional[str] = None
|
|
content: Optional[str] = None
|
|
|
|
|
|
@dataclass
|
|
class PRInfo:
|
|
"""Pull request information"""
|
|
number: int
|
|
title: str
|
|
description: str
|
|
author: str
|
|
source_branch: str
|
|
target_branch: str
|
|
url: str
|
|
state: str
|
|
|
|
|
|
class BaseGitService(ABC):
|
|
"""Base class for Git platform services"""
|
|
|
|
def __init__(self, base_url: str, token: str, repo_owner: str, repo_name: str):
|
|
self.base_url = base_url.rstrip("/")
|
|
self.token = token
|
|
self.repo_owner = repo_owner
|
|
self.repo_name = repo_name
|
|
|
|
@abstractmethod
|
|
async def get_pull_request(self, pr_number: int) -> PRInfo:
|
|
"""Get pull request information"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def get_pr_files(self, pr_number: int) -> List[FileChange]:
|
|
"""Get list of changed files in PR"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def get_file_content(self, file_path: str, ref: str) -> str:
|
|
"""Get file content at specific ref"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def create_review_comment(
|
|
self,
|
|
pr_number: int,
|
|
file_path: str,
|
|
line_number: int,
|
|
comment: str,
|
|
commit_id: str
|
|
) -> Dict[str, Any]:
|
|
"""Create a review comment on PR"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def create_review(
|
|
self,
|
|
pr_number: int,
|
|
comments: List[Dict[str, Any]],
|
|
body: str = ""
|
|
) -> Dict[str, Any]:
|
|
"""Create a review with multiple comments"""
|
|
pass
|
|
|