33import typing
44from typing import Any
55
6- from pydantic import computed_field
6+ from pydantic import (
7+ AliasChoices ,
8+ Field ,
9+ computed_field ,
10+ field_validator ,
11+ model_validator ,
12+ )
713import requests
814import urllib3
915
@@ -27,12 +33,42 @@ class YoutrackConfig(config.ServiceConfig):
2733 incloud_instance : bool = False
2834 query : str = 'for:me #Unresolved'
2935 query_limit : int = 100
30- import_tags : bool = True
31- tag_template : str = '{{tag|lower}}'
36+ import_labels_as_tags : bool = Field (
37+ True , validation_alias = AliasChoices ('import_labels_as_tags' , 'import_tags' )
38+ )
39+ label_template : str = Field (
40+ '{{label|lower}}' ,
41+ validation_alias = AliasChoices ('label_template' , 'tag_template' ),
42+ )
3243
3344 only_if_assigned : config .UnsupportedOption [str ] = ''
3445 also_unassigned : config .UnsupportedOption [bool ] = False
3546
47+ @model_validator (mode = 'before' )
48+ @classmethod
49+ def deprecate_legacy_tag_options (cls , values : Any ) -> Any :
50+ if not isinstance (values , dict ):
51+ return values
52+
53+ if 'import_tags' in values :
54+ log .warning ('import_tags is deprecated in favor of import_labels_as_tags' )
55+ if 'tag_template' in values :
56+ log .warning ('tag_template is deprecated in favor of label_template' )
57+
58+ template = values .get ('label_template' , values .get ('tag_template' ))
59+ if isinstance (template , str ) and 'tag' in template :
60+ log .warning (
61+ "The 'tag' variable in YouTrack label templates is deprecated "
62+ "in favor of 'label'."
63+ )
64+
65+ return values
66+
67+ @field_validator ('label_template' , mode = 'after' )
68+ @classmethod
69+ def migrate_legacy_tag_template (cls , value : str ) -> str :
70+ return value .replace ('tag' , 'label' )
71+
3672 @computed_field
3773 @property
3874 def base_url (self ) -> str :
@@ -103,10 +139,7 @@ def get_default_description(self) -> str:
103139
104140 def get_tags (self ) -> list [str ]:
105141 return self .get_tags_from_labels (
106- [tag ['name' ] for tag in self .record .get ('tags' , [])],
107- toggle_option = 'import_tags' ,
108- template_option = 'tag_template' ,
109- template_variable = 'tag' ,
142+ [tag ['name' ] for tag in self .record .get ('tags' , [])]
110143 )
111144
112145
0 commit comments