ayon-core/openpype/modules/clockify/launcher_actions/ClockifyStart.py
Alexey Bogomolov 249bda0c80
Clockify: refresh and fix the integration (#4607)
* WIP clockify fix

* WIP disable wp validation, make sync work

* fix launcher start timer action

* fix finish time entry

* fix start and stop timers, cleanup, add TODO

* show task name and type in description, add TODO

* change rate limiter constants

* black formatting

* remove task type from data

* cleanup debug prints

* fix hound comments

* remove unused import

* move ids to property, fix user validation

* remove f-strings, rollback description parsing

* attempt to fix ftrack actions

* check if sync action got some projects

* get api data on process

* remove unused variable

* remove ratelimiter dependency

* add response validation

* a bit cleanup

* Update openpype/modules/clockify/clockify_module.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* Update openpype/modules/clockify/clockify_api.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* Update openpype/modules/clockify/clockify_api.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* Update openpype/modules/clockify/clockify_api.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* Update openpype/modules/clockify/ftrack/server/action_clockify_sync_server.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* replace dunders with underscores

* remove excessive variables

* update set_user_id

* continue check_running if no timer found

* bring back come py2 compatibility

* cleanup

* get values directly from clockapi

* hound

* get task type to fill the tag field correctly

* add logger, catch some json errors

* remove check running timer, add project_id verification module

* add current task_id check

* remove package entries

* make method private, fix typo

* get task_type for the idle-restarted timer

* remove trailing whitespace

* show correct idle countdown values

* finx indentation

* Update openpype/modules/clockify/clockify_api.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* Update openpype/modules/clockify/clockify_module.py

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>

* revert lock file

* remove unused constants and redundant code

* import clockify_api inside the method

* do not query asset docs double time, add comments

* add permissions check fail Exception

* rename clockapi to clockify_api

* formatting

* removed unused variables

---------

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <jakub.trllo@gmail.com>
2023-03-17 11:41:32 +01:00

55 lines
1.9 KiB
Python

from openpype.client import get_asset_by_name
from openpype.pipeline import LauncherAction
from openpype_modules.clockify.clockify_api import ClockifyAPI
class ClockifyStart(LauncherAction):
name = "clockify_start_timer"
label = "Clockify - Start Timer"
icon = "app_icons/clockify.png"
order = 500
clockify_api = ClockifyAPI()
def is_compatible(self, session):
"""Return whether the action is compatible with the session"""
if "AVALON_TASK" in session:
return True
return False
def process(self, session, **kwargs):
self.clockify_api.set_api()
user_id = self.clockify_api.user_id
workspace_id = self.clockify_api.workspace_id
project_name = session["AVALON_PROJECT"]
asset_name = session["AVALON_ASSET"]
task_name = session["AVALON_TASK"]
description = asset_name
# fetch asset docs
asset_doc = get_asset_by_name(project_name, asset_name)
# get task type to fill the timer tag
task_info = asset_doc["data"]["tasks"][task_name]
task_type = task_info["type"]
# check if the task has hierarchy and fill the
parents_data = asset_doc["data"]
if parents_data is not None:
description_items = parents_data.get("parents", [])
description_items.append(asset_name)
description_items.append(task_name)
description = "/".join(description_items)
project_id = self.clockify_api.get_project_id(
project_name, workspace_id
)
tag_ids = []
tag_name = task_type
tag_ids.append(self.clockify_api.get_tag_id(tag_name, workspace_id))
self.clockify_api.start_time_entry(
description,
project_id,
tag_ids=tag_ids,
workspace_id=workspace_id,
user_id=user_id,
)