clockify use folder and task entity

This commit is contained in:
Jakub Trllo 2024-03-04 17:46:11 +01:00
parent 9b86afb4fa
commit 262cbda493
2 changed files with 20 additions and 32 deletions

View file

@ -3,7 +3,6 @@ import threading
import time
from ayon_core.modules import AYONAddon, ITrayModule, IPluginPaths
from ayon_core.client import get_asset_by_name
from .constants import CLOCKIFY_FTRACK_USER_PATH, CLOCKIFY_FTRACK_SERVER_PATH
@ -255,33 +254,27 @@ class ClockifyModule(AYONAddon, ITrayModule, IPluginPaths):
if not self.clockify_api.get_api_key():
return
project_name = input_data.get("project_name")
folder_path = input_data.get("folder_path")
task_name = input_data.get("task_name")
task_type = input_data.get("task_type")
if not all((project_name, folder_path, task_name, task_type)):
return
# Concatenate hierarchy and task to get description
description_items = list(input_data.get("hierarchy", []))
description_items.append(task_name)
description = "/".join(description_items)
description = "/".join([folder_path.lstrip("/"), task_name])
# Check project existence
project_name = input_data.get("project_name")
project_id = self._verify_project_exists(project_name)
if not project_id:
return
# Setup timer tags
tag_ids = []
tag_name = input_data.get("task_type")
if not tag_name:
# no task_type found in the input data
# if the timer is restarted by idle time (bug?)
asset_name = input_data["hierarchy"][-1]
asset_doc = get_asset_by_name(project_name, asset_name)
task_info = asset_doc["data"]["tasks"][task_name]
tag_name = task_info.get("type", "")
if not tag_name:
self.log.info("No tag information found for the timer")
if not task_type:
self.log.info("No tag information found for the timer")
task_tag_id = self.clockify_api.get_tag_id(tag_name)
tag_ids = []
task_tag_id = self.clockify_api.get_tag_id(task_type)
if task_tag_id is not None:
tag_ids.append(task_tag_id)

View file

@ -1,4 +1,5 @@
from ayon_core.client import get_asset_by_name
import ayon_api
from ayon_core.pipeline import LauncherAction
from openpype_modules.clockify.clockify_api import ClockifyAPI
@ -21,24 +22,18 @@ class ClockifyStart(LauncherAction):
user_id = self.clockify_api.user_id
workspace_id = self.clockify_api.workspace_id
project_name = session["AYON_PROJECT_NAME"]
asset_name = session["AYON_FOLDER_PATH"]
folder_path = session["AYON_FOLDER_PATH"]
task_name = session["AYON_TASK_NAME"]
description = asset_name
description = "/".join([folder_path.lstrip("/"), task_name])
# fetch asset docs
asset_doc = get_asset_by_name(project_name, asset_name)
# fetch folder entity
folder_entity = ayon_api.get_folder_by_path(project_name, folder_path)
task_entity = ayon_api.get_task_by_name(
project_name, folder_entity["id"], task_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)
task_type = task_entity["taskType"]
project_id = self.clockify_api.get_project_id(
project_name, workspace_id