Skip to content

Commit

Permalink
make NovaTask class a dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
atarutin committed Jun 15, 2024
1 parent 9032597 commit 04ea1d2
Showing 1 changed file with 36 additions and 60 deletions.
96 changes: 36 additions & 60 deletions core/nova_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,26 @@
Nova task component module
"""

from dataclasses import dataclass
from typing import Optional
from core.nova_status import Status


@dataclass(frozen=True)
class NovaTask:
"""Nova task"""

deployment_asterisk = "*"

@staticmethod
def map_jira_issue_status(status):
"""Maps Jira issue status to Nova task status"""
match status:
case "Selected For Release":
result = Status.READY_FOR_RELEASE
case "Done":
result = Status.DONE
case "In Development":
result = Status.IN_DEVELOPMENT
case "Ready for UAT":
result = Status.IN_DEVELOPMENT
case "Ready for testing":
result = Status.IN_DEVELOPMENT
case "In Testing":
result = Status.IN_DEVELOPMENT
case "Ready for Review":
result = Status.IN_DEVELOPMENT
case "Open":
result = Status.IN_DEVELOPMENT
case _:
result = Status.UNDEFINED

return result
name: str
status: Status
summary: str = ""
deployment: Optional[str] = None

def __init__(
self,
name: str,
status: Status,
summary: str = "",
deployment: Optional[str] = None,
):
if not name:
def __post_init__(self):
if not self.name:
raise ValueError("Task name is not defined")

self._name = name
self._status = status
self._summary = summary
self._deployment = deployment

@property
def status(self):
"""Task status"""
return self._status

@property
def name(self):
"""Task name"""
return self._name

@property
def summary(self):
"""Task summary"""
return self._summary

@property
def deployment(self):
"""Task deployment instructions"""
return self._deployment

def get_release_notes(self, preview=False) -> str:
"""
Returns release notes for task
Expand All @@ -79,9 +30,9 @@ def get_release_notes(self, preview=False) -> str:
includes asterisk if task has deployment instructions
:return: release notes
"""
key = self._name.strip().upper()
key = self.name.strip().upper()
summary = (
self._summary.split("]")[-1]
self.summary.rsplit("]", 1)[-1]
.strip()
.lstrip("[")
.rstrip(".")
Expand All @@ -90,9 +41,34 @@ def get_release_notes(self, preview=False) -> str:
)
ending = "" if summary.endswith(".") else "."
asterisk_or_not = (
(NovaTask.deployment_asterisk if self._deployment else "")
(NovaTask.deployment_asterisk if self.deployment else "")
if preview
else ""
)

return f"{key}{asterisk_or_not}: {summary}{ending}"

@staticmethod
def map_jira_issue_status(status):
"""Maps Jira issue status to Nova task status"""
match status:
case "Selected For Release":
result = Status.READY_FOR_RELEASE
case "Done":
result = Status.DONE
case "In Development":
result = Status.IN_DEVELOPMENT
case "Ready for UAT":
result = Status.IN_DEVELOPMENT
case "Ready for testing":
result = Status.IN_DEVELOPMENT
case "In Testing":
result = Status.IN_DEVELOPMENT
case "Ready for Review":
result = Status.IN_DEVELOPMENT
case "Open":
result = Status.IN_DEVELOPMENT
case _:
result = Status.UNDEFINED

return result

0 comments on commit 04ea1d2

Please sign in to comment.