atlassian-python-api 5.0.3__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.
@@ -2191,6 +2191,66 @@ class Bitbucket(BitbucketBase):
2191
2191
  body["parent"] = {"id": parent_id}
2192
2192
  return self.post(url, data=body)
2193
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
+
2194
2254
  def _url_pull_request_comment(self, project_key, repository_slug, pull_request_id, comment_id):
2195
2255
  url = f"{self._url_pull_request_comments(project_key, repository_slug, pull_request_id)}/{comment_id}"
2196
2256
  return url
@@ -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)
@@ -7,7 +7,7 @@ import re
7
7
  import sys
8
8
  import time
9
9
  import warnings
10
- from typing import cast
10
+ from typing import Optional, cast
11
11
  from urllib.parse import urljoin
12
12
 
13
13
  import requests
@@ -238,7 +238,8 @@ class Server(ConfluenceServerBase):
238
238
 
239
239
  def get_page_space(self, page_id):
240
240
  """Get space key from page ID."""
241
- page = self.get_content(page_id, expand="space")
241
+ params = {"expand": "space"}
242
+ page = self.get(f"content/{page_id}", params=params)
242
243
  return page.get("space", {}).get("key")
243
244
 
244
245
  def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, expand=None):
@@ -337,13 +338,16 @@ class Server(ConfluenceServerBase):
337
338
 
338
339
  def get_page_id(self, space, title, type="page"):
339
340
  """
340
- Provide content id from search result by title and space.
341
+ Get page ID by searching for it by space key and title - returns the ID from the first result or None if not found.
341
342
  :param space: SPACE key
342
343
  :param title: title
343
344
  :param type: type of content: Page or Blogpost. Defaults to page
344
345
  :return:
345
346
  """
346
- return (self.get_page_by_title(space, title, type=type) or {}).get("id")
347
+ json_response = self.get_page_by_title(space, title, type=type)
348
+ if json_response and "results" in json_response and len(json_response["results"]) > 0:
349
+ return json_response["results"][0]["id"]
350
+ return None
347
351
 
348
352
  def get_parent_content_id(self, page_id):
349
353
  """
@@ -1153,16 +1157,38 @@ class Server(ConfluenceServerBase):
1153
1157
  path = f"rest/api/content/{page_id}/child/attachment"
1154
1158
 
1155
1159
  try:
1156
- # Confluence's multipart PUT endpoint atomically creates an
1157
- # attachment or adds a revision when the filename already
1158
- # exists. A GET followed by POST is racy and Cloud may reject
1159
- # the attachment-data endpoint for a same-name upload.
1160
- response = self.put(
1161
- path=path,
1162
- data=data,
1163
- headers=headers,
1164
- files={"file": (name, content, content_type)},
1165
- )
1160
+ # Confluence Server doesn't support PUT on the child/attachment endpoint.
1161
+ # We need to check if the attachment exists first, then create or update accordingly.
1162
+ # GET existing attachment to check if it exists
1163
+ existing_attachment = None
1164
+ try:
1165
+ attachments = self.get(path=path, headers=headers)
1166
+ if "results" in attachments:
1167
+ for attachment in attachments["results"]:
1168
+ if attachment.get("title") == name:
1169
+ existing_attachment = attachment
1170
+ break
1171
+ except HTTPError:
1172
+ pass
1173
+
1174
+ if existing_attachment:
1175
+ # Update existing attachment using PUT on the specific attachment ID
1176
+ attachment_id = existing_attachment["id"]
1177
+ update_path = f"rest/api/content/{attachment_id}"
1178
+ response = self.put(
1179
+ path=update_path,
1180
+ data=data,
1181
+ headers=headers,
1182
+ files={"file": (name, content, content_type)},
1183
+ )
1184
+ else:
1185
+ # Create new attachment using POST
1186
+ response = self.post(
1187
+ path=path,
1188
+ data=data,
1189
+ headers=headers,
1190
+ files={"file": (name, content, content_type)},
1191
+ )
1166
1192
  except HTTPError as e:
1167
1193
  if e.response.status_code == 403:
1168
1194
  # Raise ApiError as the documented reason is ambiguous
@@ -1366,6 +1392,36 @@ class Server(ConfluenceServerBase):
1366
1392
  url = f"rest/experimental/content/{attachment_id}/version/{version}"
1367
1393
  return self.delete(url)
1368
1394
 
1395
+ def move_or_update_attachment_json_rpc(
1396
+ self,
1397
+ originalContentId: str,
1398
+ originalName: str,
1399
+ newContentEntityId: Optional[str] = None,
1400
+ newName: Optional[str] = None,
1401
+ ):
1402
+ """
1403
+ Move attachment from source confluence page to destination confluence page optionally with new title
1404
+ OR
1405
+ Just update attachment from source confluence page with new title
1406
+ via JSON-RPC.
1407
+ :param str originalContentId: confluence source page id
1408
+ :param str newContentEntityId: confluence destination page id
1409
+ :param str originalName: source attachment title
1410
+ :param str newName: new attachment title
1411
+ """
1412
+ if self.api_version == "cloud" or self.cloud:
1413
+ return {}
1414
+ url = "rpc/json-rpc/confluenceservice-v2"
1415
+ data = {
1416
+ "jsonrpc": "2.0",
1417
+ "method": "moveAttachment",
1418
+ "id": 9,
1419
+ "params": [originalContentId, originalName, newContentEntityId, newName],
1420
+ }
1421
+
1422
+ response = self.post(url, data=data)
1423
+ return (response or {}).get("result") or {}
1424
+
1369
1425
  def remove_page_attachment_keep_version(self, page_id, filename, keep_last_versions):
1370
1426
  """
1371
1427
  Keep last versions