Skip to content

Commit

Permalink
API: Engagement update jira epic (#11234)
Browse files Browse the repository at this point in the history
Co-authored-by: Raouf HADDADA <[email protected]>
  • Loading branch information
raouf-haddada and Raouf HADDADA authored Nov 12, 2024
1 parent ab2a2c0 commit ee77ea4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dojo/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,11 @@ class ReportGenerateSerializer(serializers.Serializer):
)


class EngagementUpdateJiraEpicSerializer(serializers.Serializer):
epic_name = serializers.CharField(required=False, max_length=200)
epic_priority = serializers.CharField(required=False, allow_null=True)


class TagSerializer(serializers.Serializer):
tags = TagListSerializerField(required=True)

Expand Down
30 changes: 30 additions & 0 deletions dojo/api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,36 @@ def download_file(self, request, file_id, pk=None):
# send file
return generate_file_response(file_object)

@extend_schema(
request=serializers.EngagementUpdateJiraEpicSerializer,
responses={status.HTTP_200_OK: serializers.EngagementUpdateJiraEpicSerializer},
)
@action(
detail=True, methods=["post"], permission_classes=[IsAuthenticated],
)
def update_jira_epic(self, request, pk=None):
engagement = self.get_object()
try:

if engagement.has_jira_issue:
jira_helper.update_epic(engagement, **request.data)
response = Response(
{"info": "Jira Epic update query sent"},
status=status.HTTP_200_OK,
)
else:
jira_helper.add_epic(engagement, **request.data)
response = Response(
{"info": "Jira Epic create query sent"},
status=status.HTTP_200_OK,
)
return response
except ValidationError:
return Response(
{"error": "Bad Request!"},
status=status.HTTP_400_BAD_REQUEST,
)


# @extend_schema_view(**schema_with_prefetch())
# Nested models with prefetch make the response schema too long for Swagger UI
Expand Down
9 changes: 8 additions & 1 deletion dojo/jira_link/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,14 @@ def update_epic(engagement, **kwargs):
if not epic_name:
epic_name = engagement.name

issue.update(summary=epic_name, description=epic_name)
epic_priority = kwargs.get("epic_priority", None)

jira_issue_update_kwargs = {
"summary": epic_name,
"description": epic_name,
"priority": {"name": epic_priority},
}
issue.update(**jira_issue_update_kwargs)
return True
except JIRAError as e:
logger.exception(e)
Expand Down

0 comments on commit ee77ea4

Please sign in to comment.