feat(tempo): harden worklog sync and add tests [FASE-1.4]

Add tempo-api-python-client dependency, TEMPO_API_VERSION setting, enum-safe Jira link lookup, work type on create_worklog, and mocked auto_log tests.
This commit is contained in:
2026-05-18 13:36:26 +02:00
parent b8c9c4ac6a
commit 03d7d1cc80
4 changed files with 82 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ from sqlalchemy.orm import Session
from app.config import settings
from app.domain.exceptions import InvalidOperationError
from app.models.jira_link import JiraLink
from app.models.jira_link import JiraLink, JiraLinkEntityType
logger = logging.getLogger(__name__)
@@ -33,17 +33,21 @@ def log_worklog(
date: str,
time_spent_seconds: int,
description: str,
work_type: str | None = None,
) -> dict:
"""Create a worklog entry in Tempo."""
tempo = get_tempo_client()
worklog = tempo.create_worklog(
accountId=author_account_id,
issueId=jira_issue_id,
dateFrom=date,
timeSpentSeconds=time_spent_seconds,
description=description,
)
return worklog
kwargs: dict = {
"accountId": author_account_id,
"issueId": jira_issue_id,
"dateFrom": date,
"timeSpentSeconds": time_spent_seconds,
"description": description,
}
wt = work_type or settings.TEMPO_DEFAULT_WORK_TYPE
if wt:
kwargs["workType"] = wt
return tempo.create_worklog(**kwargs)
def auto_log_test_worklog(
@@ -61,7 +65,10 @@ def auto_log_test_worklog(
link = (
db.query(JiraLink)
.filter(JiraLink.entity_id == test.id, JiraLink.entity_type == "test")
.filter(
JiraLink.entity_id == test.id,
JiraLink.entity_type == JiraLinkEntityType.test,
)
.first()
)
@@ -77,7 +84,9 @@ def auto_log_test_worklog(
result = log_worklog(
jira_issue_id=int(link.jira_issue_id),
author_account_id=getattr(user, "jira_account_id", "") or "",
date=test.created_at.strftime("%Y-%m-%d"),
date=(getattr(test, "updated_at", None) or test.created_at).strftime(
"%Y-%m-%d",
),
time_spent_seconds=duration,
description=f"[Aegis] {activity_type}: {test.name}",
)