SeaCogs/issuecards/api/wrapper.py

23 lines
1 KiB
Python
Raw Normal View History

2025-03-28 09:56:44 -05:00
from ..models import Issue, Repository
from .forgejo import fetch_forgejo_issue
from .github import fetch_github_issue
from .gitlab import fetch_gitlab_issue, fetch_gitlab_merge_request
async def fetch_issue(repository: Repository, issue_number: int, gitlab_issue_type: str = "issue") -> Issue:
match repository.provider.service:
case "github":
if gitlab_issue_type == "merge_request":
raise ValueError("Wrong provider!")
return await fetch_github_issue(repository, issue_number)
case "forgejo":
if gitlab_issue_type == "merge_request":
raise ValueError("Wrong provider!")
return await fetch_forgejo_issue(repository, issue_number)
case "gitlab":
if gitlab_issue_type == "merge_request":
return await fetch_gitlab_merge_request(repository, issue_number)
return await fetch_gitlab_issue(repository, issue_number)
case _:
raise ValueError("Unsupported provider service: '%s'" % repository.provider.service)