-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(api): Accept project slugs in release endpoints #117493
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
Changes from all commits
c9b78bc
fc62835
f996069
50b05bf
8b486a5
72dd86d
d1b3232
efb45cb
5870536
18b0660
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import sentry_sdk | ||
| from django.db.models import Q | ||
| from drf_spectacular.utils import extend_schema, extend_schema_serializer | ||
| from rest_framework.exceptions import ParseError | ||
| from drf_spectacular.utils import OpenApiParameter, extend_schema, extend_schema_serializer | ||
| from rest_framework.exceptions import ParseError, ValidationError | ||
| from rest_framework.request import Request | ||
| from rest_framework.response import Response | ||
| from rest_framework.serializers import ListField | ||
|
|
@@ -17,6 +17,10 @@ | |
| get_stats_period_detail, | ||
| ) | ||
| from sentry.api.exceptions import ConflictError, InvalidRepository, ResourceDoesNotExist | ||
| from sentry.api.helpers.projects import ( | ||
| PROJECT_ID_OR_SLUG_SCHEMA, | ||
| ProjectIdOrSlugField, | ||
| ) | ||
| from sentry.api.serializers import serialize | ||
| from sentry.api.serializers.rest_framework import ( | ||
| ReleaseHeadCommitSerializer, | ||
|
|
@@ -38,6 +42,7 @@ | |
| as_validation_errors, | ||
| ) | ||
| from sentry.apidocs.utils import inline_sentry_response_serializer | ||
| from sentry.constants import ALL_ACCESS_PROJECT_ID, ALL_ACCESS_PROJECTS_SLUG | ||
| from sentry.models.activity import Activity | ||
| from sentry.models.organization import Organization | ||
| from sentry.models.release import Release, ReleaseStatus | ||
|
|
@@ -314,7 +319,21 @@ class OrganizationReleaseDetailsEndpoint( | |
| parameters=[ | ||
| GlobalParams.ORG_ID_OR_SLUG, | ||
| ReleaseParams.VERSION, | ||
| ReleaseParams.PROJECT_ID, | ||
| OpenApiParameter( | ||
| name="project_id", | ||
| location="query", | ||
| required=False, | ||
| type=str, | ||
| deprecated=True, | ||
| description="Deprecated. Use project instead.", | ||
| ), | ||
| OpenApiParameter( | ||
| name="project", | ||
| location="query", | ||
| required=False, | ||
| type=PROJECT_ID_OR_SLUG_SCHEMA, | ||
| description="The project ID or slug to filter by. Overrides project_id when both are sent.", | ||
| ), | ||
| ReleaseParams.HEALTH, | ||
| ReleaseParams.ADOPTION_STAGES, | ||
| ReleaseParams.SUMMARY_STATS_PERIOD, | ||
|
|
@@ -340,7 +359,7 @@ def get( | |
| """ | ||
| # Dictionary responsible for storing selected project meta data | ||
| current_project_meta = {} | ||
| project_id = request.GET.get("project") | ||
| project_id = request.GET.get("project") or request.GET.get("project_id") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The call to Suggested FixPass the validated project information to Prompt for AI Agent |
||
| with_health = request.GET.get("health") == "1" | ||
| with_adoption_stages = request.GET.get("adoptionStages") == "1" | ||
| summary_stats_period = request.GET.get("summaryStatsPeriod") or "14d" | ||
|
|
@@ -362,15 +381,30 @@ def get( | |
| if not self.has_release_permission(request, organization, release): | ||
| raise ResourceDoesNotExist | ||
|
|
||
| # Validate project access when project_id is provided | ||
| # Validate project access when a project identifier is provided. | ||
| project = None | ||
| project_ids: set[int] | None = None | ||
| project_slugs: set[str] | None = None | ||
| if project_id: | ||
| try: | ||
| project_id_int = int(project_id) | ||
| except ValueError: | ||
| project_id_or_slug = ProjectIdOrSlugField().run_validation(project_id) | ||
| except ValidationError: | ||
| raise ParseError(detail="Invalid project") | ||
|
|
||
| if isinstance(project_id_or_slug, int): | ||
| if project_id_or_slug == ALL_ACCESS_PROJECT_ID: | ||
| raise ParseError(detail="Invalid project") | ||
| project_ids = {project_id_or_slug} | ||
| else: | ||
| if project_id_or_slug == ALL_ACCESS_PROJECTS_SLUG: | ||
| raise ParseError(detail="Invalid project") | ||
| project_slugs = {project_id_or_slug} | ||
|
|
||
| validated_projects = self.get_projects( | ||
| request, organization, project_ids={project_id_int} | ||
| request, | ||
| organization, | ||
| project_ids=project_ids, | ||
| project_slugs=project_slugs, | ||
| ) | ||
| if not validated_projects: | ||
| raise ResourceDoesNotExist | ||
|
|
@@ -395,7 +429,12 @@ def get( | |
|
|
||
| # Get prev and next release to current release | ||
| try: | ||
| filter_params = self.get_filter_params(request, organization) | ||
| filter_params = self.get_filter_params( | ||
| request, | ||
| organization, | ||
| project_ids=project_ids, | ||
| project_slugs=project_slugs, | ||
| ) | ||
| current_project_meta.update( | ||
| { | ||
| **self.get_adjacent_releases_to_current_release( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.