Skip to content

Commit f88e7d2

Browse files
authored
feat: string-based API support (#204)
1 parent 679711b commit f88e7d2

File tree

9 files changed

+549
-1
lines changed

9 files changed

+549
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pdoc__ = {'tests': False}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from enum import Enum
2+
3+
4+
class EditBranchPatchPath(Enum):
5+
NAME = "/name"
6+
TITLE = "/title"
7+
PRIORITY = "/priority"
8+
9+
10+
class ListBranchesOrderBy(Enum):
11+
ID = "id"
12+
NAME = "name"
13+
TITLE = "title"
14+
CREATED_AT = "createdAt"
15+
UPDATED_AT = "updatedAt"
16+
EXPORT_PATTERN = "exportPattern"
17+
PRIORITY = "priority"
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
from typing import Optional, Iterable
2+
3+
from crowdin_api.api_resources.abstract.resources import BaseResource
4+
from crowdin_api.api_resources.branches.types import (
5+
CloneBranchRequest,
6+
AddBranchRequest,
7+
EditBranchPatch,
8+
MergeBranchRequest
9+
)
10+
from crowdin_api.sorting import Sorting
11+
12+
13+
class BranchesResource(BaseResource):
14+
"""
15+
Resource for Bundles
16+
17+
Link to documentation:
18+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches
19+
20+
Link to documentation for enterprise:
21+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches
22+
"""
23+
24+
def get_cloned_branch(
25+
self,
26+
project_id: int,
27+
branch_id: int,
28+
clone_id: str
29+
):
30+
"""
31+
Get Cloned Branch
32+
33+
Link to documentation:
34+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.clones.branch.get
35+
36+
Link to documentation for enterprise:
37+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.clones.branch.get
38+
"""
39+
40+
return self.requester.request(
41+
method="get",
42+
path=f"projects/{project_id}/branches/{branch_id}/clones/{clone_id}/branch"
43+
)
44+
45+
def get_branch_clones_path(self, project_id: int, branch_id: int, clone_id: Optional[str] = None):
46+
if clone_id is not None:
47+
return f"projects/{project_id}/branches/{branch_id}/clones/{clone_id}"
48+
return f"projects/{project_id}/branches/{branch_id}/clones"
49+
50+
def clone_branch(
51+
self,
52+
project_id: int,
53+
branch_id: int,
54+
request_data: CloneBranchRequest
55+
):
56+
"""
57+
Clone Branch
58+
59+
Link to documentation:
60+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.clones.post
61+
62+
Link to documentation for enterprise:
63+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.clones.post
64+
"""
65+
66+
return self.requester.request(
67+
method="post",
68+
path=self.get_branch_clones_path(project_id, branch_id),
69+
request_data=request_data
70+
)
71+
72+
def check_branch_clone_status(
73+
self,
74+
project_id: int,
75+
branch_id: int,
76+
clone_id: str
77+
):
78+
"""
79+
Check Branch Clone Status
80+
81+
Link to documentation:
82+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.clones.get
83+
84+
Link to documentation for enterprise:
85+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.clones.get
86+
"""
87+
88+
return self.requester.request(
89+
method="get",
90+
path=self.get_branch_clones_path(project_id, branch_id, clone_id)
91+
)
92+
93+
def get_branches_path(
94+
self,
95+
project_id: int,
96+
branch_id: Optional[int] = None
97+
):
98+
if branch_id is not None:
99+
return f"projects/{project_id}/branches/{branch_id}"
100+
101+
return f"projects/{project_id}/branches"
102+
103+
def list_branches(
104+
self,
105+
project_id: int,
106+
name: Optional[str] = None,
107+
order_by: Optional[Sorting] = None,
108+
limit: Optional[int] = None,
109+
offset: Optional[int] = None,
110+
):
111+
"""
112+
List Branches
113+
114+
Link to documentation:
115+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.getMany
116+
117+
Link to documentation for enterprise:
118+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.getMany
119+
"""
120+
121+
params = {
122+
"name": name,
123+
"orderBy": order_by,
124+
}
125+
params.update(self.get_page_params(limit=limit, offset=offset))
126+
127+
return self.requester.request(
128+
method="get",
129+
path=self.get_branches_path(project_id),
130+
params=params,
131+
)
132+
133+
def add_branch(
134+
self,
135+
project_id: int,
136+
request_data: AddBranchRequest
137+
):
138+
"""
139+
Add Branch
140+
141+
Link to documentation:
142+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.post
143+
144+
Link to documentation for enterprise:
145+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.post
146+
"""
147+
148+
return self.requester.request(
149+
method="post",
150+
path=self.get_branches_path(project_id),
151+
request_data=request_data,
152+
)
153+
154+
def get_branch(self, project_id: int, branch_id: int):
155+
"""
156+
Get Branch
157+
158+
Link to documentation:
159+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.get
160+
161+
Link to documentation for enterprise:
162+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.get
163+
"""
164+
165+
return self.requester.request(
166+
method="get",
167+
path=self.get_branches_path(project_id, branch_id),
168+
)
169+
170+
def delete_branch(self, project_id: int, branch_id: int):
171+
"""
172+
Delete Branch
173+
174+
Link to documentation:
175+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.delete
176+
177+
Link to documentation for enterprise:
178+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.delete
179+
"""
180+
181+
return self.requester.request(
182+
method="delete",
183+
path=self.get_branches_path(project_id, branch_id),
184+
)
185+
186+
def edit_branch(self, project_id: int, branch_id: int, patches: Iterable[EditBranchPatch]):
187+
"""
188+
Edit Branch
189+
190+
Link to documentation:
191+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.patch
192+
193+
Link to documentation for enterprise:
194+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.patch
195+
"""
196+
197+
return self.requester.request(
198+
method="patch",
199+
path=self.get_branches_path(project_id, branch_id),
200+
request_data=patches,
201+
)
202+
203+
def get_branch_merges_path(self, project_id: int, branch_id: int, merge_id: Optional[int] = None):
204+
if merge_id is not None:
205+
return f"projects/{project_id}/branches/{branch_id}/merges/{merge_id}"
206+
207+
return f"projects/{project_id}/branches/{branch_id}/merges"
208+
209+
def merge_branch(self, project_id: int, branch_id: int, request: MergeBranchRequest):
210+
"""
211+
Merge Branch
212+
213+
Link to documentation:
214+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.post
215+
216+
Link to documentation for enterprise:
217+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.post
218+
"""
219+
220+
return self.requester.request(
221+
method="post",
222+
path=self.get_branch_merges_path(project_id, branch_id),
223+
request_data=request,
224+
)
225+
226+
def check_branch_merge_status(self, project_id: int, branch_id: int, merge_id: int):
227+
"""
228+
Check Branch Merge Status
229+
230+
Link to documentation:
231+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.get
232+
233+
Link to documentation for enterprise:
234+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.get
235+
"""
236+
237+
return self.requester.request(
238+
method="get",
239+
path=self.get_branch_merges_path(project_id, branch_id, merge_id),
240+
)
241+
242+
def get_branch_merge_summary(self, project_id: int, branch_id: int, merge_id: int):
243+
"""
244+
Get Branch Merge Summary
245+
246+
Link to documentation:
247+
https://support.crowdin.com/developer/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.summary.get
248+
249+
Link to documentation for enterprise:
250+
https://support.crowdin.com/developer/enterprise/api/v2/string-based/#tag/Branches/operation/api.projects.branches.merges.summary.get
251+
"""
252+
253+
return self.requester.request(
254+
method="get",
255+
path=self.get_branch_merges_path(project_id, branch_id, merge_id) + "/summary",
256+
)

0 commit comments

Comments
 (0)