diff --git a/api/integrations/gitlab/services/webhooks.py b/api/integrations/gitlab/services/webhooks.py index 88f97a31ec60..2563303596e6 100644 --- a/api/integrations/gitlab/services/webhooks.py +++ b/api/integrations/gitlab/services/webhooks.py @@ -3,7 +3,6 @@ import requests import structlog -from django.urls import reverse from core.helpers import get_current_site_url from features.feature_external_resources.models import ( @@ -20,11 +19,6 @@ logger = structlog.get_logger("gitlab") -def _get_webhook_url(webhook_uuid: uuid.UUID) -> str: - path = reverse("api-v1:gitlab-webhook", kwargs={"webhook_uuid": str(webhook_uuid)}) - return f"{get_current_site_url()}{path}" - - def has_live_resource_for_path( config: GitLabConfiguration, project_path: str, @@ -83,7 +77,7 @@ def ensure_webhook_registered( instance_url=config.gitlab_instance_url, access_token=config.access_token, project_path=project_path, - hook_url=_get_webhook_url(webhook_uuid), + hook_url=f"{get_current_site_url()}/api/v1/gitlab-webhook/{webhook_uuid}/", secret=secret, ) except requests.RequestException as exc: diff --git a/api/tests/unit/integrations/gitlab/test_webhooks.py b/api/tests/unit/integrations/gitlab/test_webhooks.py index a62fcf139194..ed7f43dc849b 100644 --- a/api/tests/unit/integrations/gitlab/test_webhooks.py +++ b/api/tests/unit/integrations/gitlab/test_webhooks.py @@ -1,6 +1,9 @@ +import uuid + import pytest import requests import responses +from django.urls import resolve from pytest_mock import MockerFixture from pytest_structlog import StructuredLogCapture @@ -15,6 +18,19 @@ ensure_webhook_registered, ) from integrations.gitlab.tasks import register_gitlab_webhook +from integrations.gitlab.views import gitlab_webhook + + +def test_gitlab_webhook_url__expected_path__resolves_to_webhook_view() -> None: + # Given + webhook_uuid = uuid.uuid4() + + # When + match = resolve(f"/api/v1/gitlab-webhook/{webhook_uuid}/") + + # Then + assert match.func is gitlab_webhook + assert match.kwargs == {"webhook_uuid": webhook_uuid} @pytest.mark.django_db diff --git a/docs/docs/deployment-self-hosting/observability/_events-catalogue.md b/docs/docs/deployment-self-hosting/observability/_events-catalogue.md index c92b09660b9d..c06cfe22e9a2 100644 --- a/docs/docs/deployment-self-hosting/observability/_events-catalogue.md +++ b/docs/docs/deployment-self-hosting/observability/_events-catalogue.md @@ -239,7 +239,7 @@ Attributes: ### `gitlab.webhook.deregistered` Logged at `info` from: - - `api/integrations/gitlab/services/webhooks.py:152` + - `api/integrations/gitlab/services/webhooks.py:146` Attributes: - `gitlab.hook.id` @@ -250,7 +250,7 @@ Attributes: ### `gitlab.webhook.deregistration_failed` Logged at `warning` from: - - `api/integrations/gitlab/services/webhooks.py:145` + - `api/integrations/gitlab/services/webhooks.py:139` Attributes: - `exc_info` @@ -262,7 +262,7 @@ Attributes: ### `gitlab.webhook.registered` Logged at `info` from: - - `api/integrations/gitlab/services/webhooks.py:105` + - `api/integrations/gitlab/services/webhooks.py:99` Attributes: - `gitlab.hook.id` @@ -274,7 +274,7 @@ Attributes: ### `gitlab.webhook.registration_failed` Logged at `error` from: - - `api/integrations/gitlab/services/webhooks.py:90` + - `api/integrations/gitlab/services/webhooks.py:84` Attributes: - `exc_info`