agent-tool-openproject-cli 0.2.1__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.
- agent_tool_openproject_cli-0.2.1.dist-info/METADATA +457 -0
- agent_tool_openproject_cli-0.2.1.dist-info/RECORD +40 -0
- agent_tool_openproject_cli-0.2.1.dist-info/WHEEL +5 -0
- agent_tool_openproject_cli-0.2.1.dist-info/entry_points.txt +2 -0
- agent_tool_openproject_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
- agent_tool_openproject_cli-0.2.1.dist-info/top_level.txt +1 -0
- opcli/__init__.py +3 -0
- opcli/__main__.py +6 -0
- opcli/cli.py +166 -0
- opcli/client.py +252 -0
- opcli/commands/__init__.py +1 -0
- opcli/commands/_shared.py +50 -0
- opcli/commands/attachments.py +104 -0
- opcli/commands/auth.py +113 -0
- opcli/commands/comments.py +90 -0
- opcli/commands/costs.py +205 -0
- opcli/commands/custom_fields.py +82 -0
- opcli/commands/filelinks.py +100 -0
- opcli/commands/guide.py +198 -0
- opcli/commands/memberships.py +110 -0
- opcli/commands/notifications.py +130 -0
- opcli/commands/projects.py +149 -0
- opcli/commands/raw.py +83 -0
- opcli/commands/search.py +256 -0
- opcli/commands/settings.py +59 -0
- opcli/commands/time_entries.py +214 -0
- opcli/commands/users.py +109 -0
- opcli/commands/wiki.py +49 -0
- opcli/commands/workpackages.py +338 -0
- opcli/config.py +134 -0
- opcli/context.py +117 -0
- opcli/credentials.py +139 -0
- opcli/duration.py +56 -0
- opcli/errors.py +81 -0
- opcli/hal.py +75 -0
- opcli/output.py +225 -0
- opcli/resolve.py +183 -0
- opcli/searchspec.py +269 -0
- opcli/serialize.py +225 -0
- opcli/wpfilters.py +159 -0
opcli/wpfilters.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"""Build OpenProject work-package ``filters`` arrays from friendly options.
|
|
2
|
+
|
|
3
|
+
Encapsulates the fiddly rules the research surfaced:
|
|
4
|
+
|
|
5
|
+
* values are ALWAYS arrays of strings (ids too);
|
|
6
|
+
* omitting filters entirely means "open only" — pass ``[]`` for everything;
|
|
7
|
+
* status ``open``/``closed`` use the ``o``/``c`` operators with ``values:null``;
|
|
8
|
+
* full-text uses the ``search`` filter with the ``**`` operator.
|
|
9
|
+
|
|
10
|
+
Beyond the raw options, it accepts lots of predefined conveniences (``mine``,
|
|
11
|
+
``unassigned``, ``overdue``, ``updated_since``, ``version`` …) and a list of
|
|
12
|
+
``--where`` expressions compiled via :mod:`opcli.searchspec`.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from . import hal, resolve, searchspec
|
|
21
|
+
from .client import Client
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _date(spec: str | None) -> str | None:
|
|
25
|
+
return searchspec.to_date(spec).isoformat() if spec else None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _user_value(client: Client, ref: str, project: Any) -> str:
|
|
29
|
+
"""Return the filter value for a user ref — 'me' passes straight through
|
|
30
|
+
(the API understands it), otherwise resolve to a numeric id string."""
|
|
31
|
+
if ref.strip().lower() == "me":
|
|
32
|
+
return "me"
|
|
33
|
+
href = resolve.user(client, ref, project_ref=project)
|
|
34
|
+
return str(hal.id_from_href(href))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def build(
|
|
38
|
+
client: Client,
|
|
39
|
+
*,
|
|
40
|
+
project: str | int | None = None,
|
|
41
|
+
status: str | None = None,
|
|
42
|
+
type_: str | None = None,
|
|
43
|
+
assignee: str | None = None,
|
|
44
|
+
author: str | None = None,
|
|
45
|
+
responsible: str | None = None,
|
|
46
|
+
priority: str | None = None,
|
|
47
|
+
parent: str | int | None = None,
|
|
48
|
+
version: str | None = None,
|
|
49
|
+
id_list: str | None = None,
|
|
50
|
+
query: str | None = None,
|
|
51
|
+
subject: str | None = None,
|
|
52
|
+
# predefined booleans
|
|
53
|
+
mine: bool = False,
|
|
54
|
+
unassigned: bool = False,
|
|
55
|
+
watching: bool = False,
|
|
56
|
+
overdue: bool = False,
|
|
57
|
+
# dates (accept ISO or relative specs like 7d / +30d / today)
|
|
58
|
+
created_since: str | None = None,
|
|
59
|
+
created_before: str | None = None,
|
|
60
|
+
updated_since: str | None = None,
|
|
61
|
+
due_before: str | None = None,
|
|
62
|
+
due_after: str | None = None,
|
|
63
|
+
start_after: str | None = None,
|
|
64
|
+
start_before: str | None = None,
|
|
65
|
+
where: list[str] | None = None,
|
|
66
|
+
all_statuses: bool = False,
|
|
67
|
+
extra: list[dict] | None = None,
|
|
68
|
+
) -> list[dict[str, Any]]:
|
|
69
|
+
filters: list[dict[str, Any]] = []
|
|
70
|
+
status_set = False
|
|
71
|
+
|
|
72
|
+
if project is not None:
|
|
73
|
+
filters.append({"project": {"operator": "=", "values": [str(resolve.project_id(client, project))]}})
|
|
74
|
+
|
|
75
|
+
if status:
|
|
76
|
+
status_set = True
|
|
77
|
+
low = status.strip().lower()
|
|
78
|
+
if low == "open":
|
|
79
|
+
filters.append({"status": {"operator": "o", "values": None}})
|
|
80
|
+
elif low == "closed":
|
|
81
|
+
filters.append({"status": {"operator": "c", "values": None}})
|
|
82
|
+
else:
|
|
83
|
+
sid = resolve._resolve_collection(client, "statuses", status, ["name"], label="status")["id"]
|
|
84
|
+
filters.append({"status": {"operator": "=", "values": [str(sid)]}})
|
|
85
|
+
|
|
86
|
+
if type_:
|
|
87
|
+
tid = resolve._resolve_collection(client, "types", type_, ["name"], label="type")["id"]
|
|
88
|
+
filters.append({"type": {"operator": "=", "values": [str(tid)]}})
|
|
89
|
+
|
|
90
|
+
if mine:
|
|
91
|
+
filters.append({"assignee": {"operator": "=", "values": ["me"]}})
|
|
92
|
+
elif unassigned:
|
|
93
|
+
filters.append({"assignee": {"operator": "!*", "values": None}})
|
|
94
|
+
elif assignee:
|
|
95
|
+
filters.append({"assignee": {"operator": "=", "values": [_user_value(client, assignee, project)]}})
|
|
96
|
+
|
|
97
|
+
if author:
|
|
98
|
+
filters.append({"author": {"operator": "=", "values": [_user_value(client, author, project)]}})
|
|
99
|
+
if responsible:
|
|
100
|
+
filters.append({"responsible": {"operator": "=", "values": [_user_value(client, responsible, project)]}})
|
|
101
|
+
if watching:
|
|
102
|
+
filters.append({"watcher": {"operator": "=", "values": ["me"]}})
|
|
103
|
+
|
|
104
|
+
if priority:
|
|
105
|
+
pid = resolve._resolve_collection(client, "priorities", priority, ["name"], label="priority")["id"]
|
|
106
|
+
filters.append({"priority": {"operator": "=", "values": [str(pid)]}})
|
|
107
|
+
|
|
108
|
+
if parent is not None:
|
|
109
|
+
filters.append({"parent": {"operator": "=", "values": [str(parent)]}})
|
|
110
|
+
|
|
111
|
+
if version:
|
|
112
|
+
vid = resolve.version(client, version, project_ref=project)["id"]
|
|
113
|
+
filters.append({"version": {"operator": "=", "values": [str(vid)]}})
|
|
114
|
+
|
|
115
|
+
if id_list:
|
|
116
|
+
ids = [s.strip() for s in str(id_list).split(",") if s.strip()]
|
|
117
|
+
filters.append({"id": {"operator": "=", "values": ids}})
|
|
118
|
+
|
|
119
|
+
if query:
|
|
120
|
+
filters.append({"search": {"operator": "**", "values": [query]}})
|
|
121
|
+
if subject:
|
|
122
|
+
filters.append({"subject": {"operator": "~", "values": [subject]}})
|
|
123
|
+
|
|
124
|
+
# date ranges (open-ended <>d with an empty bound)
|
|
125
|
+
if created_since or created_before:
|
|
126
|
+
filters.append({"createdAt": {"operator": "<>d", "values": [_date(created_since) or "", _date(created_before) or ""]}})
|
|
127
|
+
if updated_since:
|
|
128
|
+
filters.append({"updatedAt": {"operator": "<>d", "values": [_date(updated_since), ""]}})
|
|
129
|
+
if overdue:
|
|
130
|
+
# due before today and (unless a status was requested) still open
|
|
131
|
+
filters.append({"dueDate": {"operator": "<>d", "values": ["", _date("yesterday")]}})
|
|
132
|
+
if not status:
|
|
133
|
+
filters.append({"status": {"operator": "o", "values": None}})
|
|
134
|
+
status_set = True
|
|
135
|
+
if due_after or due_before:
|
|
136
|
+
filters.append({"dueDate": {"operator": "<>d", "values": [_date(due_after) or "", _date(due_before) or ""]}})
|
|
137
|
+
if start_after or start_before:
|
|
138
|
+
filters.append({"startDate": {"operator": "<>d", "values": [_date(start_after) or "", _date(start_before) or ""]}})
|
|
139
|
+
|
|
140
|
+
if where:
|
|
141
|
+
for expr in where:
|
|
142
|
+
f = searchspec.compile_where(client, expr, project_ref=project)
|
|
143
|
+
filters.append(f)
|
|
144
|
+
if "status" in f:
|
|
145
|
+
status_set = True
|
|
146
|
+
|
|
147
|
+
if extra:
|
|
148
|
+
filters.extend(extra)
|
|
149
|
+
|
|
150
|
+
# replicate OpenProject's "open by default" (it only auto-applies that when
|
|
151
|
+
# the filters param is omitted, which we never do) unless widened.
|
|
152
|
+
if not status_set and not all_statuses:
|
|
153
|
+
filters.append({"status": {"operator": "o", "values": None}})
|
|
154
|
+
|
|
155
|
+
return filters
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def encode(filters: list[dict]) -> str:
|
|
159
|
+
return json.dumps(filters)
|