Skip to content

Commit

Permalink
Merge pull request #239 from lsst-ts/tickets/DM-42871
Browse files Browse the repository at this point in the history
Adjustments for the JIRA Cloud REST API interface
  • Loading branch information
sebastian-aranda authored Feb 27, 2024
2 parents 0f092be + 5252042 commit 4d2675a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Version History
===============

v5.17.3
-------

* Adjustments for new JIRA Cloud REST API interface `<https://github.com/lsst-ts/LOVE-manager/pull/239>`_

v5.17.2
-------

Expand Down
33 changes: 27 additions & 6 deletions manager/api/tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


import math
import os
import random
from unittest.mock import patch

Expand Down Expand Up @@ -282,6 +283,7 @@ def test_missing_parameters(self):
jira_response = jira_ticket(self.jira_request_narrative_without_param.data)
assert "Error creating jira payload" in jira_response.data["ack"]

@patch.dict(os.environ, {"JIRA_API_HOSTNAME": "jira.lsstcorp.org"})
def test_needed_parameters(self):
"""Test call to jira_ticket function with all needed parameters"""
mock_jira_patcher = patch("requests.post")
Expand All @@ -294,12 +296,18 @@ def test_needed_parameters(self):
jira_response = jira_ticket(self.jira_request_exposure_full.data)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira ticket created"
assert jira_response.data["url"] == "https://jira.lsstcorp.org/browse/LOVE-XX"
assert (
jira_response.data["url"]
== f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/LOVE-XX"
)

jira_response = jira_ticket(self.jira_request_narrative_full.data)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira ticket created"
assert jira_response.data["url"] == "https://jira.lsstcorp.org/browse/LOVE-XX"
assert (
jira_response.data["url"]
== f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/LOVE-XX"
)

mock_jira_patcher.stop()

Expand All @@ -319,6 +327,7 @@ def test_add_comment(self):
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira comment created"

@patch.dict(os.environ, {"JIRA_API_HOSTNAME": "jira.lsstcorp.org"})
def test_handle_narrative_jira_payload(self):
"""Test call to function handle_jira_payload with all needed parameters
for narrative request type
Expand All @@ -333,14 +342,20 @@ def test_handle_narrative_jira_payload(self):
jira_response = handle_jira_payload(self.jira_request_narrative_full_jira_new)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira ticket created"
assert jira_response.data["url"] == "https://jira.lsstcorp.org/browse/LOVE-XX"
assert (
jira_response.data["url"]
== f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/LOVE-XX"
)

jira_response = handle_jira_payload(
self.jira_request_narrative_full_jira_comment
)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira comment created"
assert jira_response.data["url"] == "https://jira.lsstcorp.org/browse/LOVE-XX"
assert (
jira_response.data["url"]
== f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/LOVE-XX"
)

mock_jira_patcher.stop()

Expand All @@ -358,13 +373,19 @@ def test_handle_exposure_jira_payload(self):
jira_response = handle_jira_payload(self.jira_request_exposure_full_jira_new)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira ticket created"
assert jira_response.data["url"] == "https://jira.lsstcorp.org/browse/LOVE-XX"
assert (
jira_response.data["url"]
== f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/LOVE-XX"
)

jira_response = handle_jira_payload(
self.jira_request_exposure_full_jira_comment
)
assert jira_response.status_code == 200
assert jira_response.data["ack"] == "Jira comment created"
assert jira_response.data["url"] == "https://jira.lsstcorp.org/browse/LOVE-XX"
assert (
jira_response.data["url"]
== f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/LOVE-XX"
)

mock_jira_patcher.stop()
53 changes: 34 additions & 19 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,19 @@ def get_jira_description(request_data):


def jira_ticket(request_data):
"""Connects to JIRA API to create a ticket on a specific project.
For more information on issuetypes refer to:
https://jira.lsstcorp.org/rest/api/latest/issuetype/?projectId=JIRA_PROJECT_ID
"""Connect to the Rubin Observatory JIRA Cloud REST API to
create a ticket on the OBS project.
For more information on the issue creation payload refer to:
https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post
For details on the fields available for the JIRA Cloud REST API see:
- https://rubinobs.atlassian.net/rest/api/latest/field
For details on the OBS project see:
- https://rubinobs.atlassian.net/rest/api/latest/project/OBS
For more information on the REST API endpoints refer to:
- https://developer.atlassian.com/cloud/jira/platform/rest/v3
- https://developer.atlassian.com/cloud/jira/platform/\
basic-auth-for-rest-apis/
Params
------
Expand Down Expand Up @@ -417,27 +424,32 @@ def jira_ticket(request_data):
try:
jira_payload = {
"fields": {
"issuetype": {"id": 12302},
"project": {"id": os.environ.get("JIRA_PROJECT_ID")},
"issuetype": {"id": "10065"},
"project": {"id": "10037"},
"labels": [
"LOVE",
*tags_data,
],
"summary": get_jira_title(request_data),
"description": get_jira_description(request_data),
"customfield_15602": (
"on" if int(request_data.get("level", 0)) >= 100 else "off"
),
"customfield_16702": float(request_data.get("time_lost", 0)),
# customfield_15602 which represents the URGENT flag
# is not yet migrated to the new JIRA cloud OBS project.
# The following block is commented until the migration is done.
# TODO: DM-43066
# "customfield_15602": (
# "on" if int(request_data.get("level", 0)) >= 100
# else "off"
# ),
"customfield_10106": float(request_data.get("time_lost", 0)),
# Default values of the following fields are set to -1
"customfield_17204": {
"customfield_10107": {
"id": (
str(primary_software_components_ids[0])
if primary_software_components_ids
else "-1"
)
},
"customfield_17205": {
"customfield_10196": {
"id": (
str(primary_hardware_components_ids[0])
if primary_hardware_components_ids
Expand Down Expand Up @@ -470,7 +482,7 @@ def jira_ticket(request_data):
return Response(
{
"ack": "Jira ticket created",
"url": f"https://jira.lsstcorp.org/browse/{response_data['key']}",
"url": f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/{response_data['key']}",
},
status=200,
)
Expand All @@ -485,10 +497,13 @@ def jira_ticket(request_data):


def jira_comment(request_data):
"""Connects to JIRA API to add a comment to
a previously created ticket on a specific project.
For more information on issuetypes refer to:
ttps://jira.lsstcorp.org/rest/api/latest/issuetype/?projectId=JIRA_PROJECT_ID
"""Connect to the Rubin Observatory JIRA Cloud REST API to
make a comment on a previously created ticket.
For more information on the REST API endpoints refer to:
- https://developer.atlassian.com/cloud/jira/platform/rest/v3
- https://developer.atlassian.com/cloud/jira/platform/\
basic-auth-for-rest-apis/
Params
------
Expand Down Expand Up @@ -527,7 +542,7 @@ def jira_comment(request_data):
return Response(
{
"ack": "Jira comment created",
"url": f"https://jira.lsstcorp.org/browse/{jira_id}",
"url": f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/{jira_id}",
},
status=200,
)
Expand Down

0 comments on commit 4d2675a

Please sign in to comment.