fix(tempo): use search_worklogs(authorIds) in test endpoint
Some checks failed
Aegis CI / lint-and-test (push) Has been cancelled

get_worklogs_by_account_id does not exist in tempoapiclient v4.
The correct method is search_worklogs(dateFrom, dateTo, authorIds=[...]).
Also improve error messages: 401 points to where to get the token,
404 tells the user the Account ID may be wrong.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kitos
2026-05-27 11:25:15 +02:00
parent bd0586d296
commit 44ef4129a5

View File

@@ -390,26 +390,41 @@ def test_tempo_connection(
try:
from tempoapiclient import client_v4 as tempo_client
tempo = tempo_client.Tempo(auth_token=tempo_token)
# Use a minimal date range to verify connectivity without fetching much data
worklogs = tempo.get_worklogs_by_account_id(
account_id=jira_account_id,
# search_worklogs by authorId is the correct v4 method; use a tight
# date range so we fetch almost nothing but still verify connectivity.
worklogs = tempo.search_worklogs(
dateFrom="2024-01-01",
dateTo="2024-01-02",
authorIds=[jira_account_id],
)
count = len(worklogs) if isinstance(worklogs, list) else "n/a"
return {
"status": "ok",
"message": f"Tempo connected. Account ID: {jira_account_id}",
"worklogs_found": len(worklogs) if isinstance(worklogs, list) else "n/a",
"message": f"Tempo connected successfully. Account ID: {jira_account_id}",
"worklogs_found": count,
}
except Exception as exc:
err = str(exc)
if "401" in err or "Unauthorized" in err:
msg = "Authentication failed (401). Check your Tempo API token."
msg = (
f"Authentication failed (401). "
f"Check your Tempo API token — obtain it at "
f"Jira → Apps → Tempo → Settings → API Integration."
)
elif "403" in err or "Forbidden" in err:
msg = "Access denied (403). The token may not have the required Tempo permissions."
msg = "Access denied (403). The Tempo token lacks the required permissions."
elif "404" in err or "not found" in err.lower():
msg = (
f"Account ID not found (404). "
f"The value '{jira_account_id}' may be wrong — see the instructions "
f"below to find your correct Atlassian Account ID."
)
else:
msg = f"Tempo connection failed: {err}"
logger.warning("Tempo test connection failed for user %s: %s", current_user.username, err)
logger.warning(
"Tempo test connection failed for user %s (account_id=%s): %s",
current_user.username, jira_account_id, err,
)
return {"status": "error", "message": msg}