Skip to content

ref(plugins): Minor fixes for plugins #54217

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

Merged
merged 8 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/sentry/middleware/integrations/integration_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import logging
import re
from typing import Mapping, Type
from typing import Callable, Mapping, Type

from django.http import HttpRequest, HttpResponse

from sentry.silo import SiloMode

Expand Down Expand Up @@ -46,10 +48,10 @@ class IntegrationControlMiddleware:
parser.provider: parser for parser in ACTIVE_PARSERS
}

def __init__(self, get_response):
def __init__(self, get_response: Callable[[], HttpResponse]):
self.get_response = get_response

def _identify_provider(self, request) -> str | None:
def _identify_provider(self, request: HttpRequest) -> str | None:
"""
Parses the provider out of the request path
e.g. `/extensions/slack/commands/` -> `slack`
Expand All @@ -65,7 +67,7 @@ def _identify_provider(self, request) -> str | None:
return None
return result.group(1)

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

def __call__(self, request):
def __call__(self, request: HttpRequest):
if not self._should_operate(request):
return self.get_response(request)

Expand Down
6 changes: 5 additions & 1 deletion src/sentry_plugins/bitbucket/endpoints/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __call__(self, organization, event):
pass


class BitbucketWebhookEndpoint(View):
class BitbucketPluginWebhookEndpoint(View):
_handlers = {"repo:push": PushEventWebhook}

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

def post(self, request: Request, organization_id):
logger.error(
"bitbucket_plugin.deprecation_check",
extra={"organization_id": organization_id, "meta": request.META},
)
try:
organization = Organization.objects.get_from_cache(id=organization_id)
except Organization.DoesNotExist:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry_plugins/bitbucket/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.urls import re_path

from .endpoints.webhook import BitbucketWebhookEndpoint
from .endpoints.webhook import BitbucketPluginWebhookEndpoint

urlpatterns = [
re_path(
r"^organizations/(?P<organization_id>[^\/]+)/webhook/$",
BitbucketWebhookEndpoint.as_view(),
BitbucketPluginWebhookEndpoint.as_view(),
)
]
6 changes: 3 additions & 3 deletions src/sentry_plugins/github/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from django.urls import re_path

from .webhooks import GithubIntegrationsWebhookEndpoint, GithubWebhookEndpoint
from .webhooks import GithubPluginIntegrationsWebhookEndpoint, GithubPluginWebhookEndpoint

urlpatterns = [
re_path(
r"^organizations/(?P<organization_id>[^\/]+)/webhook/$",
GithubWebhookEndpoint.as_view(),
GithubPluginWebhookEndpoint.as_view(),
),
re_path(
r"^installations/webhook/$",
GithubIntegrationsWebhookEndpoint.as_view(),
GithubPluginIntegrationsWebhookEndpoint.as_view(),
),
]
8 changes: 4 additions & 4 deletions src/sentry_plugins/github/webhooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .integration import GithubIntegrationsWebhookEndpoint
from .non_integration import GithubWebhookEndpoint
from .integration import GithubPluginIntegrationsWebhookEndpoint
from .non_integration import GithubPluginWebhookEndpoint

__all__ = (
"GithubIntegrationsWebhookEndpoint",
"GithubWebhookEndpoint",
"GithubPluginIntegrationsWebhookEndpoint",
"GithubPluginWebhookEndpoint",
)
10 changes: 9 additions & 1 deletion src/sentry_plugins/github/webhooks/integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import logging

from django.http import HttpResponse
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
Expand All @@ -11,8 +13,10 @@
from .base import GithubWebhookBase
from .events import InstallationEventWebhook, InstallationRepositoryEventWebhook, PushEventWebhook

logger = logging.getLogger(__name__)


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

def post(self, request: Request) -> HttpResponse:
logger.error(
"github_plugin.install.deprecation_check",
extra={"meta": request.META},
)
return self.handle(request)
6 changes: 5 additions & 1 deletion src/sentry_plugins/github/webhooks/non_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logger = logging.getLogger("sentry.webhooks")


class GithubWebhookEndpoint(GithubWebhookBase):
class GithubPluginWebhookEndpoint(GithubWebhookBase):
def get_logging_data(self, organization):
return {"organization_id": organization.id}

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

def post(self, request: Request, organization_id):
logger.error(
"github_plugin.webhook.deprecation_check",
extra={"organization_id": organization_id, "meta": request.META},
)
try:
organization = Organization.objects.get_from_cache(id=organization_id)
except Organization.DoesNotExist:
Expand Down
14 changes: 0 additions & 14 deletions src/sentry_plugins/gitlab/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ class GitLabPlugin(CorePluginMixin, IssuePlugin2):
conf_key = "gitlab"
required_field = "gitlab_url"
feature_descriptions = [
FeatureDescription(
"""
Track commits and releases (learn more
[here](https://docs.sentry.io/learn/releases/))
""",
IntegrationFeatures.COMMITS,
),
FeatureDescription(
"""
Resolve Sentry issues via GitLab commits and merge requests by
including `Fixes PROJ-ID` in the message
""",
IntegrationFeatures.COMMITS,
),
FeatureDescription(
"""
Create GitLab issues from Sentry
Expand Down