Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status change on user action #73

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5646155
Now when we scart task from AYON we see WIP status
timsergeeff Aug 15, 2024
8be86c8
Update pre_status_cahnge.py
timsergeeff Aug 15, 2024
16809f4
Apply suggestions from code review
timsergeeff Aug 15, 2024
f520094
Feature status change on user actions
timsergeeff Sep 6, 2024
0f80294
q
timsergeeff Sep 6, 2024
1986328
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
1ef9986
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
a30a67d
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
951c874
Update package.py
timsergeeff Sep 9, 2024
3a54d77
Update server/settings/publish_plugins.py
timsergeeff Sep 9, 2024
6e079ff
Update server/settings/app_start.py
timsergeeff Sep 9, 2024
7522617
Update server/settings/app_start.py
timsergeeff Sep 9, 2024
871c1c4
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
51be2e8
Update client/ayon_kitsu/version.py
timsergeeff Sep 9, 2024
792d097
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
324d1fd
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
01d0a78
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
ebea911
Update client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
timsergeeff Sep 9, 2024
ab37014
Update client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
timsergeeff Sep 9, 2024
f8aecab
Update client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
timsergeeff Sep 9, 2024
199ce1c
Update client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
timsergeeff Sep 9, 2024
2e63589
Update client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
timsergeeff Sep 9, 2024
ca06642
Update client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
timsergeeff Sep 9, 2024
2735be6
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
e18410f
Update client/ayon_kitsu/addon.py
timsergeeff Sep 9, 2024
7028b6a
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
7a1c455
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
1a55b6f
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
fd68f03
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
1bd7d5a
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
6bbd396
Update server/settings/app_start.py
timsergeeff Sep 9, 2024
1447316
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
934fd0f
Update client/ayon_kitsu/hooks/pre_status_cahnge.py
timsergeeff Sep 9, 2024
55a585e
Rename pre_status_cahnge.py to pre_status_change.py
timsergeeff Sep 10, 2024
e1af2da
Update integrate_kitsu_note.py
timsergeeff Sep 10, 2024
fe825c0
Merge branch 'ynput:develop' into feature
timsergeeff Oct 29, 2024
d887d10
fix render farm instance tag
timsergeeff Oct 29, 2024
8abe493
fix farm render target using instace farm
timsergeeff Oct 29, 2024
bd7ed98
Merge branch 'feature' of https://github.com/timsergeeff/ayon-kitsu i…
timsergeeff Oct 29, 2024
87ef0d5
Update addon.py
timsergeeff Oct 29, 2024
653c0bb
Update version.py
timsergeeff Oct 29, 2024
1d0cf22
Update package.py
timsergeeff Oct 29, 2024
3c66ba9
Update pre_status_change.py
timsergeeff Oct 29, 2024
2cfc432
Update pre_status_change.py
timsergeeff Oct 29, 2024
2df77f4
fix tests
timsergeeff Oct 29, 2024
623c5b3
tests
timsergeeff Oct 30, 2024
a3b8bdf
tests
timsergeeff Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __pycache__
.vscode
poetry.lock
package/
package.py

frontend/node_modules
frontend/dist
Expand Down
4 changes: 3 additions & 1 deletion client/ayon_kitsu/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ def get_plugin_paths(self):

return {
"publish": self.get_publish_plugin_paths(),
"hooks": self.get_launch_hook_paths(),
# The laucher action is not working since AYON conversion
# "actions": [os.path.join(KITSU_ROOT, "plugins", "launcher")],
}

def get_publish_plugin_paths(self, host_name=None):
return [os.path.join(KITSU_ROOT, "plugins", "publish")]

def get_launch_hook_paths(self, host_name=None):
return [os.path.join(KITSU_ROOT, "hooks")]

def is_kitsu_enabled_in_settings(project_settings):
"""Check if kitsu is enabled in kitsu project settings.
Expand Down
107 changes: 107 additions & 0 deletions client/ayon_kitsu/hooks/pre_status_change.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from ayon_applications import PostLaunchHook

import os
import gazu

class PreKitsuStatusChange(PostLaunchHook):
"""On launch of an application change task statuses on Kitsu.

When launching an application this launch hook may change the
status on Kitsu with the relevant task id.

If "pause other tasks" is enabled this will also change the status of
all other tasks to the paused task status. This can be useful for
X, Y, Z.
"""
order = 1
launch_types = set()

# status settings
set_status_app_start_note = False
app_start_status_shortname = "wip"
status_change_conditions = {
"status_conditions": []
}

# comment settings
custom_comment_template = {
"enabled": False,
"comment_template": "{comment}",
}
def execute(self):
if "KITSU_LOGIN" not in os.environ:
self.log.info(
"KITSU_LOGIN is not set. assuming rendeing in deadline. Skipping status."
)
return

data = self.launch_context.data
project_settings = data["project_settings"]["kitsu"]["appstart"]

if project_settings["set_status_app_start_note"]:
self.log.info("Kitsu Status change is Enabled.")
else:
self.log.info("Kitsu Status change is disabled.")
return

if not project_settings["app_start_status_shortname"]:
self.log.info("App starting status in not configured")
return
app_start_status_shortname= project_settings[
"app_start_status_shortname"
]

if project_settings["app_startstatus_change_conditions"]:
status_conditions= project_settings["app_startstatus_change_conditions"]
else:
self.log.info("Status change condotions are empty")

gazu.set_host(os.environ["KITSU_SERVER"])
gazu.log_in(os.environ["KITSU_LOGIN"], os.environ["KITSU_PWD"])

if not self.data["task_entity"]["data"].get("kitsuId"):
self.log.info("This task does not have a kitsu task id. Skipping kitsu task status change.")
return

kitsuId = self.data["task_entity"]["data"]["kitsuId"]
task=gazu.task.get_task(kitsuId)
task_current_status_shortname= task["task_status"]["short_name"]

# Check if any status condition is not met
allow_status_change = True
for status_cond in status_conditions:
condition = status_cond["condition"] == "equal"
match = status_cond["short_name"] == task_current_status_shortname
if match and not condition or condition and not match:
allow_status_change = False
break

if allow_status_change:
if not gazu.task.get_task_status_by_short_name(self.app_start_status_shortname):
self.log.info("Failed to recieve kitsu status instance for shortname. Skipping Status change.")
return
Comment on lines +80 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A “line too long” happens when the number of the characters per line exceeds the maximum number specified in repo.

line-length = 79

personally, I prefer to have some display in my IDE to tell me the number of characters in my line.
image

Fixes are mostly like

Suggested change
if not gazu.task.get_task_status_by_short_name(self.app_start_status_shortname):
self.log.info("Failed to recieve kitsu status instance for shortname. Skipping Status change.")
return
if not gazu.task.get_task_status_by_short_name(
self.app_start_status_shortname
):
self.log.info(
"Failed to recieve kitsu status instance for shortname."
" Skipping Status change."
)
return

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also even better - if you setup strict linter rules in an IDE (code editor) you can have it auto-correct the formatting for you. That way you don't need to do this manually.

kitsu_wip_status = gazu.task.get_task_status_by_short_name(self.app_start_status_shortname)

self.log.info("Current Kitsu task status is {task_current_status_shortname}. Task id {kitsuId}")
self.log.info("Changing Kitsu task status to {self.app_start_status_shortname}.")

gazu.task.add_comment(task["id"], kitsu_wip_status)

if not project_settings["set_pause_status_to_other_tasks"]:
self.log.info("Pausing all other tasks with same status disabled.")
else:
self.log.info("Pausing all other tasks with same status enabled.")
pause_status_shortname= project_settings["pause_status_shortname"]
if gazu.task.get_task_status_by_short_name(pause_status_shortname):
pause_status=gazu.task.get_task_status_by_short_name(pause_status_shortname)
user_tasks= gazu.user.all_tasks_to_do()
for other_task in user_tasks:
same_status = other_task["task_status_short_name"] == app_start_status_shortname
same_task = other_task["id"] == kitsuId
if same_status and not same_task:
gazu.task.add_comment(other_task["id"], pause_status,)
else:
self.log.info("Failed to recieve kitsu pause status instance. Skipping pause Status change.")
else:
self.log.info("Status not changed due to conditions: {status_conditions}")
gazu.log_out()
22 changes: 21 additions & 1 deletion client/ayon_kitsu/plugins/publish/integrate_kitsu_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class IntegrateKitsuNote(KitsuPublishContextPlugin):

order = pyblish.api.IntegratorOrder
label = "Kitsu Note and Status"
families = ["kitsu"]
families = ["*"]

# status settings
set_status_note = False
Expand All @@ -27,6 +27,8 @@ class IntegrateKitsuNote(KitsuPublishContextPlugin):
"enabled": False,
"comment_template": "{comment}",
}
set_status_note_farm = False
note_farm_status_shortname = "farm"

timsergeeff marked this conversation as resolved.
Show resolved Hide resolved
def format_publish_comment(self, instance):
"""Format the instance's publish comment
Expand Down Expand Up @@ -62,16 +64,34 @@ def process(self, context):
"family_requirements"
]

farm_status_change = False

families= []

for instance in context:
if instance.data.get("farm"):
farm_status_change = True

self.log.debug(f'Instance in context has farm flag: {farm_status_change}')

if farm_status_change and self.set_status_note_farm:
kitsu_task = instance.data.get("kitsuTask")
farm_status = gazu.task.get_task_status_by_short_name(self.note_farm_status_shortname)
gazu.task.add_comment(kitsu_task, farm_status)
return

for instance in context:
# Check if instance is a review by checking its family
# Allow a match to primary family or any of families
families = set(
[instance.data["family"]] + instance.data.get("families", [])
)

if "review" not in families or "kitsu" not in families:
continue

kitsu_task = instance.data.get("kitsuTask")

if not kitsu_task:
continue

Expand Down
34 changes: 34 additions & 0 deletions server/settings/app_start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from ayon_server.settings import BaseSettingsModel, SettingsField


def _status_change_cond_enum():
return [
{"value": "equal", "label": "Equal"},
{"value": "not_equal", "label": "Not equal"},
]


class AppStartStatusChangeCondition(BaseSettingsModel):
condition: str = SettingsField(
"equal", enum_resolver=_status_change_cond_enum, title="Condition"
)
short_name: str = SettingsField("", title="Short name")


class AppStartStatusChange(BaseSettingsModel):
set_status_app_start_note: bool = SettingsField(title="Set status change on app start")
app_start_status_shortname: str = SettingsField(title="App start Status shortname")
app_startstatus_change_conditions: list[AppStartStatusChangeCondition] = SettingsField(
default_factory=AppStartStatusChangeCondition, title="App start status change conditions"
)
set_pause_status_to_other_tasks: bool = SettingsField(title="Set pause status to other tasks")
pause_status_shortname: str = SettingsField(title="Pause Status shortname")


APPSTART_DEFAULT_VALUES = {
"set_status_app_start_note": False,
"app_start_status_shortname": "wip",
"app_startstatus_change_conditions": [],
"set_pause_status_to_other_tasks": False,
"pause_status_shortname": "pause",
}
6 changes: 6 additions & 0 deletions server/settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .sync_settings import SyncSettings, SYNC_DEFAULT_VALUES
from .publish_plugins import PublishPlugins, PUBLISH_DEFAULT_VALUES
from .app_start import AppStartStatusChange, APPSTART_DEFAULT_VALUES


## Entities naming pattern
Expand Down Expand Up @@ -43,6 +44,10 @@ class KitsuSettings(BaseSettingsModel):
default_factory=EntityPattern,
title="Entities naming pattern",
)
appstart: AppStartStatusChange = SettingsField(
default_factory=AppStartStatusChange,
title="App start status change",
)
publish: PublishPlugins = SettingsField(
default_factory=PublishPlugins,
title="Publish plugins",
Expand All @@ -59,6 +64,7 @@ class KitsuSettings(BaseSettingsModel):
"sequence": "SQ##",
"shot": "SH##",
},
"appstart": APPSTART_DEFAULT_VALUES,
"publish": PUBLISH_DEFAULT_VALUES,
"sync_settings": SYNC_DEFAULT_VALUES,
}
4 changes: 4 additions & 0 deletions server/settings/publish_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class IntegrateKitsuNotes(BaseSettingsModel):
default_factory=CustomCommentTemplateModel,
title="Custom Comment Template",
)
set_status_note_farm: bool = SettingsField(title="Set status on note farm")
note_farm_status_shortname: str = SettingsField(title="Note farm shortname")


class PublishPlugins(BaseSettingsModel):
Expand Down Expand Up @@ -294,5 +296,7 @@ class PublishPlugins(BaseSettingsModel):
| family | `{family}` |
| name | `{name}` |""",
},
"set_status_note_farm": False,
"note_farm_status_shortname": "farm"
}
}
Loading