kaiten-cli 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kaiten_cli/__init__.py +5 -0
- kaiten_cli/__main__.py +9 -0
- kaiten_cli/agent_gateway.py +577 -0
- kaiten_cli/app.py +1636 -0
- kaiten_cli/completion.py +570 -0
- kaiten_cli/discovery.py +39 -0
- kaiten_cli/errors.py +79 -0
- kaiten_cli/i18n.py +92 -0
- kaiten_cli/locales/ru.json +2967 -0
- kaiten_cli/localized_click.py +160 -0
- kaiten_cli/models.py +202 -0
- kaiten_cli/profiles.py +316 -0
- kaiten_cli/registry/__init__.py +260 -0
- kaiten_cli/registry/addons.py +392 -0
- kaiten_cli/registry/audit_and_analytics.py +451 -0
- kaiten_cli/registry/automation_schema.py +44 -0
- kaiten_cli/registry/automation_schemas.json +7417 -0
- kaiten_cli/registry/automations.py +342 -0
- kaiten_cli/registry/base.py +62 -0
- kaiten_cli/registry/blockers.py +320 -0
- kaiten_cli/registry/boards.py +520 -0
- kaiten_cli/registry/card_relations.py +376 -0
- kaiten_cli/registry/card_types.py +363 -0
- kaiten_cli/registry/cards.py +1329 -0
- kaiten_cli/registry/charts.py +539 -0
- kaiten_cli/registry/checklists.py +600 -0
- kaiten_cli/registry/columns.py +558 -0
- kaiten_cli/registry/comments.py +224 -0
- kaiten_cli/registry/custom_directories.py +980 -0
- kaiten_cli/registry/custom_properties.py +1460 -0
- kaiten_cli/registry/dashboards.py +564 -0
- kaiten_cli/registry/documents.py +761 -0
- kaiten_cli/registry/external_links.py +128 -0
- kaiten_cli/registry/files.py +738 -0
- kaiten_cli/registry/github_addon.py +613 -0
- kaiten_cli/registry/iterations.py +397 -0
- kaiten_cli/registry/lanes.py +205 -0
- kaiten_cli/registry/live_contracts.py +361 -0
- kaiten_cli/registry/members.py +336 -0
- kaiten_cli/registry/module_docs.py +108 -0
- kaiten_cli/registry/projects.py +369 -0
- kaiten_cli/registry/query.py +129 -0
- kaiten_cli/registry/restrictions.py +249 -0
- kaiten_cli/registry/roles_and_groups.py +1102 -0
- kaiten_cli/registry/scim.py +263 -0
- kaiten_cli/registry/service_desk.py +1270 -0
- kaiten_cli/registry/snapshot.py +187 -0
- kaiten_cli/registry/spaces.py +272 -0
- kaiten_cli/registry/subscribers.py +168 -0
- kaiten_cli/registry/tags.py +193 -0
- kaiten_cli/registry/time_logs.py +353 -0
- kaiten_cli/registry/tree.py +352 -0
- kaiten_cli/registry/utilities.py +287 -0
- kaiten_cli/registry/webhooks.py +265 -0
- kaiten_cli/runtime/__init__.py +1 -0
- kaiten_cli/runtime/automation_validation.py +115 -0
- kaiten_cli/runtime/behaviors.py +787 -0
- kaiten_cli/runtime/cache.py +733 -0
- kaiten_cli/runtime/client.py +387 -0
- kaiten_cli/runtime/endpoints.py +59 -0
- kaiten_cli/runtime/executor.py +269 -0
- kaiten_cli/runtime/fs_security.py +168 -0
- kaiten_cli/runtime/input.py +310 -0
- kaiten_cli/runtime/output.py +59 -0
- kaiten_cli/runtime/public_validation.py +35 -0
- kaiten_cli/runtime/snapshot_build.py +527 -0
- kaiten_cli/runtime/snapshot_common.py +363 -0
- kaiten_cli/runtime/snapshot_query.py +306 -0
- kaiten_cli/runtime/snapshot_store.py +1192 -0
- kaiten_cli/runtime/snapshots.py +62 -0
- kaiten_cli/runtime/sqlite_errors.py +23 -0
- kaiten_cli/runtime/support/__init__.py +1 -0
- kaiten_cli/runtime/support/addons.py +953 -0
- kaiten_cli/runtime/support/audit.py +70 -0
- kaiten_cli/runtime/support/batch.py +234 -0
- kaiten_cli/runtime/support/card_move_url.py +213 -0
- kaiten_cli/runtime/support/cards.py +174 -0
- kaiten_cli/runtime/support/checklists.py +21 -0
- kaiten_cli/runtime/support/company_users.py +117 -0
- kaiten_cli/runtime/support/dashboards.py +35 -0
- kaiten_cli/runtime/support/documents.py +175 -0
- kaiten_cli/runtime/support/files.py +561 -0
- kaiten_cli/runtime/support/markdown_export.py +525 -0
- kaiten_cli/runtime/support/pagination.py +167 -0
- kaiten_cli/runtime/support/projects.py +66 -0
- kaiten_cli/runtime/support/relations.py +86 -0
- kaiten_cli/runtime/support/restrictions.py +62 -0
- kaiten_cli/runtime/support/spaces.py +20 -0
- kaiten_cli/runtime/support/time_logs.py +61 -0
- kaiten_cli/runtime/support/tree.py +140 -0
- kaiten_cli/runtime/support/tree_sharing.py +447 -0
- kaiten_cli/runtime/trace.py +500 -0
- kaiten_cli/runtime/transforms.py +128 -0
- kaiten_cli/schema_docs.py +22 -0
- kaiten_cli/update_check.py +519 -0
- kaiten_cli-0.3.3.dist-info/METADATA +1110 -0
- kaiten_cli-0.3.3.dist-info/RECORD +99 -0
- kaiten_cli-0.3.3.dist-info/WHEEL +4 -0
- kaiten_cli-0.3.3.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""Support helpers for audit/activity commands."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from kaiten_cli.runtime.support.batch import (
|
|
8
|
+
DEFAULT_BATCH_WORKERS,
|
|
9
|
+
MAX_BATCH_WORKERS,
|
|
10
|
+
fetch_card_collection_batch,
|
|
11
|
+
)
|
|
12
|
+
from kaiten_cli.runtime.transforms import select_fields
|
|
13
|
+
|
|
14
|
+
MAX_ACTIVITY_PAGES = 50
|
|
15
|
+
MAX_ACTIVITY_PAGE_SIZE = 100
|
|
16
|
+
DEFAULT_HISTORY_WORKERS = DEFAULT_BATCH_WORKERS
|
|
17
|
+
MAX_HISTORY_WORKERS = MAX_BATCH_WORKERS
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
async def fetch_all_space_activity(client, args: dict[str, Any], *, timeout: float) -> list[Any]:
|
|
21
|
+
"""Fetch space activity with bounded pagination."""
|
|
22
|
+
page_size = min(args.get("page_size", MAX_ACTIVITY_PAGE_SIZE), MAX_ACTIVITY_PAGE_SIZE)
|
|
23
|
+
max_pages = min(args.get("max_pages", MAX_ACTIVITY_PAGES), MAX_ACTIVITY_PAGES)
|
|
24
|
+
|
|
25
|
+
params: dict[str, Any] = {}
|
|
26
|
+
for key in ("actions", "created_after", "created_before", "author_id"):
|
|
27
|
+
if args.get(key) is not None:
|
|
28
|
+
params[key] = args[key]
|
|
29
|
+
|
|
30
|
+
all_activity: list[Any] = []
|
|
31
|
+
for page in range(max_pages):
|
|
32
|
+
params["limit"] = page_size
|
|
33
|
+
params["offset"] = page * page_size
|
|
34
|
+
result = await client.get(
|
|
35
|
+
f"/spaces/{args['space_id']}/activity", params=params, timeout=timeout
|
|
36
|
+
)
|
|
37
|
+
if not result:
|
|
38
|
+
break
|
|
39
|
+
all_activity.extend(result)
|
|
40
|
+
if len(result) < page_size:
|
|
41
|
+
break
|
|
42
|
+
return all_activity
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def fetch_card_location_histories(
|
|
46
|
+
*,
|
|
47
|
+
domain: str,
|
|
48
|
+
token: str,
|
|
49
|
+
card_ids: list[int],
|
|
50
|
+
workers: int,
|
|
51
|
+
fields: str | None,
|
|
52
|
+
timeout: float,
|
|
53
|
+
reporter,
|
|
54
|
+
execution_context=None,
|
|
55
|
+
cache_policy: str = "request_scope",
|
|
56
|
+
) -> dict[str, Any]:
|
|
57
|
+
return await fetch_card_collection_batch(
|
|
58
|
+
domain=domain,
|
|
59
|
+
token=token,
|
|
60
|
+
card_ids=card_ids,
|
|
61
|
+
workers=workers,
|
|
62
|
+
timeout=timeout,
|
|
63
|
+
reporter=reporter,
|
|
64
|
+
execution_context=execution_context,
|
|
65
|
+
cache_policy=cache_policy,
|
|
66
|
+
path_for_card=lambda card_id: f"/cards/{card_id}/location-history",
|
|
67
|
+
result_field="history",
|
|
68
|
+
transform_items=lambda items: select_fields(items, fields),
|
|
69
|
+
worker_label="batch-history",
|
|
70
|
+
)
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"""Shared batch-fetch helpers for card-scoped endpoints."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from kaiten_cli.errors import ApiError, CliError, ValidationError
|
|
10
|
+
from kaiten_cli.i18n import tr
|
|
11
|
+
from kaiten_cli.runtime.client import KaitenClient
|
|
12
|
+
from kaiten_cli.runtime.support.pagination import fetch_all_offset_pages
|
|
13
|
+
|
|
14
|
+
DEFAULT_BATCH_WORKERS = 2
|
|
15
|
+
MAX_BATCH_WORKERS = 6
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _normalize_batch_error(card_id: int, exc: Exception) -> dict[str, Any]:
|
|
19
|
+
payload = {
|
|
20
|
+
"card_id": card_id,
|
|
21
|
+
"error_type": "internal_error",
|
|
22
|
+
"message": str(exc),
|
|
23
|
+
}
|
|
24
|
+
if isinstance(exc, CliError):
|
|
25
|
+
payload["error_type"] = exc.error_type
|
|
26
|
+
if isinstance(exc, ApiError):
|
|
27
|
+
payload["status_code"] = exc.status_code
|
|
28
|
+
return payload
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def unique_card_ids(card_ids: list[int]) -> list[int]:
|
|
32
|
+
unique: list[int] = []
|
|
33
|
+
seen: set[int] = set()
|
|
34
|
+
for card_id in card_ids:
|
|
35
|
+
if card_id in seen:
|
|
36
|
+
continue
|
|
37
|
+
seen.add(card_id)
|
|
38
|
+
unique.append(card_id)
|
|
39
|
+
return unique
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async def fetch_card_collection_batch(
|
|
43
|
+
*,
|
|
44
|
+
domain: str,
|
|
45
|
+
token: str,
|
|
46
|
+
card_ids: list[int],
|
|
47
|
+
workers: int,
|
|
48
|
+
timeout: float,
|
|
49
|
+
reporter,
|
|
50
|
+
execution_context=None,
|
|
51
|
+
cache_policy: str = "request_scope",
|
|
52
|
+
path_for_card: Callable[[int], str],
|
|
53
|
+
query_for_card: Callable[[int], dict[str, Any] | None] | None = None,
|
|
54
|
+
page_size: int | None = None,
|
|
55
|
+
max_pages: int | None = None,
|
|
56
|
+
result_field: str,
|
|
57
|
+
transform_items: Callable[[list[Any]], list[Any] | Any],
|
|
58
|
+
worker_label: str,
|
|
59
|
+
) -> dict[str, Any]:
|
|
60
|
+
if (page_size is None) != (max_pages is None):
|
|
61
|
+
raise ValidationError(tr("Batch pagination requires both page_size and max_pages."))
|
|
62
|
+
unique_ids = unique_card_ids(card_ids)
|
|
63
|
+
queue: asyncio.Queue[tuple[int, int]] = asyncio.Queue()
|
|
64
|
+
for index, card_id in enumerate(unique_ids):
|
|
65
|
+
queue.put_nowait((index, card_id))
|
|
66
|
+
|
|
67
|
+
ordered_items: list[dict[str, Any] | None] = [None] * len(unique_ids)
|
|
68
|
+
ordered_errors: list[dict[str, Any] | None] = [None] * len(unique_ids)
|
|
69
|
+
bounded_workers = max(workers, 1)
|
|
70
|
+
|
|
71
|
+
async def worker(worker_index: int) -> None:
|
|
72
|
+
client = KaitenClient(
|
|
73
|
+
domain=domain,
|
|
74
|
+
token=token,
|
|
75
|
+
reporter=reporter,
|
|
76
|
+
execution_context=execution_context,
|
|
77
|
+
cache_policy=cache_policy,
|
|
78
|
+
)
|
|
79
|
+
if reporter is not None:
|
|
80
|
+
reporter(
|
|
81
|
+
tr(
|
|
82
|
+
"{value_0}: worker={value_1} started",
|
|
83
|
+
value_0=worker_label,
|
|
84
|
+
value_1=worker_index,
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
try:
|
|
88
|
+
while True:
|
|
89
|
+
try:
|
|
90
|
+
index, card_id = queue.get_nowait()
|
|
91
|
+
except asyncio.QueueEmpty:
|
|
92
|
+
break
|
|
93
|
+
try:
|
|
94
|
+
path = path_for_card(card_id)
|
|
95
|
+
query = query_for_card(card_id) if query_for_card is not None else None
|
|
96
|
+
if page_size is None and max_pages is None:
|
|
97
|
+
result = await client.get(path, params=query, timeout=timeout)
|
|
98
|
+
items = result if isinstance(result, list) else []
|
|
99
|
+
else:
|
|
100
|
+
items = await fetch_all_offset_pages(
|
|
101
|
+
client,
|
|
102
|
+
path,
|
|
103
|
+
params=query,
|
|
104
|
+
page_size=page_size,
|
|
105
|
+
max_pages=max_pages,
|
|
106
|
+
timeout=timeout,
|
|
107
|
+
reporter=reporter,
|
|
108
|
+
)
|
|
109
|
+
ordered_items[index] = {
|
|
110
|
+
"card_id": card_id,
|
|
111
|
+
result_field: transform_items(items),
|
|
112
|
+
}
|
|
113
|
+
except Exception as exc: # noqa: BLE001 - per-card failures stay in-band.
|
|
114
|
+
ordered_errors[index] = _normalize_batch_error(card_id, exc)
|
|
115
|
+
finally:
|
|
116
|
+
queue.task_done()
|
|
117
|
+
finally:
|
|
118
|
+
await client.close()
|
|
119
|
+
if reporter is not None:
|
|
120
|
+
reporter(
|
|
121
|
+
tr(
|
|
122
|
+
"{value_0}: worker={value_1} finished",
|
|
123
|
+
value_0=worker_label,
|
|
124
|
+
value_1=worker_index,
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
await asyncio.gather(*(worker(i + 1) for i in range(bounded_workers)))
|
|
129
|
+
|
|
130
|
+
items = [item for item in ordered_items if item is not None]
|
|
131
|
+
errors = [item for item in ordered_errors if item is not None]
|
|
132
|
+
return {
|
|
133
|
+
"items": items,
|
|
134
|
+
"errors": errors,
|
|
135
|
+
"meta": {
|
|
136
|
+
"requested": len(card_ids),
|
|
137
|
+
"requested_count": len(card_ids),
|
|
138
|
+
"unique_count": len(unique_ids),
|
|
139
|
+
"succeeded": len(items),
|
|
140
|
+
"failed": len(errors),
|
|
141
|
+
"workers": bounded_workers,
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
async def fetch_card_entity_batch(
|
|
147
|
+
*,
|
|
148
|
+
domain: str,
|
|
149
|
+
token: str,
|
|
150
|
+
card_ids: list[int],
|
|
151
|
+
workers: int,
|
|
152
|
+
timeout: float,
|
|
153
|
+
reporter,
|
|
154
|
+
execution_context=None,
|
|
155
|
+
cache_policy: str = "request_scope",
|
|
156
|
+
path_for_card: Callable[[int], str],
|
|
157
|
+
query_for_card: Callable[[int], dict[str, Any] | None] | None = None,
|
|
158
|
+
result_field: str,
|
|
159
|
+
transform_item: Callable[[dict[str, Any]], dict[str, Any] | Any],
|
|
160
|
+
worker_label: str,
|
|
161
|
+
) -> dict[str, Any]:
|
|
162
|
+
unique_ids = unique_card_ids(card_ids)
|
|
163
|
+
queue: asyncio.Queue[tuple[int, int]] = asyncio.Queue()
|
|
164
|
+
for index, card_id in enumerate(unique_ids):
|
|
165
|
+
queue.put_nowait((index, card_id))
|
|
166
|
+
|
|
167
|
+
ordered_items: list[dict[str, Any] | None] = [None] * len(unique_ids)
|
|
168
|
+
ordered_errors: list[dict[str, Any] | None] = [None] * len(unique_ids)
|
|
169
|
+
bounded_workers = max(workers, 1)
|
|
170
|
+
|
|
171
|
+
async def worker(worker_index: int) -> None:
|
|
172
|
+
client = KaitenClient(
|
|
173
|
+
domain=domain,
|
|
174
|
+
token=token,
|
|
175
|
+
reporter=reporter,
|
|
176
|
+
execution_context=execution_context,
|
|
177
|
+
cache_policy=cache_policy,
|
|
178
|
+
)
|
|
179
|
+
if reporter is not None:
|
|
180
|
+
reporter(
|
|
181
|
+
tr(
|
|
182
|
+
"{value_0}: worker={value_1} started",
|
|
183
|
+
value_0=worker_label,
|
|
184
|
+
value_1=worker_index,
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
try:
|
|
188
|
+
while True:
|
|
189
|
+
try:
|
|
190
|
+
index, card_id = queue.get_nowait()
|
|
191
|
+
except asyncio.QueueEmpty:
|
|
192
|
+
break
|
|
193
|
+
try:
|
|
194
|
+
result = await client.get(
|
|
195
|
+
path_for_card(card_id),
|
|
196
|
+
params=query_for_card(card_id) if query_for_card is not None else None,
|
|
197
|
+
timeout=timeout,
|
|
198
|
+
)
|
|
199
|
+
payload = result if isinstance(result, dict) else {}
|
|
200
|
+
ordered_items[index] = {
|
|
201
|
+
"card_id": card_id,
|
|
202
|
+
result_field: transform_item(payload),
|
|
203
|
+
}
|
|
204
|
+
except Exception as exc: # noqa: BLE001 - per-card failures stay in-band.
|
|
205
|
+
ordered_errors[index] = _normalize_batch_error(card_id, exc)
|
|
206
|
+
finally:
|
|
207
|
+
queue.task_done()
|
|
208
|
+
finally:
|
|
209
|
+
await client.close()
|
|
210
|
+
if reporter is not None:
|
|
211
|
+
reporter(
|
|
212
|
+
tr(
|
|
213
|
+
"{value_0}: worker={value_1} finished",
|
|
214
|
+
value_0=worker_label,
|
|
215
|
+
value_1=worker_index,
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
await asyncio.gather(*(worker(i + 1) for i in range(bounded_workers)))
|
|
220
|
+
|
|
221
|
+
items = [item for item in ordered_items if item is not None]
|
|
222
|
+
errors = [item for item in ordered_errors if item is not None]
|
|
223
|
+
return {
|
|
224
|
+
"items": items,
|
|
225
|
+
"errors": errors,
|
|
226
|
+
"meta": {
|
|
227
|
+
"requested": len(card_ids),
|
|
228
|
+
"requested_count": len(card_ids),
|
|
229
|
+
"unique_count": len(unique_ids),
|
|
230
|
+
"succeeded": len(items),
|
|
231
|
+
"failed": len(errors),
|
|
232
|
+
"workers": bounded_workers,
|
|
233
|
+
},
|
|
234
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""Helpers for moving cards from Kaiten UI URLs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
from urllib.parse import parse_qs, unquote, urlparse
|
|
8
|
+
|
|
9
|
+
from kaiten_cli.errors import ValidationError
|
|
10
|
+
from kaiten_cli.i18n import tr
|
|
11
|
+
from kaiten_cli.runtime.endpoints import KAITEN_HOST_SUFFIX, normalize_profile_domain
|
|
12
|
+
|
|
13
|
+
COLUMN_CHILD_KEYS = ("columns", "subcolumns", "children")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True, slots=True)
|
|
17
|
+
class ParsedCardUrl:
|
|
18
|
+
domain: str
|
|
19
|
+
space_id: int
|
|
20
|
+
card_ref: str
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True, slots=True)
|
|
24
|
+
class ParsedTargetUrl:
|
|
25
|
+
domain: str
|
|
26
|
+
space_id: int
|
|
27
|
+
column_id: int
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def normalize_kaiten_domain(value: str) -> str:
|
|
31
|
+
return normalize_profile_domain(value)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _domain_from_url(raw_url: str) -> str:
|
|
35
|
+
parsed = urlparse(raw_url)
|
|
36
|
+
hostname = (parsed.hostname or "").lower()
|
|
37
|
+
if not hostname.endswith(KAITEN_HOST_SUFFIX):
|
|
38
|
+
raise ValidationError(tr("URL must point to a Kaiten tenant: {value_0}", value_0=raw_url))
|
|
39
|
+
return normalize_kaiten_domain(hostname)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _path_segments(raw_url: str) -> list[str]:
|
|
43
|
+
parsed = urlparse(raw_url)
|
|
44
|
+
return [unquote(segment) for segment in parsed.path.split("/") if segment]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _space_id_from_segments(segments: list[str], *, raw_url: str) -> int:
|
|
48
|
+
try:
|
|
49
|
+
space_index = segments.index("space")
|
|
50
|
+
return int(segments[space_index + 1])
|
|
51
|
+
except (ValueError, IndexError) as exc:
|
|
52
|
+
raise ValidationError(
|
|
53
|
+
tr("URL must contain /space/<space_id>/: {value_0}", value_0=raw_url)
|
|
54
|
+
) from exc
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def parse_card_url(raw_url: str) -> ParsedCardUrl:
|
|
58
|
+
segments = _path_segments(raw_url)
|
|
59
|
+
try:
|
|
60
|
+
card_index = segments.index("card")
|
|
61
|
+
if card_index == 0 or segments[card_index - 1] != "boards":
|
|
62
|
+
raise ValueError
|
|
63
|
+
card_ref = segments[card_index + 1]
|
|
64
|
+
except (ValueError, IndexError) as exc:
|
|
65
|
+
raise ValidationError(
|
|
66
|
+
tr("Card URL must contain /boards/card/<id-or-key>: {value_0}", value_0=raw_url)
|
|
67
|
+
) from exc
|
|
68
|
+
if not card_ref:
|
|
69
|
+
raise ValidationError(
|
|
70
|
+
tr("Card URL must contain a card ID or key: {value_0}", value_0=raw_url)
|
|
71
|
+
)
|
|
72
|
+
return ParsedCardUrl(
|
|
73
|
+
domain=_domain_from_url(raw_url),
|
|
74
|
+
space_id=_space_id_from_segments(segments, raw_url=raw_url),
|
|
75
|
+
card_ref=card_ref,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def parse_target_url(raw_url: str) -> ParsedTargetUrl:
|
|
80
|
+
parsed = urlparse(raw_url)
|
|
81
|
+
segments = _path_segments(raw_url)
|
|
82
|
+
if "boards" not in segments:
|
|
83
|
+
raise ValidationError(
|
|
84
|
+
tr("Target URL must point to a board view: {value_0}", value_0=raw_url)
|
|
85
|
+
)
|
|
86
|
+
query = parse_qs(parsed.query)
|
|
87
|
+
focus = (query.get("focus") or [""])[0]
|
|
88
|
+
if focus != "column":
|
|
89
|
+
raise ValidationError(tr("Target URL must use focus=column."))
|
|
90
|
+
focus_ids = query.get("focusId")
|
|
91
|
+
if not focus_ids or not focus_ids[0]:
|
|
92
|
+
raise ValidationError(tr("Target URL must include focusId=<column_id>."))
|
|
93
|
+
try:
|
|
94
|
+
column_id = int(focus_ids[0])
|
|
95
|
+
except ValueError as exc:
|
|
96
|
+
raise ValidationError(tr("Target URL focusId must be an integer column ID.")) from exc
|
|
97
|
+
return ParsedTargetUrl(
|
|
98
|
+
domain=_domain_from_url(raw_url),
|
|
99
|
+
space_id=_space_id_from_segments(segments, raw_url=raw_url),
|
|
100
|
+
column_id=column_id,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def validate_url_domain(url_domain: str, profile_domain: str, *, label: str) -> None:
|
|
105
|
+
normalized_profile = normalize_kaiten_domain(profile_domain)
|
|
106
|
+
if url_domain != normalized_profile:
|
|
107
|
+
raise ValidationError(
|
|
108
|
+
tr(
|
|
109
|
+
"{value_0} host {value_1}.kaiten.ru does not match profile domain {value_2}.kaiten.ru. Pass --profile for the {value_3} tenant.",
|
|
110
|
+
value_0=label,
|
|
111
|
+
value_1=url_domain,
|
|
112
|
+
value_2=normalized_profile,
|
|
113
|
+
value_3=url_domain,
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _iter_column_nodes(columns: Any):
|
|
119
|
+
if not isinstance(columns, list):
|
|
120
|
+
return
|
|
121
|
+
for column in columns:
|
|
122
|
+
if not isinstance(column, dict):
|
|
123
|
+
continue
|
|
124
|
+
yield column
|
|
125
|
+
for key in COLUMN_CHILD_KEYS:
|
|
126
|
+
child_columns = column.get(key)
|
|
127
|
+
if child_columns is not columns:
|
|
128
|
+
yield from _iter_column_nodes(child_columns)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def find_column(board: dict[str, Any], column_id: int) -> dict[str, Any] | None:
|
|
132
|
+
for column in _iter_column_nodes(board.get("columns")):
|
|
133
|
+
if column.get("id") == column_id:
|
|
134
|
+
return column
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def lane_title(board: dict[str, Any], lane_id: int | None) -> str | None:
|
|
139
|
+
if lane_id is None:
|
|
140
|
+
return None
|
|
141
|
+
for lane in board.get("lanes", []):
|
|
142
|
+
if isinstance(lane, dict) and lane.get("id") == lane_id:
|
|
143
|
+
return lane.get("title")
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
async def resolve_move_target(
|
|
148
|
+
client,
|
|
149
|
+
target: ParsedTargetUrl,
|
|
150
|
+
*,
|
|
151
|
+
lane_id: int | None,
|
|
152
|
+
timeout: float,
|
|
153
|
+
) -> dict[str, Any]:
|
|
154
|
+
boards = await client.get(f"/spaces/{target.space_id}/boards", timeout=timeout)
|
|
155
|
+
if not isinstance(boards, list):
|
|
156
|
+
raise ValidationError(
|
|
157
|
+
tr("Expected a board list for space {value_0}.", value_0=target.space_id)
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
for board_summary in boards:
|
|
161
|
+
if not isinstance(board_summary, dict) or "id" not in board_summary:
|
|
162
|
+
continue
|
|
163
|
+
board_id = board_summary["id"]
|
|
164
|
+
board = board_summary
|
|
165
|
+
if "columns" not in board or "lanes" not in board:
|
|
166
|
+
board = await client.get(f"/boards/{board_id}", timeout=timeout)
|
|
167
|
+
if not isinstance(board, dict):
|
|
168
|
+
continue
|
|
169
|
+
|
|
170
|
+
column = find_column(board, target.column_id)
|
|
171
|
+
if column is None:
|
|
172
|
+
continue
|
|
173
|
+
|
|
174
|
+
lanes = [lane for lane in board.get("lanes", []) if isinstance(lane, dict)]
|
|
175
|
+
resolved_lane_id = lane_id
|
|
176
|
+
if resolved_lane_id is not None:
|
|
177
|
+
lane_ids = {lane.get("id") for lane in lanes}
|
|
178
|
+
if lane_ids and resolved_lane_id not in lane_ids:
|
|
179
|
+
raise ValidationError(
|
|
180
|
+
tr(
|
|
181
|
+
"Lane {value_0} does not belong to target board {value_1}.",
|
|
182
|
+
value_0=resolved_lane_id,
|
|
183
|
+
value_1=board_id,
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
elif len(lanes) == 1 and isinstance(lanes[0].get("id"), int):
|
|
187
|
+
resolved_lane_id = lanes[0]["id"]
|
|
188
|
+
elif len(lanes) > 1:
|
|
189
|
+
raise ValidationError(
|
|
190
|
+
tr(
|
|
191
|
+
"Target board {value_0} has {value_1} lanes; pass --lane-id explicitly.",
|
|
192
|
+
value_0=board_id,
|
|
193
|
+
value_1=len(lanes),
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
"space_id": target.space_id,
|
|
199
|
+
"board_id": board_id,
|
|
200
|
+
"board_title": board.get("title"),
|
|
201
|
+
"column_id": target.column_id,
|
|
202
|
+
"column_title": column.get("title"),
|
|
203
|
+
"lane_id": resolved_lane_id,
|
|
204
|
+
"lane_title": lane_title(board, resolved_lane_id),
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
raise ValidationError(
|
|
208
|
+
tr(
|
|
209
|
+
"Column {value_0} was not found in space {value_1}.",
|
|
210
|
+
value_0=target.column_id,
|
|
211
|
+
value_1=target.space_id,
|
|
212
|
+
)
|
|
213
|
+
)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Support helpers for bulk card operations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from kaiten_cli.runtime.support.batch import DEFAULT_BATCH_WORKERS, fetch_card_entity_batch
|
|
8
|
+
from kaiten_cli.runtime.support.pagination import (
|
|
9
|
+
API_MAX_PAGE_SIZE,
|
|
10
|
+
MAX_COLLECTION_MAX_PAGES,
|
|
11
|
+
fetch_all_offset_pages,
|
|
12
|
+
)
|
|
13
|
+
from kaiten_cli.runtime.transforms import compact_response, select_fields, strip_base64
|
|
14
|
+
|
|
15
|
+
DEFAULT_CARD_MAX_PAGES = 50
|
|
16
|
+
MAX_CARD_PAGES = MAX_COLLECTION_MAX_PAGES
|
|
17
|
+
MAX_CARD_PAGE_SIZE = API_MAX_PAGE_SIZE
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _card_query_params(args: dict[str, Any]) -> dict[str, Any]:
|
|
21
|
+
page_size = args.get("page_size", MAX_CARD_PAGE_SIZE)
|
|
22
|
+
params: dict[str, Any] = {"relations": args.get("relations", "none")}
|
|
23
|
+
string_keys = (
|
|
24
|
+
"query",
|
|
25
|
+
"tag",
|
|
26
|
+
"tag_ids",
|
|
27
|
+
"member_ids",
|
|
28
|
+
"owner_ids",
|
|
29
|
+
"exclude_owner_ids",
|
|
30
|
+
"responsible_ids",
|
|
31
|
+
"states",
|
|
32
|
+
"column_ids",
|
|
33
|
+
"exclude_board_ids",
|
|
34
|
+
"exclude_lane_ids",
|
|
35
|
+
"exclude_column_ids",
|
|
36
|
+
"exclude_card_ids",
|
|
37
|
+
"organization_ids",
|
|
38
|
+
"organizations_ids",
|
|
39
|
+
"type_ids",
|
|
40
|
+
"external_id",
|
|
41
|
+
"created_after",
|
|
42
|
+
"created_before",
|
|
43
|
+
"updated_after",
|
|
44
|
+
"updated_before",
|
|
45
|
+
"first_moved_in_progress_after",
|
|
46
|
+
"first_moved_in_progress_before",
|
|
47
|
+
"last_moved_to_done_at_after",
|
|
48
|
+
"last_moved_to_done_at_before",
|
|
49
|
+
"due_date_after",
|
|
50
|
+
"due_date_before",
|
|
51
|
+
"additional_card_fields",
|
|
52
|
+
"filter",
|
|
53
|
+
"order_by",
|
|
54
|
+
"order_direction",
|
|
55
|
+
"visible",
|
|
56
|
+
)
|
|
57
|
+
int_keys = (
|
|
58
|
+
"space_id",
|
|
59
|
+
"board_id",
|
|
60
|
+
"column_id",
|
|
61
|
+
"lane_id",
|
|
62
|
+
"condition",
|
|
63
|
+
"type_id",
|
|
64
|
+
"owner_id",
|
|
65
|
+
"responsible_id",
|
|
66
|
+
"order_space_id",
|
|
67
|
+
)
|
|
68
|
+
bool_keys = (
|
|
69
|
+
"overdue",
|
|
70
|
+
"asap",
|
|
71
|
+
"done_on_time",
|
|
72
|
+
"with_due_date",
|
|
73
|
+
"is_request",
|
|
74
|
+
"archived",
|
|
75
|
+
"broken_api",
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
for key in string_keys + int_keys + bool_keys:
|
|
79
|
+
if args.get(key) is not None:
|
|
80
|
+
params[key] = args[key]
|
|
81
|
+
params["limit"] = page_size
|
|
82
|
+
return params
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
async def _fetch_cards(
|
|
86
|
+
client, params: dict[str, Any], *, page_size: int, max_pages: int, timeout: float
|
|
87
|
+
) -> list[Any]:
|
|
88
|
+
return await fetch_all_offset_pages(
|
|
89
|
+
client,
|
|
90
|
+
"/cards",
|
|
91
|
+
params=params,
|
|
92
|
+
page_size=page_size,
|
|
93
|
+
max_pages=max_pages,
|
|
94
|
+
timeout=timeout,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
async def fetch_all_cards(client, args: dict[str, Any], *, timeout: float) -> list[Any]:
|
|
99
|
+
"""Fetch cards with bounded pagination and low-load defaults."""
|
|
100
|
+
page_size = args.get("page_size", MAX_CARD_PAGE_SIZE)
|
|
101
|
+
max_pages = args.get("max_pages", DEFAULT_CARD_MAX_PAGES)
|
|
102
|
+
selection = args.get("selection")
|
|
103
|
+
|
|
104
|
+
base_params = _card_query_params(args)
|
|
105
|
+
base_params.pop("selection", None)
|
|
106
|
+
|
|
107
|
+
if selection == "archived_only":
|
|
108
|
+
archived_params = dict(base_params)
|
|
109
|
+
archived_params["archived"] = True
|
|
110
|
+
archived_params.pop("condition", None)
|
|
111
|
+
return await _fetch_cards(
|
|
112
|
+
client, archived_params, page_size=page_size, max_pages=max_pages, timeout=timeout
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
if selection == "active_only":
|
|
116
|
+
all_cards = await _fetch_cards(
|
|
117
|
+
client, base_params, page_size=page_size, max_pages=max_pages, timeout=timeout
|
|
118
|
+
)
|
|
119
|
+
archived_params = dict(base_params)
|
|
120
|
+
archived_params["archived"] = True
|
|
121
|
+
archived_params.pop("condition", None)
|
|
122
|
+
archived_cards = await _fetch_cards(
|
|
123
|
+
client, archived_params, page_size=page_size, max_pages=max_pages, timeout=timeout
|
|
124
|
+
)
|
|
125
|
+
archived_ids = {
|
|
126
|
+
item["id"] for item in archived_cards if isinstance(item, dict) and "id" in item
|
|
127
|
+
}
|
|
128
|
+
return [
|
|
129
|
+
item
|
|
130
|
+
for item in all_cards
|
|
131
|
+
if not (isinstance(item, dict) and item.get("id") in archived_ids)
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
return await _fetch_cards(
|
|
135
|
+
client, base_params, page_size=page_size, max_pages=max_pages, timeout=timeout
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _shape_card_entity(
|
|
140
|
+
item: dict[str, Any], *, compact: bool, fields: str | None
|
|
141
|
+
) -> dict[str, Any]:
|
|
142
|
+
shaped = compact_response(item, compact)
|
|
143
|
+
shaped = select_fields(shaped, fields)
|
|
144
|
+
shaped, _ = strip_base64(shaped)
|
|
145
|
+
return shaped
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
async def fetch_cards_batch_get(
|
|
149
|
+
*,
|
|
150
|
+
domain: str,
|
|
151
|
+
token: str,
|
|
152
|
+
card_ids: list[int],
|
|
153
|
+
workers: int = DEFAULT_BATCH_WORKERS,
|
|
154
|
+
compact: bool = False,
|
|
155
|
+
fields: str | None = None,
|
|
156
|
+
timeout: float,
|
|
157
|
+
reporter,
|
|
158
|
+
execution_context=None,
|
|
159
|
+
cache_policy: str = "request_scope",
|
|
160
|
+
) -> dict[str, Any]:
|
|
161
|
+
return await fetch_card_entity_batch(
|
|
162
|
+
domain=domain,
|
|
163
|
+
token=token,
|
|
164
|
+
card_ids=card_ids,
|
|
165
|
+
workers=workers,
|
|
166
|
+
timeout=timeout,
|
|
167
|
+
reporter=reporter,
|
|
168
|
+
execution_context=execution_context,
|
|
169
|
+
cache_policy=cache_policy,
|
|
170
|
+
path_for_card=lambda card_id: f"/cards/{card_id}",
|
|
171
|
+
result_field="card",
|
|
172
|
+
transform_item=lambda item: _shape_card_entity(item, compact=compact, fields=fields),
|
|
173
|
+
worker_label="batch-cards",
|
|
174
|
+
)
|