2025-09-22 02:04:19 +02:00
|
|
|
"""
|
2025-09-26 14:25:40 +02:00
|
|
|
Issue fetching using the Gitea facade.
|
|
|
|
|
|
|
|
|
|
This module now acts as an adapter to the new gitea package,
|
|
|
|
|
maintaining backwards compatibility while using the cleaner API.
|
2025-09-22 02:04:19 +02:00
|
|
|
"""
|
|
|
|
|
|
2025-09-26 14:25:40 +02:00
|
|
|
from typing import List, Dict, Any
|
2025-09-22 02:04:19 +02:00
|
|
|
|
2025-09-26 14:25:40 +02:00
|
|
|
from gitea import GiteaClient, Issue as GiteaIssue, GiteaConfig
|
2025-09-22 02:04:19 +02:00
|
|
|
from .config import get_config
|
|
|
|
|
from .exceptions import IssueError
|
|
|
|
|
|
2025-09-26 14:25:40 +02:00
|
|
|
# Re-export Issue for backwards compatibility
|
|
|
|
|
Issue = GiteaIssue
|
2025-09-22 02:04:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class IssueFetcher:
|
2025-09-26 14:25:40 +02:00
|
|
|
"""Fetches issues using the Gitea facade."""
|
2025-09-22 02:04:19 +02:00
|
|
|
|
|
|
|
|
def __init__(self, config=None):
|
|
|
|
|
self.config = config or get_config()
|
|
|
|
|
|
2025-09-26 14:25:40 +02:00
|
|
|
# Create Gitea client from tddai config
|
|
|
|
|
gitea_config = GiteaConfig.from_tddai_config(self.config)
|
|
|
|
|
self.gitea_client = GiteaClient(gitea_config)
|
|
|
|
|
|
2025-09-22 02:04:19 +02:00
|
|
|
def fetch_issue(self, issue_number: int) -> Issue:
|
|
|
|
|
"""Fetch a specific issue by number."""
|
|
|
|
|
try:
|
2025-09-26 14:25:40 +02:00
|
|
|
return self.gitea_client.issues.get(issue_number)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# Convert gitea exceptions to IssueError for backwards compatibility
|
2025-09-22 02:04:19 +02:00
|
|
|
raise IssueError(f"Failed to fetch issue #{issue_number}: {e}")
|
|
|
|
|
|
|
|
|
|
def fetch_issues(self, state: str = "all") -> List[Issue]:
|
|
|
|
|
"""Fetch all issues with optional state filter."""
|
|
|
|
|
try:
|
2025-09-26 14:25:40 +02:00
|
|
|
return self.gitea_client.issues.list(state=state)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
# Convert gitea exceptions to IssueError for backwards compatibility
|
2025-09-22 02:04:19 +02:00
|
|
|
raise IssueError(f"Failed to fetch issues: {e}")
|
|
|
|
|
|
|
|
|
|
def fetch_open_issues(self) -> List[Issue]:
|
|
|
|
|
"""Fetch only open issues."""
|
|
|
|
|
try:
|
2025-09-26 14:25:40 +02:00
|
|
|
return self.gitea_client.issues.list_open()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise IssueError(f"Failed to fetch open issues: {e}")
|
2025-09-22 02:04:19 +02:00
|
|
|
|
|
|
|
|
def get_issue_data_dict(self, issue_number: int) -> Dict[str, Any]:
|
|
|
|
|
"""Get issue data as dictionary for workspace creation."""
|
|
|
|
|
issue = self.fetch_issue(issue_number)
|
|
|
|
|
return {
|
|
|
|
|
'number': issue.number,
|
|
|
|
|
'title': issue.title,
|
|
|
|
|
'body': issue.body,
|
|
|
|
|
'state': issue.state,
|
|
|
|
|
'created_at': issue.created_at.isoformat(),
|
|
|
|
|
'updated_at': issue.updated_at.isoformat(),
|
|
|
|
|
'html_url': issue.html_url,
|
2025-09-26 14:25:40 +02:00
|
|
|
'assignee': {'login': issue.assignee.login} if issue.assignee else None,
|
|
|
|
|
'labels': [{'name': label.name} for label in issue.labels]
|
2025-09-22 02:04:19 +02:00
|
|
|
}
|