-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref(scm): search endpoint abstraction #76627
Conversation
try: | ||
response = installation.search_projects(query) | ||
except ApiError as e: | ||
return Response({"detail": str(e)}, status=400) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #76627 +/- ##
===========================================
+ Coverage 56.72% 78.20% +21.47%
===========================================
Files 6887 6902 +15
Lines 306241 306801 +560
Branches 50220 50288 +68
===========================================
+ Hits 173710 239924 +66214
+ Misses 127918 60469 -67449
- Partials 4613 6408 +1795 |
try: | ||
response = installation.search_issues(query=full_query, project_id=repo, iids=iids) | ||
except ApiError as e: | ||
return Response({"detail": str(e)}, status=400) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
|
||
@abstractmethod | ||
def handle_search_issues( | ||
self, installation: IntegrationInstallation, query: str, repo: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would love to be able to type installation
as type self.installation_class
, but i haven't been able to successfully do so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking. Something roughly like this should work:
I = TypeVar("I", bound=IntegrationInstallation)
class SourceCodeSearchEndpoint(IntegrationEndpoint, Generic[I], ABC):
@property
@abstractmethod
def installation_class(self) -> type[I]: ...
@abstractmethod
def handle_search_issues(self, installation: I, query: str, repo: str): ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that did it! thank you
return Response({"detail": "query is a required parameter"}, status=400) | ||
@property | ||
def installation_class(self): | ||
return (GitHubIntegration, GitHubEnterpriseIntegration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would simplify things to remove the tuple return type from the parent class. We could do that if there were a base class that GitHubIntegration
and GitHubEnterpriseIntegration
shared (and only them). Could you create a small one, just for this purpose? (Maybe "GenericGitHubIntegration", unless you want to rename "GitHubIntegration" and use that as the name for the base class.)
Looks good so far! I think your instincts are correct that parametrizing the |
84e40a8
to
d2b3041
Compare
from sentry.shared_integrations.exceptions import ApiError | ||
|
||
logger = logging.getLogger("sentry.integrations.bitbucket") | ||
|
||
T = TypeVar("T", bound=SourceCodeIssueIntegration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure if we prefer these to be single letter -- in the code we have many examples of T
being used. T
appears to be okay, but my IDE complains that I
is too vague lol
installation = integration.get_installation(organization.id) | ||
if not isinstance(installation, self.installation_class): | ||
integration_provider = ( | ||
self.integration_provider if self.integration_provider else "github" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could this scenario happen? Seems weird that we'd want to default this to github in the base endpoint class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i wanted self.integration_provider
to be defined to raise the NotFound
, but it would be better to error that the abstract property doesn't exist before doing that. thanks!
if self.repository_field and field == self.repository_field: | ||
return self.handle_search_repositories(integration, installation, query) | ||
|
||
return Response(status=400) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to respond with some additional info here about field
being invalid.
d2b3041
to
571f633
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
|
||
return Response(status=400) | ||
# TODO: somehow type installation with installation_class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need this comment, or did the generic change cover it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oopsie
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
PR reverted: cb5d129 |
This reverts commit 4634141. Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
This reverts commit 4634141. Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
Search endpoints do two things: search issues and search repositories (optional; not used in VSTS).
The shared logic for all SCMs is the following:
provider
string for everything except GH/GH Enterprise)field
(str)query
(str)field == “externalIssue”
, search for the repo field inrequest.GET
query
and therepo
field
== the repo field (usuallyrepo
, but Gitlab usesproject
)query