Skip to content

Commit 8ec1c3e

Browse files
authored
Merge pull request #6 from nextcloud/feat/openproject
Feat: OpenProject tools
2 parents 2c9db91 + a47c6bb commit 8ec1c3e

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from langchain_core.tools import tool
2+
from nc_py_api import Nextcloud
3+
4+
from typing import Optional
5+
6+
from ex_app.lib.all_tools.lib.decorator import safe_tool, dangerous_tool
7+
8+
9+
def get_tools(nc: Nextcloud):
10+
@tool
11+
@safe_tool
12+
def list_projects():
13+
"""
14+
List all projects in OpenProject
15+
:return: list of projects including project IDs
16+
"""
17+
18+
return nc.ocs('GET', '/ocs/v2.php/apps/integration_openproject/api/v1/projects')
19+
20+
@tool
21+
@safe_tool
22+
def list_assignees(project_id: int):
23+
"""
24+
List all available assignees of a project in OpenProject
25+
:param project_id: the ID of the project
26+
:return: list of users that can be assigned, including user IDs
27+
"""
28+
29+
return nc.ocs('GET', f'/ocs/v2.php/apps/integration_openproject/api/v1/projects/{project_id}/available-assignees')
30+
31+
@tool
32+
@dangerous_tool
33+
def create_work_package(project_id: int, title: str, description: Optional[str], assignee_id: Optional[int]):
34+
"""
35+
Create a new work package in a given project in OpenProject
36+
:param project_id: the ID of the project the work package should be created in, obtainable with list_projects
37+
:param title: The title of the work package
38+
:param description: The description of the work package
39+
:param assignee_id: The ID of the user the work package should be assigned to, obtainable via list_assignees
40+
:return:
41+
"""
42+
43+
links = {
44+
"project": {
45+
"href": f"/api/v3/projects/{project_id}",
46+
},
47+
"status": {
48+
"href": "/api/v3/statuses/1",
49+
},
50+
"type": {
51+
"href": "/api/v3/types/1",
52+
}
53+
}
54+
55+
if assignee_id:
56+
links["assignee"] = {
57+
"href": f"/api/v3/users/{assignee_id}",
58+
}
59+
60+
61+
json= {
62+
"body": {
63+
"_links": links,
64+
"subject": title,
65+
},
66+
}
67+
68+
if description:
69+
json["body"]["description"] = {
70+
"format": "markdown",
71+
"html": "",
72+
"raw": description,
73+
}
74+
75+
response = nc.ocs('POST', '/ocs/v2.php/apps/integration_openproject/api/v1/create/work-packages', json=json)
76+
77+
return True
78+
79+
80+
81+
return [
82+
list_projects,
83+
list_assignees,
84+
create_work_package
85+
]

0 commit comments

Comments
 (0)