|
@@ -1,20 +1,32 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
-from typing import Mapping
|
|
|
+from typing import Any, Mapping, Protocol, Sequence
|
|
|
|
|
|
from sentry.auth.exceptions import IdentityNotValid
|
|
|
from sentry.models import Identity, Repository
|
|
|
from sentry.shared_integrations.exceptions import ApiError
|
|
|
|
|
|
|
|
|
-class CommitContextMixin:
|
|
|
+class GetBlameForFile(Protocol):
|
|
|
+ def get_blame_for_file(
|
|
|
+ self, repo: Repository, filepath: str, ref: str, lineno: int
|
|
|
+ ) -> Sequence[Mapping[str, Any]]:
|
|
|
+ ...
|
|
|
+
|
|
|
+
|
|
|
+class GetClient(Protocol):
|
|
|
+ def get_client(self) -> GetBlameForFile:
|
|
|
+ ...
|
|
|
+
|
|
|
+
|
|
|
+class CommitContextMixin(GetClient):
|
|
|
# whether or not integration has the ability to search through Repositories
|
|
|
# dynamically given a search query
|
|
|
repo_search = False
|
|
|
|
|
|
def get_blame_for_file(
|
|
|
self, repo: Repository, filepath: str, ref: str, lineno: int
|
|
|
- ) -> str | None:
|
|
|
+ ) -> Sequence[Mapping[str, Any]] | None:
|
|
|
"""
|
|
|
Calls the client's `get_blame_for_file` method to see if the file has a blame list.
|
|
|
|
|
@@ -29,8 +41,6 @@ class CommitContextMixin:
|
|
|
return None
|
|
|
try:
|
|
|
response = client.get_blame_for_file(repo, filepath, ref, lineno)
|
|
|
- if response is None:
|
|
|
- return None
|
|
|
except IdentityNotValid:
|
|
|
return None
|
|
|
except ApiError as e:
|
|
@@ -39,7 +49,7 @@ class CommitContextMixin:
|
|
|
return response
|
|
|
|
|
|
def get_commit_context(
|
|
|
- self, repo: Repository, filepath: str, branch: str, event_frame
|
|
|
+ self, repo: Repository, filepath: str, branch: str, event_frame: Mapping[str, Any]
|
|
|
) -> Mapping[str, str] | None:
|
|
|
"""Formats the source code url used for stack trace linking."""
|
|
|
raise NotImplementedError
|