11import win32com .universal
22from logging import getLogger
3- from typing import Callable , Dict , List , Optional , overload
3+ from typing import Callable , Dict , List , Optional , Type , overload
44
55from syncgitlab2msproject .custom_types import WebURL
6+ from syncgitlab2msproject .helper_classes import TaskTyperSetter
67
78from .custom_types import IssueRef
89from .exceptions import (
@@ -79,9 +80,11 @@ def check_get_url(value: Optional[str]) -> Optional[WebURL]:
7980def update_task_with_issue_data (
8081 task : Task ,
8182 issue : Issue ,
83+ task_type_setter : Type [TaskTyperSetter ],
8284 * ,
8385 parent_ids : Optional [List [IssueRef ]] = None ,
8486 ignore_issue : bool = False ,
87+ is_add : bool = False ,
8588) -> List [IssueRef ]:
8689 """
8790 Update task with issue data
@@ -91,9 +94,11 @@ def update_task_with_issue_data(
9194 Args:
9295 task: The MS Project task that will be updated
9396 issue: the issue with the data to be considered
97+ task_type_setter: Helper class to set the task type correct
9498 parent_ids: the parent stuff
9599 ignore_issue: only return the related (and moved) ids but do not really sync
96100 This is required so we can ignored also moved issues correctly
101+ is_add:
97102
98103 Returns:
99104 list of IssueRefs that
@@ -107,7 +112,11 @@ def update_task_with_issue_data(
107112 assert moved_ref is not None
108113 try :
109114 return update_task_with_issue_data (
110- task , moved_ref , parent_ids = parent_ids , ignore_issue = ignore_issue
115+ task ,
116+ moved_ref ,
117+ task_type_setter ,
118+ parent_ids = parent_ids ,
119+ ignore_issue = ignore_issue ,
111120 )
112121 except MovedIssueNotDefined :
113122 logger .warning (
@@ -117,6 +126,8 @@ def update_task_with_issue_data(
117126 elif not ignore_issue :
118127 set_issue_ref_to_task (task , issue )
119128 try :
129+ type_setter = task_type_setter (issue )
130+ type_setter .set_task_type_before_sync (task , is_add )
120131 task .name = issue .title
121132 task .notes = issue .description
122133 if issue .due_date is not None :
@@ -135,6 +146,7 @@ def update_task_with_issue_data(
135146 task .text28 = "; " .join ([f'"{ label } "' for label in issue .labels ])
136147 if issue .is_closed :
137148 task .actual_finish = issue .closed_at
149+ type_setter .set_task_type_after_sync (task )
138150 except (MSProjectValueSetError , win32com .universal .com_error ) as e :
139151 logger .error (
140152 f"FATAL: Could not sync issue { issue } to task { task } .\n Error: { e } "
@@ -144,12 +156,14 @@ def update_task_with_issue_data(
144156 return parent_ids
145157
146158
147- def add_issue_as_task_to_project (tasks : MSProject , issue : Issue ):
159+ def add_issue_as_task_to_project (
160+ tasks : MSProject , issue : Issue , task_type_setter : Type [TaskTyperSetter ]
161+ ):
148162 task = tasks .add_task (issue .title )
149163 logger .info (f"Created { task } as it was missing for issue, now syncing it." )
150164 # Add a setting to allow forcing outline level on new tasks
151165 # task.outline_level = 1
152- update_task_with_issue_data (task , issue )
166+ update_task_with_issue_data (task , issue , task_type_setter , is_add = True )
153167
154168
155169class IssueFinder :
@@ -237,6 +251,7 @@ def sync_gitlab_issues_to_ms_project(
237251 tasks : MSProject ,
238252 issues : List [Issue ],
239253 gitlab_url : WebURL ,
254+ task_type_setter : Type [TaskTyperSetter ],
240255 include_issue : Optional [Callable [[Issue ], bool ]] = None ,
241256) -> None :
242257 """
@@ -295,7 +310,7 @@ def always_true(x: Issue):
295310 # added and we also want make sure that moved ignored issues are handled
296311 # correctly
297312 synced += update_task_with_issue_data (
298- task , ref_issue , ignore_issue = ignore_issue
313+ task , ref_issue , task_type_setter , ignore_issue = ignore_issue
299314 )
300315
301316 # adding everything that was not synced and is not duplicate
@@ -308,4 +323,4 @@ def always_true(x: Issue):
308323 f"as it has been marked to be ignored."
309324 )
310325 else :
311- add_issue_as_task_to_project (tasks , ref_issue )
326+ add_issue_as_task_to_project (tasks , ref_issue , task_type_setter )
0 commit comments