-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new endpoints for filtering and updating tasks
Signed-off-by: Conrado Costa <[email protected]>
- Loading branch information
1 parent
90b5a68
commit 96ad07d
Showing
13 changed files
with
10,261 additions
and
480 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
Task Manager API endpoints | ||
""" | ||
import logging | ||
|
||
from apps.taskman.models import JiraCustomFields | ||
|
||
from .constants import JIRA_TASKMAN_PROJECT_KEY | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class JiraTaskQueryBuilder: | ||
""" | ||
Query builder for updating or creating tasks | ||
""" | ||
|
||
def __init__(self, flaw): | ||
""" | ||
init stuff | ||
""" | ||
self._flaw = flaw | ||
self._project = JIRA_TASKMAN_PROJECT_KEY | ||
self.query = {} | ||
|
||
def generate(self, is_creation=False): | ||
""" | ||
Generate and return a dict accepted by Jira API to | ||
create or update a Jira Issue given a flaw and its task. | ||
Removes not accepted fields on if is_creation is set | ||
""" | ||
self.generate_base() | ||
self.generate_description() | ||
self.generate_labels() | ||
self.generate_summary() | ||
self.generate_owner() | ||
self.generate_group() | ||
|
||
if not is_creation: | ||
self.generate_team() | ||
|
||
return self.query | ||
|
||
def generate_base(self): | ||
"""Create a base dict to assemble a Jira query""" | ||
self.query = { | ||
"fields": { | ||
"issuetype": {"name": "Story"}, | ||
"project": {"key": self._project}, | ||
} | ||
} | ||
|
||
def generate_owner(self): | ||
"""Add the assignee of the task to query""" | ||
if not hasattr(self._flaw, "task"): | ||
return | ||
if self._flaw.task.owner: | ||
self.query["fields"]["assignee"] = {"name": self._flaw.task.owner} | ||
|
||
def generate_team(self): | ||
"""Add the team of the task to query""" | ||
if not hasattr(self._flaw, "task"): | ||
return | ||
if self._flaw.task.team_id: | ||
self.query["fields"][JiraCustomFields.TEAM] = self._flaw.task.team_id | ||
|
||
def generate_description(self): | ||
"""Add descrition of the task to query""" | ||
self.query["fields"]["description"] = self._flaw.description | ||
|
||
def generate_labels(self): | ||
"""Add labels of the task to query""" | ||
labels = [f"flawuuid:{str(self._flaw.uuid)}", f"impact:{self._flaw.impact}"] | ||
|
||
if self._flaw.is_major_incident_temp(): | ||
labels.append("major_incident") | ||
|
||
self.query["fields"]["labels"] = [ | ||
*labels, | ||
f"flawuuid:{str(self._flaw.uuid)}", | ||
f"impact:{self._flaw.impact}", | ||
] | ||
|
||
def generate_summary(self): | ||
"""Add summary of the task to query""" | ||
if not self._flaw.cve_id or self._flaw.cve_id in self._flaw.title: | ||
summary = self._flaw.title | ||
else: | ||
summary = f"{self._flaw.cve_id} {self._flaw.title}" | ||
|
||
self.query["fields"]["summary"] = summary | ||
|
||
def generate_group(self): | ||
if not hasattr(self._flaw, "task") or not self._flaw.task.jira_group_key: | ||
return | ||
self.query["fields"][JiraCustomFields.EPIC_KEY] = self._flaw.task.jira_group_key |
Oops, something went wrong.