Skip to content

Commit

Permalink
Merge pull request #221 from lsst-ts/tickets/DM-41211
Browse files Browse the repository at this point in the history
Remove JIRA fields ids mapping
  • Loading branch information
sebastian-aranda authored Nov 6, 2023
2 parents 8cecc2f + 22dd919 commit 72c8744
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 66 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version History
v5.14.9
-------

* Remove JIRA fields ids mapping `<https://github.com/lsst-ts/LOVE-manager/pull/221>`_
* Bump urllib3 from 1.26.17 to 1.26.18 in /manager `<https://github.com/lsst-ts/LOVE-manager/pull/218>`_

v5.14.8
Expand Down
82 changes: 70 additions & 12 deletions manager/api/tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,49 @@
# this program. If not, see <http://www.gnu.org/licenses/>.


import math
import random
from unittest.mock import patch

import requests
from api.views import jira_comment, jira_ticket
from django.test import TestCase, override_settings

from manager.utils import (
OLE_JIRA_OBS_COMPONENTS_FIELDS,
OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS,
OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS,
)
OLE_JIRA_OBS_COMPONENTS_FIELDS = [
"AuxTel",
"Calibrations",
"Environmental Monitoring Systems",
"Facilities",
"IT Infrastricture",
"MainTel",
"Observer Remark",
"Other",
"Unknown",
]

OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS = [
"None",
"CSC level",
"Component Level (EUI)",
"Visualization",
"Analysis",
"Other",
"Camera Control Software",
]

OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS = [
"None",
"Mount",
"Rotator",
"Hexapod",
"M2",
"Science Cameras",
"M1M3",
"Dome",
"Utilities",
"Calibration",
"Other",
]


@override_settings(DEBUG=True)
Expand Down Expand Up @@ -67,13 +98,40 @@ def setUp(self):
}

request_narrative = {
"components": ",".join(list(OLE_JIRA_OBS_COMPONENTS_FIELDS.keys())[:2]),
"primary_software_components": list(
OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS.keys()
)[0],
"primary_hardware_components": list(
OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS.keys()
)[0],
"components": ",".join(
list(
OLE_JIRA_OBS_COMPONENTS_FIELDS[
: math.ceil(
random.random() * (len(OLE_JIRA_OBS_COMPONENTS_FIELDS) - 1)
)
]
)
),
"components_ids": ",".join(
[str(n) for n in range(1, math.ceil(random.random() * 100))]
),
"primary_software_components": ",".join(
OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS[
math.ceil(
random.random()
* (len(OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS) - 1)
)
]
),
"primary_software_components_ids": ",".join(
[str(math.ceil(random.random() * 100))]
),
"primary_hardware_components": ",".join(
OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS[
math.ceil(
random.random()
* (len(OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS) - 1)
)
]
),
"primary_hardware_components_ids": ",".join(
[str(math.ceil(random.random() * 100))]
),
"date_begin": "2022-07-03T19:58:13.00000",
"date_end": "2022-07-04T19:25:13.00000",
"time_lost": 10,
Expand Down
78 changes: 24 additions & 54 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,6 @@
JSON_RESPONSE_LOCAL_STORAGE_NOT_ALLOWED = {"error": "Local storage not allowed."}
JSON_RESPONSE_ERROR_NOT_VALID_JSON = {"error": "Not a valid JSON response."}

# Mappings
OLE_JIRA_OBS_COMPONENTS_FIELDS = {
"AuxTel": 20710,
"Calibrations": 20714,
"Environmental Monitoring Systems": 20711,
"Facilities": 20712,
"IT Infrastricture": 20718,
"MainTel": 20709,
"Observer Remark": 20717,
"Other": 20713,
"Unknown": 19507,
}

OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS = {
"None": -1,
"CSC level": 16810,
"Component Level (EUI)": 16811,
"Visualization": 16812,
"Analysis": 16813,
"Other": 16814,
"Camera Control Software": 16815,
}

OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS = {
"None": -1,
"Mount": 16816,
"Rotator": 16817,
"Hexapod": 16818,
"M2": 16819,
"Science Cameras": 16820,
"M1M3": 16821,
"Dome": 16822,
"Utilities": 16825,
"Calibration": 16826,
"Other": 16827,
}


class LocationPermission(BasePermission):
"""Permission class to check if the user is in the location whitelist."""
Expand Down Expand Up @@ -432,28 +395,27 @@ def jira_ticket(request_data):
return Response({"ack": "Error reading request type"}, status=400)

tags_data = request_data.get("tags").split(",") if request_data.get("tags") else []
components_data = (
request_data.get("components").split(",")
if request_data.get("components")

components_ids = (
request_data.get("components_ids").split(",")
if request_data.get("components_ids")
else []
)
components_ids = [OLE_JIRA_OBS_COMPONENTS_FIELDS[c] for c in components_data]
primary_software_component_data = request_data.get(
"primary_software_components", "None"
primary_software_components_ids = (
request_data.get("primary_software_components_ids").split(",")
if request_data.get("primary_software_components_ids")
else None
)
primary_software_component_id = OLE_JIRA_OBS_PRIMARY_SOFTWARE_COMPONENT_FIELDS[
primary_software_component_data
]
primary_hardware_component_data = request_data.get(
"primary_hardware_components", "None"
primary_hardware_components_ids = (
request_data.get("primary_hardware_components_ids").split(",")
if request_data.get("primary_hardware_components_ids")
else None
)
primary_hardware_component_id = OLE_JIRA_OBS_PRIMARY_HARDWARE_COMPONENT_FIELDS[
primary_hardware_component_data
]

try:
jira_payload = {
"fields": {
"issuetype": {"id": 12302},
"project": {"id": os.environ.get("JIRA_PROJECT_ID")},
"labels": [
"LOVE",
Expand All @@ -465,9 +427,17 @@ def jira_ticket(request_data):
if int(request_data.get("level", 0)) >= 100
else "off",
"customfield_16702": float(request_data.get("time_lost", 0)),
"customfield_17204": {"id": str(primary_software_component_id)},
"customfield_17205": {"id": str(primary_hardware_component_id)},
"issuetype": {"id": 12302},
# Default values of the following fields are set to -1
"customfield_17204": {
"id": str(primary_software_components_ids[0])
if primary_software_components_ids
else "-1"
},
"customfield_17205": {
"id": str(primary_hardware_components_ids[0])
if primary_hardware_components_ids
else "-1"
},
},
"update": {
"components": [{"set": [{"id": str(id)} for id in components_ids]}]
Expand Down

0 comments on commit 72c8744

Please sign in to comment.