added clockify check to app launch

This commit is contained in:
Jakub Trllo 2019-03-11 16:43:00 +01:00
parent a88c14b723
commit 3fb4f30e9b

View file

@ -146,6 +146,25 @@ class AppAction(BaseHandler):
entity = entities[0]
project_name = entity['project']['full_name']
# Validate Clockify settings if Clockify is required
clockify_timer = os.environ.get('CLOCKIFY_WORKSPACE', None)
if clockify_timer is not None:
from pype.clockify import ClockifyAPI
clockapi = ClockifyAPI()
if clockapi.verify_api() is False:
title = 'Launch message'
header = '# You Can\'t launch **any Application**'
message = (
'<p>You don\'t have set Clockify API'
' key in Clockify settings</p>'
)
items = [
{'type': 'label', 'value': header},
{'type': 'label', 'value': message}
]
self.show_interface(event, items, title)
return False
database = pypelib.get_avalon_database()
# Get current environments
@ -293,6 +312,29 @@ class AppAction(BaseHandler):
self.log.info('Starting timer for task: ' + task['name'])
user.start_timer(task, force=True)
# RUN TIMER IN Clockify
if clockify_timer is not None:
task_name = task['name']
project_name = task['project']['full_name']
def get_parents(entity):
output = []
if entity.entity_type.lower() == 'project':
return output
output.extend(get_parents(entity['parent']))
output.append(entity['name'])
return output
desc_items = get_parents(task['parent'])
description = '/'.join(desc_items)
project_id = clockapi.get_project_id(project_name)
task_id = clockapi.get_task_id(task_name, project_id)
clockapi.start_time_entry(
description, project_id, task_id,
)
# Change status of task to In progress
config = get_config_data()