Skip to content

Commit bdbec4d

Browse files
authored
ref(plugins): Minor fixes for plugins (#54217)
This PR is a variety of small edits while investigating plugin webhooks. - Typing on the middleware - Removing unused features from GitLab listing - Add logging to check for dead code on Github/Bitbucket (which I suspect were migrated) - Rename Plugin views to avoid naming collision with integration views
1 parent e58fb2a commit bdbec4d

File tree

8 files changed

+35
-31
lines changed

8 files changed

+35
-31
lines changed

src/sentry/middleware/integrations/integration_control.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import logging
44
import re
5-
from typing import Mapping, Type
5+
from typing import Callable, Mapping, Type
6+
7+
from django.http import HttpRequest, HttpResponse
68

79
from sentry.silo import SiloMode
810

@@ -46,10 +48,10 @@ class IntegrationControlMiddleware:
4648
parser.provider: parser for parser in ACTIVE_PARSERS
4749
}
4850

49-
def __init__(self, get_response):
51+
def __init__(self, get_response: Callable[[], HttpResponse]):
5052
self.get_response = get_response
5153

52-
def _identify_provider(self, request) -> str | None:
54+
def _identify_provider(self, request: HttpRequest) -> str | None:
5355
"""
5456
Parses the provider out of the request path
5557
e.g. `/extensions/slack/commands/` -> `slack`
@@ -65,7 +67,7 @@ def _identify_provider(self, request) -> str | None:
6567
return None
6668
return result.group(1)
6769

68-
def _should_operate(self, request) -> bool:
70+
def _should_operate(self, request: HttpRequest) -> bool:
6971
"""
7072
Determines whether this middleware will operate or just pass the request along.
7173
"""
@@ -74,7 +76,7 @@ def _should_operate(self, request) -> bool:
7476
is_not_setup = not request.path.endswith(self.setup_suffix)
7577
return is_correct_silo and is_integration and is_not_setup
7678

77-
def __call__(self, request):
79+
def __call__(self, request: HttpRequest):
7880
if not self._should_operate(request):
7981
return self.get_response(request)
8082

src/sentry_plugins/bitbucket/endpoints/webhook.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __call__(self, organization, event):
7777
pass
7878

7979

80-
class BitbucketWebhookEndpoint(View):
80+
class BitbucketPluginWebhookEndpoint(View):
8181
_handlers = {"repo:push": PushEventWebhook}
8282

8383
def get_handler(self, event_type):
@@ -91,6 +91,10 @@ def dispatch(self, request: Request, *args, **kwargs) -> HttpResponse:
9191
return super().dispatch(request, *args, **kwargs)
9292

9393
def post(self, request: Request, organization_id):
94+
logger.error(
95+
"bitbucket_plugin.deprecation_check",
96+
extra={"organization_id": organization_id, "meta": request.META},
97+
)
9498
try:
9599
organization = Organization.objects.get_from_cache(id=organization_id)
96100
except Organization.DoesNotExist:

src/sentry_plugins/bitbucket/urls.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from django.urls import re_path
22

3-
from .endpoints.webhook import BitbucketWebhookEndpoint
3+
from .endpoints.webhook import BitbucketPluginWebhookEndpoint
44

55
urlpatterns = [
66
re_path(
77
r"^organizations/(?P<organization_id>[^\/]+)/webhook/$",
8-
BitbucketWebhookEndpoint.as_view(),
8+
BitbucketPluginWebhookEndpoint.as_view(),
99
)
1010
]

src/sentry_plugins/github/urls.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from django.urls import re_path
22

3-
from .webhooks import GithubIntegrationsWebhookEndpoint, GithubWebhookEndpoint
3+
from .webhooks import GithubPluginIntegrationsWebhookEndpoint, GithubPluginWebhookEndpoint
44

55
urlpatterns = [
66
re_path(
77
r"^organizations/(?P<organization_id>[^\/]+)/webhook/$",
8-
GithubWebhookEndpoint.as_view(),
8+
GithubPluginWebhookEndpoint.as_view(),
99
),
1010
re_path(
1111
r"^installations/webhook/$",
12-
GithubIntegrationsWebhookEndpoint.as_view(),
12+
GithubPluginIntegrationsWebhookEndpoint.as_view(),
1313
),
1414
]
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from .integration import GithubIntegrationsWebhookEndpoint
2-
from .non_integration import GithubWebhookEndpoint
1+
from .integration import GithubPluginIntegrationsWebhookEndpoint
2+
from .non_integration import GithubPluginWebhookEndpoint
33

44
__all__ = (
5-
"GithubIntegrationsWebhookEndpoint",
6-
"GithubWebhookEndpoint",
5+
"GithubPluginIntegrationsWebhookEndpoint",
6+
"GithubPluginWebhookEndpoint",
77
)

src/sentry_plugins/github/webhooks/integration.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import logging
4+
35
from django.http import HttpResponse
46
from django.utils.decorators import method_decorator
57
from django.views.decorators.csrf import csrf_exempt
@@ -11,8 +13,10 @@
1113
from .base import GithubWebhookBase
1214
from .events import InstallationEventWebhook, InstallationRepositoryEventWebhook, PushEventWebhook
1315

16+
logger = logging.getLogger(__name__)
17+
1418

15-
class GithubIntegrationsWebhookEndpoint(GithubWebhookBase):
19+
class GithubPluginIntegrationsWebhookEndpoint(GithubWebhookBase):
1620
_handlers = {
1721
"push": PushEventWebhook,
1822
"installation": InstallationEventWebhook,
@@ -30,4 +34,8 @@ def get_secret(self, organization: Organization) -> str | None:
3034
return options.get("github.integration-hook-secret")
3135

3236
def post(self, request: Request) -> HttpResponse:
37+
logger.error(
38+
"github_plugin.install.deprecation_check",
39+
extra={"meta": request.META},
40+
)
3341
return self.handle(request)

src/sentry_plugins/github/webhooks/non_integration.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
logger = logging.getLogger("sentry.webhooks")
1313

1414

15-
class GithubWebhookEndpoint(GithubWebhookBase):
15+
class GithubPluginWebhookEndpoint(GithubWebhookBase):
1616
def get_logging_data(self, organization):
1717
return {"organization_id": organization.id}
1818

@@ -22,6 +22,10 @@ def get_secret(self, organization: Organization) -> str | None:
2222
)
2323

2424
def post(self, request: Request, organization_id):
25+
logger.error(
26+
"github_plugin.webhook.deprecation_check",
27+
extra={"organization_id": organization_id, "meta": request.META},
28+
)
2529
try:
2630
organization = Organization.objects.get_from_cache(id=organization_id)
2731
except Organization.DoesNotExist:

src/sentry_plugins/gitlab/plugin.py

-14
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ class GitLabPlugin(CorePluginMixin, IssuePlugin2):
1818
conf_key = "gitlab"
1919
required_field = "gitlab_url"
2020
feature_descriptions = [
21-
FeatureDescription(
22-
"""
23-
Track commits and releases (learn more
24-
[here](https://docs.sentry.io/learn/releases/))
25-
""",
26-
IntegrationFeatures.COMMITS,
27-
),
28-
FeatureDescription(
29-
"""
30-
Resolve Sentry issues via GitLab commits and merge requests by
31-
including `Fixes PROJ-ID` in the message
32-
""",
33-
IntegrationFeatures.COMMITS,
34-
),
3521
FeatureDescription(
3622
"""
3723
Create GitLab issues from Sentry

0 commit comments

Comments
 (0)