Skip to content

Commit

Permalink
Fix issue with adding float and str on update_time_lost method
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-aranda committed Aug 27, 2024
1 parent ee8cac7 commit 2b12abf
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions manager/manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,25 +532,24 @@ def update_time_lost(jira_id: int, add_time_lost: float = 0.0) -> Response:
}
url = f"https://{os.environ.get('JIRA_API_HOSTNAME')}/rest/api/latest/issue/{jira_id}/"
response = requests.get(url, headers=headers)
existent_time_lost = (
response.json().get(TIME_LOST_FIELD, 0.0)
if response.status_code == 200
else 0.0
)
jira_payload = {
"fields": {
TIME_LOST_FIELD: float(existent_time_lost + add_time_lost),
},
}
response = requests.put(url, json=jira_payload, headers=headers)
if response.status_code == 204:
return Response(
{
"ack": "Jira time_lost field updated",
"url": f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/{jira_id}",

if response.status_code == 200:
jira_ticket_fields = response.json().get("fields", {})
existent_time_lost = float(jira_ticket_fields.get(TIME_LOST_FIELD, 0.0))
jira_payload = {
"fields": {
TIME_LOST_FIELD: existent_time_lost + add_time_lost,
},
status=200,
)
}
response = requests.put(url, json=jira_payload, headers=headers)
if response.status_code == 204:
return Response(
{
"ack": "Jira time_lost field updated",
"url": f"https://{os.environ.get('JIRA_API_HOSTNAME')}/browse/{jira_id}",
},
status=200,
)
return Response(
{
"ack": "Jira time_lost field could not be updated",
Expand Down Expand Up @@ -603,7 +602,7 @@ def jira_comment(request_data):
response = requests.post(url, json=jira_payload, headers=headers)
if "time_lost" in request_data:
timelost_response = update_time_lost(
jira_id=jira_id, add_time_lost=request_data.get("time_lost", 0.0)
jira_id=jira_id, add_time_lost=float(request_data.get("time_lost", 0.0))
)
if timelost_response.status_code != 200:
return timelost_response
Expand Down

0 comments on commit 2b12abf

Please sign in to comment.