Skip to content

Commit

Permalink
Added function to query existing jira ticket for time lost
Browse files Browse the repository at this point in the history
  • Loading branch information
Vebop committed Aug 14, 2024
1 parent ec4273c commit cc4446e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,32 @@ def jira_ticket(request_data):
)


def get_time_lost_from_jira(jira_id):
"""Connect to the Rubin Observatory JIRA Cloud REST API to
retreive a jira ticket's time_lost attribute
Params
------
jira_id: int
Jira ID
Returns
-------
Float
The value of the time lost on the existing jira ticket, or 0.0
"""
headers = {
"Authorization": f"Basic {os.environ.get('JIRA_API_TOKEN')}",
"content-type": "application/json",
}
url = f"https://{os.environ.get('JIRA_API_HOSTNAME')}/rest/api/latest/issue/{jira_id}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.get("customfield_10106", 0.0)
else:
return 0.0


def jira_comment(request_data):
"""Connect to the Rubin Observatory JIRA Cloud REST API to
make a comment on a previously created ticket.
Expand Down Expand Up @@ -538,6 +564,12 @@ def jira_comment(request_data):
jira_payload = {
"body": get_jira_description(request_data),
}
if 'time_lost' in request_data:
jira_payload["feilds"]["customfield_10106"] = float(
get_time_lost_from_jira(jira_id=jira_id)
+ request_data.get("time_lost", 0.0)
)

except Exception as e:
return Response({"ack": f"Error creating jira payload: {e}"}, status=400)

Expand Down

0 comments on commit cc4446e

Please sign in to comment.