|
2 | 2 |
|
3 | 3 | from django.db.models import F
|
4 | 4 | from django.utils import timezone
|
| 5 | +from drf_spectacular.utils import extend_schema |
5 | 6 | from rest_framework import serializers
|
6 | 7 | from rest_framework.request import Request
|
7 | 8 | from rest_framework.response import Response
|
8 | 9 |
|
| 10 | +from sentry.api.api_owners import ApiOwner |
9 | 11 | from sentry.api.api_publish_status import ApiPublishStatus
|
10 | 12 | from sentry.api.base import region_silo_endpoint
|
11 | 13 | from sentry.api.bases.organization import OrganizationReleasesBaseEndpoint
|
12 | 14 | from sentry.api.exceptions import ParameterValidationError, ResourceDoesNotExist
|
13 | 15 | from sentry.api.paginator import OffsetPaginator
|
14 | 16 | from sentry.api.serializers import serialize
|
15 | 17 | from sentry.api.serializers.rest_framework.project import ProjectField
|
| 18 | +from sentry.apidocs.constants import RESPONSE_BAD_REQUEST |
| 19 | +from sentry.apidocs.parameters import GlobalParams, ReleaseParams |
16 | 20 | from sentry.models.deploy import Deploy
|
17 | 21 | from sentry.models.environment import Environment
|
18 | 22 | from sentry.models.organization import Organization
|
|
23 | 27 | logger = logging.getLogger(__name__)
|
24 | 28 |
|
25 | 29 |
|
| 30 | +class DeployResponseSerializer(serializers.Serializer): |
| 31 | + """Serializer for Deploy response objects""" |
| 32 | + |
| 33 | + id = serializers.CharField(help_text="The ID of the deploy") |
| 34 | + environment = serializers.CharField(help_text="The environment name") |
| 35 | + dateStarted = serializers.DateTimeField( |
| 36 | + allow_null=True, help_text="An optional date that indicates when the deploy started" |
| 37 | + ) |
| 38 | + dateFinished = serializers.DateTimeField( |
| 39 | + help_text="An optional date that indicates when the deploy ended" |
| 40 | + ) |
| 41 | + name = serializers.CharField(allow_null=True, help_text="The optional name of the deploy") |
| 42 | + url = serializers.URLField( |
| 43 | + allow_null=True, help_text="The optional URL that points to the deploy" |
| 44 | + ) |
| 45 | + |
| 46 | + |
26 | 47 | class DeploySerializer(serializers.Serializer):
|
27 |
| - name = serializers.CharField(max_length=64, required=False, allow_blank=True, allow_null=True) |
28 |
| - environment = serializers.CharField(max_length=64) |
29 |
| - url = serializers.URLField(required=False, allow_blank=True, allow_null=True) |
30 |
| - dateStarted = serializers.DateTimeField(required=False, allow_null=True) |
31 |
| - dateFinished = serializers.DateTimeField(required=False, allow_null=True) |
| 48 | + name = serializers.CharField( |
| 49 | + max_length=64, |
| 50 | + required=False, |
| 51 | + allow_blank=True, |
| 52 | + allow_null=True, |
| 53 | + help_text="The optional name of the deploy", |
| 54 | + ) |
| 55 | + environment = serializers.CharField( |
| 56 | + max_length=64, help_text="The environment you're deploying to" |
| 57 | + ) |
| 58 | + url = serializers.URLField( |
| 59 | + required=False, |
| 60 | + allow_blank=True, |
| 61 | + allow_null=True, |
| 62 | + help_text="The optional URL that points to the deploy", |
| 63 | + ) |
| 64 | + dateStarted = serializers.DateTimeField( |
| 65 | + required=False, |
| 66 | + allow_null=True, |
| 67 | + help_text="An optional date that indicates when the deploy started", |
| 68 | + ) |
| 69 | + dateFinished = serializers.DateTimeField( |
| 70 | + required=False, |
| 71 | + allow_null=True, |
| 72 | + help_text="An optional date that indicates when the deploy ended. If not provided, the current time is used.", |
| 73 | + ) |
32 | 74 | projects = serializers.ListField(
|
33 |
| - child=ProjectField(scope="project:read", id_allowed=True), required=False, allow_empty=False |
| 75 | + child=ProjectField(scope="project:read", id_allowed=True), |
| 76 | + required=False, |
| 77 | + allow_empty=False, |
| 78 | + help_text="The optional list of project slugs to create a deploy within. If not provided, deploys are created for all of the release's projects.", |
34 | 79 | )
|
35 | 80 |
|
36 | 81 | def validate_environment(self, value):
|
@@ -89,22 +134,23 @@ def create_deploy(
|
89 | 134 | return deploy
|
90 | 135 |
|
91 | 136 |
|
| 137 | +@extend_schema(tags=["Releases"]) |
92 | 138 | @region_silo_endpoint
|
93 | 139 | class ReleaseDeploysEndpoint(OrganizationReleasesBaseEndpoint):
|
| 140 | + owner = ApiOwner.UNOWNED |
94 | 141 | publish_status = {
|
95 |
| - "GET": ApiPublishStatus.UNKNOWN, |
96 |
| - "POST": ApiPublishStatus.UNKNOWN, |
| 142 | + "GET": ApiPublishStatus.PUBLIC, |
| 143 | + "POST": ApiPublishStatus.PUBLIC, |
97 | 144 | }
|
98 | 145 |
|
| 146 | + @extend_schema( |
| 147 | + operation_id="List a Release's Deploys", |
| 148 | + parameters=[GlobalParams.ORG_ID_OR_SLUG, ReleaseParams.VERSION], |
| 149 | + responses={200: DeployResponseSerializer(many=True)}, |
| 150 | + ) |
99 | 151 | def get(self, request: Request, organization, version) -> Response:
|
100 | 152 | """
|
101 |
| - List a Release's Deploys |
102 |
| - ```````````````````````` |
103 |
| -
|
104 | 153 | Returns a list of deploys based on the organization, version, and project.
|
105 |
| -
|
106 |
| - :pparam string organization_id_or_slug: the id or slug of the organization |
107 |
| - :pparam string version: the version identifier of the release. |
108 | 154 | """
|
109 | 155 | try:
|
110 | 156 | release = Release.objects.get(version=version, organization=organization)
|
@@ -136,26 +182,15 @@ def get(self, request: Request, organization, version) -> Response:
|
136 | 182 | on_results=lambda x: serialize(x, request.user),
|
137 | 183 | )
|
138 | 184 |
|
| 185 | + @extend_schema( |
| 186 | + operation_id="Create a Deploy", |
| 187 | + parameters=[GlobalParams.ORG_ID_OR_SLUG, ReleaseParams.VERSION], |
| 188 | + request=DeploySerializer, |
| 189 | + responses={201: DeployResponseSerializer, 400: RESPONSE_BAD_REQUEST}, |
| 190 | + ) |
139 | 191 | def post(self, request: Request, organization, version) -> Response:
|
140 | 192 | """
|
141 |
| - Create a Deploy |
142 |
| - ``````````````` |
143 |
| -
|
144 | 193 | Create a deploy for a given release.
|
145 |
| -
|
146 |
| - :pparam string organization_id_or_slug: the id or slug of the organization |
147 |
| - :pparam string version: the version identifier of the release. |
148 |
| - :param string environment: the environment you're deploying to |
149 |
| - :param string name: the optional name of the deploy |
150 |
| - :param list projects: the optional list of project slugs to |
151 |
| - create a deploy within. If not provided, deploys |
152 |
| - are created for all of the release's projects. |
153 |
| - :param url url: the optional url that points to the deploy |
154 |
| - :param datetime dateStarted: an optional date that indicates when |
155 |
| - the deploy started |
156 |
| - :param datetime dateFinished: an optional date that indicates when |
157 |
| - the deploy ended. If not provided, the |
158 |
| - current time is used. |
159 | 194 | """
|
160 | 195 | logging_info = {
|
161 | 196 | "org_slug": organization.slug,
|
|
0 commit comments