atlassian-python-api 5.0.2__py3-none-any.whl → 5.0.4__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.
- atlassian/VERSION +1 -1
- atlassian/__init__.py +7 -1
- atlassian/assets/__init__.py +6 -0
- atlassian/{assets.py → assets/assets_cloud.py} +264 -6
- atlassian/assets/assets_server.py +24 -0
- atlassian/bamboo.py +819 -2
- atlassian/bitbucket/__init__.py +149 -0
- atlassian/bitbucket/cloud/repositories/commits.py +13 -3
- atlassian/bitbucket/cloud/repositories/repositoryVariables.py +23 -0
- atlassian/bitbucket/cloud/workspaces/__init__.py +6 -1
- atlassian/company_calendar.py +215 -0
- atlassian/compass/__init__.py +109 -0
- atlassian/confluence/base.py +12 -1
- atlassian/confluence/cloud/__init__.py +17 -0
- atlassian/confluence/cloud/admin_management.py +125 -0
- atlassian/confluence/cloud/cloud.py +7 -21
- atlassian/confluence/server/__init__.py +140 -16
- atlassian/confluence_base.py +24 -13
- atlassian/crowd.py +1204 -6
- atlassian/jira/jira_cloud.py +83 -0
- atlassian/jira/jira_server.py +165 -31
- atlassian/service_desk.py +71 -11
- atlassian/{xray.py → xray/__init__.py} +136 -9
- {atlassian_python_api-5.0.2.dist-info → atlassian_python_api-5.0.4.dist-info}/METADATA +2 -5
- {atlassian_python_api-5.0.2.dist-info → atlassian_python_api-5.0.4.dist-info}/RECORD +28 -23
- {atlassian_python_api-5.0.2.dist-info → atlassian_python_api-5.0.4.dist-info}/WHEEL +0 -0
- {atlassian_python_api-5.0.2.dist-info → atlassian_python_api-5.0.4.dist-info}/licenses/LICENSE +0 -0
- {atlassian_python_api-5.0.2.dist-info → atlassian_python_api-5.0.4.dist-info}/top_level.txt +0 -0
atlassian/bitbucket/__init__.py
CHANGED
|
@@ -124,6 +124,17 @@ class Bitbucket(BitbucketBase):
|
|
|
124
124
|
url = self.resource_url("status", api_root="rest/indexing", api_version="latest")
|
|
125
125
|
return self.get(url)
|
|
126
126
|
|
|
127
|
+
def get_cluster_info(self):
|
|
128
|
+
"""Get system information for the Bitbucket Data Center cluster.
|
|
129
|
+
|
|
130
|
+
This administrative endpoint is available on Bitbucket Server/Data
|
|
131
|
+
Center only and requires the appropriate administrator permission.
|
|
132
|
+
"""
|
|
133
|
+
if self.cloud:
|
|
134
|
+
raise NotImplementedError("Cluster information is only available on Bitbucket Server/Data Center")
|
|
135
|
+
url = self.resource_url("admin/cluster", api_version="latest")
|
|
136
|
+
return self.get(url)
|
|
137
|
+
|
|
127
138
|
def get_users(self, user_filter=None, limit=25, start=0):
|
|
128
139
|
"""
|
|
129
140
|
Get list of bitbucket users.
|
|
@@ -366,6 +377,50 @@ class Bitbucket(BitbucketBase):
|
|
|
366
377
|
url = f"{self._url_repo(project_key, repository_slug, api_version='latest')}/hook-scripts/{script_id}"
|
|
367
378
|
return self.delete(url)
|
|
368
379
|
|
|
380
|
+
def get_hook_script(self, script_id: int):
|
|
381
|
+
"""Return the registered global hook script with ``script_id``.
|
|
382
|
+
|
|
383
|
+
The result only contains the script metadata; use
|
|
384
|
+
``get_hook_script_content()`` to fetch the script body.
|
|
385
|
+
"""
|
|
386
|
+
return self.get(f"{self._url_hook_scripts()}/{script_id}")
|
|
387
|
+
|
|
388
|
+
def get_hook_script_content(self, script_id: int):
|
|
389
|
+
"""Return the raw body of the registered global hook script.
|
|
390
|
+
|
|
391
|
+
``not_json_response`` is used because the endpoint returns the
|
|
392
|
+
executable script as plain text rather than a JSON payload.
|
|
393
|
+
"""
|
|
394
|
+
return self.get(
|
|
395
|
+
f"{self._url_hook_scripts()}/{script_id}/content",
|
|
396
|
+
not_json_response=True,
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
def update_hook_script(
|
|
400
|
+
self, script_id: int, content: bytes, name: str, hook_type: str, description: Optional[str] = None
|
|
401
|
+
):
|
|
402
|
+
"""Update a registered global hook script on Bitbucket Data Center.
|
|
403
|
+
|
|
404
|
+
``hook_type`` must be ``PRE`` or ``POST``. Like ``create_hook_script``,
|
|
405
|
+
the API expects a multipart form; ``content`` is the executable script
|
|
406
|
+
bytes.
|
|
407
|
+
"""
|
|
408
|
+
if hook_type not in ("PRE", "POST"):
|
|
409
|
+
raise ValueError("hook_type must be 'PRE' or 'POST'")
|
|
410
|
+
|
|
411
|
+
files: Dict[str, Any] = {
|
|
412
|
+
"content": ("hook-script", content, "application/octet-stream"),
|
|
413
|
+
"name": (None, name),
|
|
414
|
+
"type": (None, hook_type),
|
|
415
|
+
}
|
|
416
|
+
if description is not None:
|
|
417
|
+
files["description"] = (None, description)
|
|
418
|
+
return self.put(f"{self._url_hook_scripts()}/{script_id}", files=files, headers=self.no_check_headers)
|
|
419
|
+
|
|
420
|
+
def delete_hook_script(self, script_id: int):
|
|
421
|
+
"""Delete the registered global hook script with ``script_id``."""
|
|
422
|
+
return self.delete(f"{self._url_hook_scripts()}/{script_id}")
|
|
423
|
+
|
|
369
424
|
def get_categories(self, project_key, repository_slug=None):
|
|
370
425
|
"""
|
|
371
426
|
Get a list of categories assigned to a project or repository.
|
|
@@ -981,6 +1036,40 @@ class Bitbucket(BitbucketBase):
|
|
|
981
1036
|
url = self._url_repo(project_key, repository_slug)
|
|
982
1037
|
return self.put(url, data=params)
|
|
983
1038
|
|
|
1039
|
+
def get_repo_forkable(self, project_key, repository_slug):
|
|
1040
|
+
"""Return whether a Bitbucket Server/Data Center repository is forkable.
|
|
1041
|
+
|
|
1042
|
+
:param project_key: Project key, or a ``~user`` personal repository owner.
|
|
1043
|
+
:param repository_slug: URL-compatible repository identifier.
|
|
1044
|
+
:return: The repository's ``forkable`` flag, or ``None`` when omitted
|
|
1045
|
+
by an older Bitbucket version.
|
|
1046
|
+
"""
|
|
1047
|
+
return (self.get_repo(project_key, repository_slug) or {}).get("forkable")
|
|
1048
|
+
|
|
1049
|
+
def set_repo_forkable(self, project_key, repository_slug, forkable):
|
|
1050
|
+
"""Enable or disable forking for a Server/Data Center repository.
|
|
1051
|
+
|
|
1052
|
+
The caller requires repository administration permission. This uses the
|
|
1053
|
+
repository ``PUT`` endpoint and preserves the behavior of
|
|
1054
|
+
:meth:`update_repo` for all other repository fields.
|
|
1055
|
+
|
|
1056
|
+
:param project_key: Project key, or a ``~user`` personal repository owner.
|
|
1057
|
+
:param repository_slug: URL-compatible repository identifier.
|
|
1058
|
+
:param forkable: ``True`` to allow forks or ``False`` to prohibit them.
|
|
1059
|
+
:return: Updated repository representation.
|
|
1060
|
+
"""
|
|
1061
|
+
if not isinstance(forkable, bool):
|
|
1062
|
+
raise TypeError("forkable must be a boolean")
|
|
1063
|
+
return self.update_repo(project_key, repository_slug, forkable=forkable)
|
|
1064
|
+
|
|
1065
|
+
def enable_repo_forking(self, project_key, repository_slug):
|
|
1066
|
+
"""Enable forking for a Server/Data Center repository."""
|
|
1067
|
+
return self.set_repo_forkable(project_key, repository_slug, True)
|
|
1068
|
+
|
|
1069
|
+
def disable_repo_forking(self, project_key, repository_slug):
|
|
1070
|
+
"""Disable forking for a Server/Data Center repository."""
|
|
1071
|
+
return self.set_repo_forkable(project_key, repository_slug, False)
|
|
1072
|
+
|
|
984
1073
|
def delete_repo(self, project_key, repository_slug):
|
|
985
1074
|
"""
|
|
986
1075
|
Delete a specific repository from a project. This operates based on slug not name which may
|
|
@@ -2102,6 +2191,66 @@ class Bitbucket(BitbucketBase):
|
|
|
2102
2191
|
body["parent"] = {"id": parent_id}
|
|
2103
2192
|
return self.post(url, data=body)
|
|
2104
2193
|
|
|
2194
|
+
def add_pull_request_inline_comment(
|
|
2195
|
+
self,
|
|
2196
|
+
project_key,
|
|
2197
|
+
repository_slug,
|
|
2198
|
+
pull_request_id,
|
|
2199
|
+
text,
|
|
2200
|
+
path,
|
|
2201
|
+
from_hash,
|
|
2202
|
+
to_hash,
|
|
2203
|
+
src_path=None,
|
|
2204
|
+
line=None,
|
|
2205
|
+
line_type="CONTEXT",
|
|
2206
|
+
diff_type="RANGE",
|
|
2207
|
+
file_type=None,
|
|
2208
|
+
parent_id=None,
|
|
2209
|
+
):
|
|
2210
|
+
"""
|
|
2211
|
+
Add an inline comment on a specific line or file within a pull request.
|
|
2212
|
+
Supported on Bitbucket Server / Data Center REST API.
|
|
2213
|
+
See: https://developer.atlassian.com/server/bitbucket/rest/v900/api-group-pull-requests/
|
|
2214
|
+
|
|
2215
|
+
:param project_key: The project key (e.g. "PRJ")
|
|
2216
|
+
:param repository_slug: The repository slug (e.g. "my-repo")
|
|
2217
|
+
:param pull_request_id: The pull request ID (int)
|
|
2218
|
+
:param text: The comment text
|
|
2219
|
+
:param path: The file path relative to the repo root (e.g. "src/main.py")
|
|
2220
|
+
:param from_hash: The source commit hash (the branch HEAD before the PR)
|
|
2221
|
+
:param to_hash: The target commit hash (the branch HEAD after the PR)
|
|
2222
|
+
:param src_path: The source file path (defaults to path if not provided)
|
|
2223
|
+
:param line: The line number to comment on (required for diffType=COMMIT)
|
|
2224
|
+
:param line_type: The line type for COMMIT diffs. One of: ADDED, REMOVED, CONTEXT
|
|
2225
|
+
:param diff_type: "RANGE" for whole-file comment, "COMMIT" for line-level comment
|
|
2226
|
+
:param file_type: "FROM" or "TO" — which side of the diff to comment on (COMMIT only)
|
|
2227
|
+
:param parent_id: Optional parent comment ID for threaded replies
|
|
2228
|
+
:return: The created comment object
|
|
2229
|
+
"""
|
|
2230
|
+
url = self._url_pull_request_comments(project_key, repository_slug, pull_request_id)
|
|
2231
|
+
body = {"text": text}
|
|
2232
|
+
|
|
2233
|
+
anchor = {
|
|
2234
|
+
"diffType": diff_type,
|
|
2235
|
+
"fromHash": from_hash,
|
|
2236
|
+
"toHash": to_hash,
|
|
2237
|
+
"path": path,
|
|
2238
|
+
"srcPath": src_path or path,
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
if diff_type == "COMMIT" and line is not None:
|
|
2242
|
+
anchor["line"] = line
|
|
2243
|
+
anchor["lineType"] = line_type
|
|
2244
|
+
if file_type:
|
|
2245
|
+
anchor["fileType"] = file_type
|
|
2246
|
+
|
|
2247
|
+
body["anchor"] = anchor
|
|
2248
|
+
|
|
2249
|
+
if parent_id:
|
|
2250
|
+
body["parent"] = {"id": parent_id}
|
|
2251
|
+
|
|
2252
|
+
return self.post(url, data=body)
|
|
2253
|
+
|
|
2105
2254
|
def _url_pull_request_comment(self, project_key, repository_slug, pull_request_id, comment_id):
|
|
2106
2255
|
url = f"{self._url_pull_request_comments(project_key, repository_slug, pull_request_id)}/{comment_id}"
|
|
2107
2256
|
return url
|
|
@@ -15,15 +15,19 @@ class Commits(BitbucketCloudBase):
|
|
|
15
15
|
def __get_object(self, data):
|
|
16
16
|
return Commit(data, **self._new_session_args)
|
|
17
17
|
|
|
18
|
-
def each(self, top=None, q=None, sort=None):
|
|
18
|
+
def each(self, top=None, q=None, sort=None, include=None, exclude=None, path=None):
|
|
19
19
|
"""
|
|
20
20
|
Return the list of commits in this repository.
|
|
21
21
|
|
|
22
22
|
:param top: string: Hash of commit to get the history for.
|
|
23
|
-
:param q: string:
|
|
24
|
-
|
|
23
|
+
:param q: string: Legacy query expression. Bitbucket Cloud does not
|
|
24
|
+
support arbitrary ``q`` filtering for commits; it is
|
|
25
|
+
retained for compatibility and passed to the API.
|
|
25
26
|
:param sort: string: Name of a response property to sort results.
|
|
26
27
|
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
28
|
+
:param include: string: Commit or ref to include in the history.
|
|
29
|
+
:param exclude: string: Commit or ref to exclude from the history.
|
|
30
|
+
:param path: string: File path used to filter commits.
|
|
27
31
|
|
|
28
32
|
:return: A generator for the Commit objects
|
|
29
33
|
|
|
@@ -35,6 +39,12 @@ class Commits(BitbucketCloudBase):
|
|
|
35
39
|
params["sort"] = sort
|
|
36
40
|
if q is not None:
|
|
37
41
|
params["q"] = q
|
|
42
|
+
if include is not None:
|
|
43
|
+
params["include"] = include
|
|
44
|
+
if exclude is not None:
|
|
45
|
+
params["exclude"] = exclude
|
|
46
|
+
if path is not None:
|
|
47
|
+
params["path"] = path
|
|
38
48
|
trailing = True
|
|
39
49
|
if top is not None:
|
|
40
50
|
trailing = False
|
|
@@ -60,6 +60,29 @@ class RepositoryVariables(BitbucketCloudBase):
|
|
|
60
60
|
|
|
61
61
|
return
|
|
62
62
|
|
|
63
|
+
def get_by_key(self, key):
|
|
64
|
+
"""Return the repository variable with ``key``, or ``None``.
|
|
65
|
+
|
|
66
|
+
Bitbucket requires the variable UUID for the item endpoint. This
|
|
67
|
+
helper follows the paginated collection and returns the object with
|
|
68
|
+
its UUID, avoiding callers having to implement that lookup themselves.
|
|
69
|
+
"""
|
|
70
|
+
for variable in self.each(q=f'key="{key}"'):
|
|
71
|
+
if variable.key == key:
|
|
72
|
+
return variable
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
def update_by_key(self, key, value, secured=None):
|
|
76
|
+
"""Update a repository variable by its key and return the object."""
|
|
77
|
+
variable = self.get_by_key(key)
|
|
78
|
+
if variable is None:
|
|
79
|
+
raise ValueError(f"Repository variable with key {key!r} was not found")
|
|
80
|
+
|
|
81
|
+
data = {"value": value}
|
|
82
|
+
if secured is not None:
|
|
83
|
+
data["secured"] = secured
|
|
84
|
+
return variable.update(**data)
|
|
85
|
+
|
|
63
86
|
def get(self, uuid: str): # type: ignore[override]
|
|
64
87
|
"""
|
|
65
88
|
Returns the pipeline with the uuid in this repository.
|
|
@@ -16,7 +16,7 @@ class Workspaces(BitbucketCloudBase):
|
|
|
16
16
|
def __get_object(self, data):
|
|
17
17
|
return Workspace(data, **self._new_session_args)
|
|
18
18
|
|
|
19
|
-
def each(self, role=None, q=None, sort=None):
|
|
19
|
+
def each(self, role=None, q=None, sort=None, administrator=None):
|
|
20
20
|
"""
|
|
21
21
|
Get all workspaces matching the criteria.
|
|
22
22
|
|
|
@@ -33,6 +33,9 @@ class Workspaces(BitbucketCloudBase):
|
|
|
33
33
|
:param sort: string (default is None):
|
|
34
34
|
Name of a response property to sort results.
|
|
35
35
|
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
36
|
+
:param administrator: bool (default is None):
|
|
37
|
+
Filter workspaces by whether the authenticated user
|
|
38
|
+
is a workspace administrator.
|
|
36
39
|
|
|
37
40
|
:return: A generator for the Workspace objects
|
|
38
41
|
|
|
@@ -48,6 +51,8 @@ class Workspaces(BitbucketCloudBase):
|
|
|
48
51
|
# would produce an invalid request.
|
|
49
52
|
if sort is not None:
|
|
50
53
|
params["sort"] = sort
|
|
54
|
+
if administrator is not None:
|
|
55
|
+
params["administrator"] = administrator
|
|
51
56
|
user_workspaces_url = f"{self.url.rsplit('/', 1)[0]}/user/workspaces"
|
|
52
57
|
for workspace_access in self._get_paged(user_workspaces_url, params=params, absolute=True):
|
|
53
58
|
workspace_data = workspace_access.get("workspace", workspace_access)
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""Company Calendar for Jira REST API client.
|
|
3
|
+
|
|
4
|
+
See the vendor documentation:
|
|
5
|
+
https://brizoit.atlassian.net/wiki/spaces/CCJDOCS/pages/4018044966/REST+API
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
|
|
10
|
+
from .rest_client import AtlassianRestAPI
|
|
11
|
+
|
|
12
|
+
log = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CompanyCalendar(AtlassianRestAPI):
|
|
16
|
+
"""Client for the Company Calendar for Jira REST API.
|
|
17
|
+
|
|
18
|
+
Company Calendar for Jira exposes its REST API below
|
|
19
|
+
``rest/brizo-calendar/api/1``. Authentication is done through a Bearer
|
|
20
|
+
API token that is generated and assigned to one or more calendars by an
|
|
21
|
+
administrator.
|
|
22
|
+
|
|
23
|
+
On Cloud the base URL is fixed to
|
|
24
|
+
``https://ccj.brizoit.com/ccj/rest/brizo-calendar``, while on Data Center
|
|
25
|
+
it is ``<JIRA-URL>/rest/brizo-calendar``.
|
|
26
|
+
|
|
27
|
+
Examples
|
|
28
|
+
--------
|
|
29
|
+
>>> calendar = CompanyCalendar(
|
|
30
|
+
... "https://ccj.brizoit.com/ccj",
|
|
31
|
+
... token="API-TOKEN",
|
|
32
|
+
... )
|
|
33
|
+
>>> calendar.get_calendars()
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, *args, **kwargs):
|
|
37
|
+
kwargs["api_root"] = "rest/brizo-calendar"
|
|
38
|
+
super(CompanyCalendar, self).__init__(*args, **kwargs)
|
|
39
|
+
|
|
40
|
+
def _resource_url(self, resource):
|
|
41
|
+
return self.url_joiner(self.api_root, f"api/1/{resource}")
|
|
42
|
+
|
|
43
|
+
################################################################################################
|
|
44
|
+
# Calendars
|
|
45
|
+
################################################################################################
|
|
46
|
+
|
|
47
|
+
def get_calendars(self):
|
|
48
|
+
"""
|
|
49
|
+
Return a list of all calendars associated with the token.
|
|
50
|
+
|
|
51
|
+
:return: list[dict] - Calendars.
|
|
52
|
+
"""
|
|
53
|
+
return self.get(self._resource_url("calendar"))
|
|
54
|
+
|
|
55
|
+
def get_calendar(self, calendar_id):
|
|
56
|
+
"""
|
|
57
|
+
Return details for a specific calendar, including permissions.
|
|
58
|
+
|
|
59
|
+
:param calendar_id: int/str - The calendar ID.
|
|
60
|
+
:return: dict - Calendar details.
|
|
61
|
+
"""
|
|
62
|
+
return self.get(self._resource_url(f"calendar/{calendar_id}"))
|
|
63
|
+
|
|
64
|
+
def create_calendar(self, data):
|
|
65
|
+
"""
|
|
66
|
+
Create a new calendar.
|
|
67
|
+
|
|
68
|
+
:param data: dict - The calendar payload. See the Company Calendar REST API
|
|
69
|
+
documentation for the ``publicCalendar``/``permCalendarView``/``value`` fields
|
|
70
|
+
required for public and private calendars.
|
|
71
|
+
:return: dict - The created calendar.
|
|
72
|
+
"""
|
|
73
|
+
return self.post(self._resource_url("calendar"), data=data)
|
|
74
|
+
|
|
75
|
+
def update_calendar(self, data):
|
|
76
|
+
"""
|
|
77
|
+
Update an existing calendar.
|
|
78
|
+
|
|
79
|
+
Important: when updating, the full ``value`` JSON object must be provided.
|
|
80
|
+
Any property that is not included will be overwritten or removed.
|
|
81
|
+
|
|
82
|
+
:param data: dict - The calendar payload, including its ``id``.
|
|
83
|
+
:return: dict - The updated calendar.
|
|
84
|
+
"""
|
|
85
|
+
return self.put(self._resource_url("calendar"), data=data)
|
|
86
|
+
|
|
87
|
+
def delete_calendar(self, calendar_id):
|
|
88
|
+
"""
|
|
89
|
+
Delete the specified calendar.
|
|
90
|
+
|
|
91
|
+
Deleting a calendar is possible only when the token has permission to delete it.
|
|
92
|
+
|
|
93
|
+
:param calendar_id: int/str - The calendar ID.
|
|
94
|
+
:return: response
|
|
95
|
+
"""
|
|
96
|
+
return self.delete(self._resource_url(f"calendar/{calendar_id}"))
|
|
97
|
+
|
|
98
|
+
################################################################################################
|
|
99
|
+
# Event types
|
|
100
|
+
################################################################################################
|
|
101
|
+
|
|
102
|
+
def get_event_types(self):
|
|
103
|
+
"""
|
|
104
|
+
Return all system and custom event types.
|
|
105
|
+
|
|
106
|
+
:return: list[dict] - Event types.
|
|
107
|
+
"""
|
|
108
|
+
return self.get(self._resource_url("eventypes"))
|
|
109
|
+
|
|
110
|
+
################################################################################################
|
|
111
|
+
# Sources
|
|
112
|
+
################################################################################################
|
|
113
|
+
|
|
114
|
+
def get_source(self, source_id):
|
|
115
|
+
"""
|
|
116
|
+
Return details for a specific source.
|
|
117
|
+
|
|
118
|
+
:param source_id: int/str - The source ID.
|
|
119
|
+
:return: dict - Source details.
|
|
120
|
+
"""
|
|
121
|
+
return self.get(self._resource_url(f"source/{source_id}"))
|
|
122
|
+
|
|
123
|
+
def create_source(self, data):
|
|
124
|
+
"""
|
|
125
|
+
Create a new source for a calendar.
|
|
126
|
+
|
|
127
|
+
:param data: dict - The source payload, e.g. ``eventTypeId``,
|
|
128
|
+
``calendarConfigurationId``, ``emailsEnabled`` and ``value``.
|
|
129
|
+
:return: dict - The created source.
|
|
130
|
+
"""
|
|
131
|
+
return self.post(self._resource_url("source"), data=data)
|
|
132
|
+
|
|
133
|
+
def update_source(self, data):
|
|
134
|
+
"""
|
|
135
|
+
Update an existing source.
|
|
136
|
+
|
|
137
|
+
Important: always send the full ``value`` JSON object. Any omitted
|
|
138
|
+
property will be overwritten or removed.
|
|
139
|
+
|
|
140
|
+
:param data: dict - The source payload, including its ``id``.
|
|
141
|
+
:return: dict - The updated source.
|
|
142
|
+
"""
|
|
143
|
+
return self.put(self._resource_url("source"), data=data)
|
|
144
|
+
|
|
145
|
+
def delete_source(self, source_id):
|
|
146
|
+
"""
|
|
147
|
+
Delete a source.
|
|
148
|
+
|
|
149
|
+
Deleting a source is possible only when the token has permission to delete it.
|
|
150
|
+
|
|
151
|
+
:param source_id: int/str - The source ID.
|
|
152
|
+
:return: response
|
|
153
|
+
"""
|
|
154
|
+
return self.delete(self._resource_url(f"source/{source_id}"))
|
|
155
|
+
|
|
156
|
+
################################################################################################
|
|
157
|
+
# Events
|
|
158
|
+
################################################################################################
|
|
159
|
+
|
|
160
|
+
def create_event(self, data):
|
|
161
|
+
"""
|
|
162
|
+
Create a new event (all-day, timed or recurring).
|
|
163
|
+
|
|
164
|
+
:param data: dict - The event payload, e.g. ``{"event": {...}, "mode": "add"}``.
|
|
165
|
+
:return: dict - The created event.
|
|
166
|
+
"""
|
|
167
|
+
return self.post(self._resource_url("event"), data=data)
|
|
168
|
+
|
|
169
|
+
def update_event(self, data):
|
|
170
|
+
"""
|
|
171
|
+
Update an existing event (single or recurring).
|
|
172
|
+
|
|
173
|
+
:param data: dict - The event payload, e.g. ``{"event": {...}, "mode": "edit"}``.
|
|
174
|
+
:return: dict - The updated event.
|
|
175
|
+
"""
|
|
176
|
+
return self.put(self._resource_url("event"), data=data)
|
|
177
|
+
|
|
178
|
+
def delete_event(self, event_id):
|
|
179
|
+
"""
|
|
180
|
+
Delete an event.
|
|
181
|
+
|
|
182
|
+
:param event_id: int/str - The event ID.
|
|
183
|
+
:return: response
|
|
184
|
+
"""
|
|
185
|
+
return self.delete(self._resource_url(f"event/{event_id}"))
|
|
186
|
+
|
|
187
|
+
def delete_recurring_event(self, event_id, data):
|
|
188
|
+
"""
|
|
189
|
+
Delete a recurring event occurrence, exception, or the entire recurrence chain.
|
|
190
|
+
|
|
191
|
+
Depending on ``data``, this can delete the full recurring series, a single
|
|
192
|
+
occurrence, or exclude a specific instance from the recurrence by adding an
|
|
193
|
+
exception date. See the Company Calendar REST API documentation for the
|
|
194
|
+
required ``mode``, ``select`` and ``exdate`` fields.
|
|
195
|
+
|
|
196
|
+
:param event_id: int/str - The event ID (occurrence or parent, depending on scenario).
|
|
197
|
+
:param data: dict - The deletion payload.
|
|
198
|
+
:return: response
|
|
199
|
+
"""
|
|
200
|
+
return self.delete(self._resource_url(f"event/{event_id}/recur"), data=data)
|
|
201
|
+
|
|
202
|
+
################################################################################################
|
|
203
|
+
# Search
|
|
204
|
+
################################################################################################
|
|
205
|
+
|
|
206
|
+
def search_events(self, data):
|
|
207
|
+
"""
|
|
208
|
+
Search for events within a date range, optionally scoped to a calendar or source.
|
|
209
|
+
|
|
210
|
+
:param data: dict - The search payload. Accepts either Unix timestamps
|
|
211
|
+
(``startDate``/``endDate``) or ISO dates (``startDateIso``/``endDateIso``),
|
|
212
|
+
combined with an optional ``calendarId`` or ``sourceId``.
|
|
213
|
+
:return: dict - Paginated search results.
|
|
214
|
+
"""
|
|
215
|
+
return self.post(self._resource_url("event/search"), data=data)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Atlassian Compass REST API client."""
|
|
2
|
+
|
|
3
|
+
from ..rest_client import AtlassianRestAPI
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Compass(AtlassianRestAPI):
|
|
7
|
+
"""Client for the Compass gateway REST API.
|
|
8
|
+
|
|
9
|
+
Compass Cloud exposes these endpoints below ``/gateway/api`` on an
|
|
10
|
+
Atlassian site. JSON requests use ``data`` or ``json`` as accepted by the
|
|
11
|
+
base REST client; multipart methods accept a file path or a ``files``
|
|
12
|
+
mapping.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self, *args, **kwargs):
|
|
16
|
+
kwargs["api_root"] = "gateway/api"
|
|
17
|
+
super().__init__(*args, **kwargs)
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def _multipart_file(filename, files=None):
|
|
21
|
+
if files is not None:
|
|
22
|
+
return files, None
|
|
23
|
+
if filename is None:
|
|
24
|
+
raise ValueError("filename or files is required")
|
|
25
|
+
handle = open(filename, "rb")
|
|
26
|
+
return {"file": handle}, handle
|
|
27
|
+
|
|
28
|
+
def send_metric(self, data=None):
|
|
29
|
+
"""Send a metric value to Compass."""
|
|
30
|
+
return self.post(self.url_joiner(self.api_root, "compass/v1/metrics"), data=data)
|
|
31
|
+
|
|
32
|
+
def send_event(self, data=None):
|
|
33
|
+
"""Send a streamlined event to Compass."""
|
|
34
|
+
return self.post(self.url_joiner(self.api_root, "compass/v1/events"), data=data)
|
|
35
|
+
|
|
36
|
+
def get_entitlement_results(self, data=None):
|
|
37
|
+
"""Retrieve entitlement results for a Compass component."""
|
|
38
|
+
return self.post(self.url_joiner(self.api_root, "compass/v1/entitlements"), data=data)
|
|
39
|
+
|
|
40
|
+
def invoke_webhook(self, webhook_id, data=None):
|
|
41
|
+
"""Invoke an inbound Compass webhook."""
|
|
42
|
+
path = self.url_joiner(self.api_root, f"compass/v1/webhooks/{webhook_id}")
|
|
43
|
+
return self.post(path, data=data)
|
|
44
|
+
|
|
45
|
+
def upload_package_dependencies_lock_file(
|
|
46
|
+
self, source_id, base_source_url, component_id, filename=None, files=None
|
|
47
|
+
):
|
|
48
|
+
"""Upload a package dependency lock file."""
|
|
49
|
+
multipart, handle = self._multipart_file(filename, files)
|
|
50
|
+
try:
|
|
51
|
+
path = self.url_joiner(self.api_root, "compass/v1/package_dependencies/lock_file")
|
|
52
|
+
params = {
|
|
53
|
+
"sourceId": source_id,
|
|
54
|
+
"baseSourceUrl": base_source_url,
|
|
55
|
+
"componentId": component_id,
|
|
56
|
+
}
|
|
57
|
+
return self.put(path, params=params, files=multipart)
|
|
58
|
+
finally:
|
|
59
|
+
if handle:
|
|
60
|
+
handle.close()
|
|
61
|
+
|
|
62
|
+
def delete_package_dependencies(self, component_id, source_id):
|
|
63
|
+
"""Delete package dependencies for a component and source."""
|
|
64
|
+
path = self.url_joiner(self.api_root, f"compass/v1/package_dependencies/lock_file/{component_id}/{source_id}")
|
|
65
|
+
return self.delete(path)
|
|
66
|
+
|
|
67
|
+
def get_forge_app_attachment(self, component_id, forge_app_id, key, not_json_response=True):
|
|
68
|
+
"""Download a Forge app attachment belonging to a component."""
|
|
69
|
+
path = self.url_joiner(
|
|
70
|
+
self.api_root, f"compass/v1/component/{component_id}/app/{forge_app_id}/attachment/{key}"
|
|
71
|
+
)
|
|
72
|
+
return self.get(path, not_json_response=not_json_response)
|
|
73
|
+
|
|
74
|
+
def upload_forge_app_attachment(self, component_id, forge_app_id, key, filename=None, files=None):
|
|
75
|
+
"""Upload a Forge app attachment."""
|
|
76
|
+
multipart, handle = self._multipart_file(filename, files)
|
|
77
|
+
try:
|
|
78
|
+
path = self.url_joiner(
|
|
79
|
+
self.api_root, f"compass/v1/component/{component_id}/app/{forge_app_id}/attachment/{key}"
|
|
80
|
+
)
|
|
81
|
+
return self.put(path, files=multipart)
|
|
82
|
+
finally:
|
|
83
|
+
if handle:
|
|
84
|
+
handle.close()
|
|
85
|
+
|
|
86
|
+
def delete_forge_app_attachment(self, component_id, forge_app_id, key):
|
|
87
|
+
"""Delete a Forge app attachment."""
|
|
88
|
+
path = self.url_joiner(
|
|
89
|
+
self.api_root, f"compass/v1/component/{component_id}/app/{forge_app_id}/attachment/{key}"
|
|
90
|
+
)
|
|
91
|
+
return self.delete(path)
|
|
92
|
+
|
|
93
|
+
def upload_component_api_spec(self, component_id, filename=None, files=None):
|
|
94
|
+
"""Upload an OpenAPI specification for a Compass component."""
|
|
95
|
+
multipart, handle = self._multipart_file(filename, files)
|
|
96
|
+
try:
|
|
97
|
+
path = self.url_joiner(self.api_root, f"compass/v1/component/{component_id}/api_specs")
|
|
98
|
+
return self.put(path, files=multipart)
|
|
99
|
+
finally:
|
|
100
|
+
if handle:
|
|
101
|
+
handle.close()
|
|
102
|
+
|
|
103
|
+
def delete_component_api_spec(self, component_id):
|
|
104
|
+
"""Delete the API specification for a Compass component."""
|
|
105
|
+
path = self.url_joiner(self.api_root, f"compass/v1/component/{component_id}/api_specs")
|
|
106
|
+
return self.delete(path)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
__all__ = ["Compass"]
|
atlassian/confluence/base.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
4
|
import re
|
|
5
|
-
from urllib.parse import urljoin, urlparse
|
|
5
|
+
from urllib.parse import parse_qsl, urljoin, urlparse
|
|
6
6
|
import logging
|
|
7
7
|
from requests import HTTPError
|
|
8
8
|
from ..rest_client import AtlassianRestAPI
|
|
@@ -167,6 +167,7 @@ class ConfluenceBase(AtlassianRestAPI):
|
|
|
167
167
|
params = {}
|
|
168
168
|
|
|
169
169
|
while True:
|
|
170
|
+
current_url = url
|
|
170
171
|
response = self.get(
|
|
171
172
|
url,
|
|
172
173
|
trailing=trailing,
|
|
@@ -190,6 +191,16 @@ class ConfluenceBase(AtlassianRestAPI):
|
|
|
190
191
|
if url is None:
|
|
191
192
|
break
|
|
192
193
|
|
|
194
|
+
# Cloud V2 cursor links contain a relative endpoint and a cursor
|
|
195
|
+
# query. Reusing the already-resolved endpoint preserves both
|
|
196
|
+
# ``/wiki`` and API-gateway tenant prefixes.
|
|
197
|
+
parsed_next = urlparse(url)
|
|
198
|
+
if getattr(self, "api_version", None) == 2 and parsed_next.query and not parsed_next.scheme:
|
|
199
|
+
url = current_url
|
|
200
|
+
params = dict(parse_qsl(parsed_next.query, keep_blank_values=True))
|
|
201
|
+
trailing = False
|
|
202
|
+
continue
|
|
203
|
+
|
|
193
204
|
if not urlparse(url).scheme:
|
|
194
205
|
# Confluence returns both ``/rest/api/...`` and
|
|
195
206
|
# ``rest/api/...`` forms for next links. Neither is an
|
|
@@ -155,6 +155,23 @@ class Cloud(ConfluenceCloudBase):
|
|
|
155
155
|
"""Return every version of a legacy Confluence Cloud page as a list."""
|
|
156
156
|
return list(self.iter_page_versions(page_id, limit=limit, expand=expand))
|
|
157
157
|
|
|
158
|
+
def remove_content_history(self, page_id, version_number):
|
|
159
|
+
"""Remove one historical page version from Confluence Cloud.
|
|
160
|
+
|
|
161
|
+
The old implementation used the retired ``rest/experimental`` route.
|
|
162
|
+
Cloud exposes the operation through the versioned v1 content endpoint.
|
|
163
|
+
"""
|
|
164
|
+
endpoint = self._cloud_wiki_url(f"rest/api/content/{page_id}/version/{version_number}")
|
|
165
|
+
return self.delete(endpoint, absolute=True)
|
|
166
|
+
|
|
167
|
+
def remove_page_history(self, page_id, version_number):
|
|
168
|
+
"""Alias for :meth:`remove_content_history`."""
|
|
169
|
+
return self.remove_content_history(page_id, version_number)
|
|
170
|
+
|
|
171
|
+
def remove_content_history_in_cloud(self, page_id, version_id):
|
|
172
|
+
"""Backward-compatible alias for removing a Cloud page version."""
|
|
173
|
+
return self.remove_content_history(page_id, version_id)
|
|
174
|
+
|
|
158
175
|
def get_content_by_type(self, content_type, **kwargs):
|
|
159
176
|
"""Get content by type (page, blogpost, etc.)."""
|
|
160
177
|
return self.get("content", params={"type": content_type, **kwargs})
|