Skip to content

Commit 217e424

Browse files
authored
Confluence update or create method (atlassian-api#1050)
* Adjust fullwidth * Cleanup mistake
1 parent 0e999c3 commit 217e424

File tree

9 files changed

+75
-33
lines changed

9 files changed

+75
-33
lines changed

atlassian/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.28.2
1+
3.29.0

atlassian/bitbucket/__init__.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def get_users_info(self, user_filter=None, start=0, limit=25):
132132
def get_current_license(self):
133133
"""
134134
Retrieves details about the current license, as well as the current status of the system with
135-
regards to the installed license. The status includes the current number of users applied
135+
regard to the installed license. The status includes the current number of users applied
136136
toward the license limit, as well as any status messages about the license (warnings about expiry
137137
or user counts exceeding license limits).
138138
The authenticated user must have ADMIN permission. Unauthenticated users, and non-administrators,
@@ -414,7 +414,7 @@ def _url_project_users(self, project_key):
414414

415415
def project_users(self, key, start=0, limit=None, filter_str=None):
416416
"""
417-
Get users who has permission in project
417+
Get users with permission in project
418418
:param key: The project key
419419
:param filter_str: OPTIONAL: users filter string
420420
:param start:
@@ -447,9 +447,9 @@ def project_users_with_administrator_permissions(self, key):
447447

448448
def project_grant_user_permissions(self, project_key, username, permission):
449449
"""
450-
Grant the specified project permission to an specific user
450+
Grant the specified project permission to a specific user
451451
:param project_key: The project key
452-
:param username: user name to be granted
452+
:param username: username to be granted
453453
:param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
454454
:return:
455455
"""
@@ -464,7 +464,7 @@ def project_remove_user_permissions(self, project_key, username):
464464
the specified project or a higher global permission to call this resource.
465465
In addition, a user may not revoke their own project permissions if they do not have a higher global permission.
466466
:param project_key: The project key
467-
:param username: user name to be granted
467+
:param username: username to be granted
468468
:return:
469469
"""
470470
url = self._url_project_users(project_key)
@@ -496,7 +496,7 @@ def project_groups(self, key, start=0, limit=None, filter_str=None):
496496

497497
def project_grant_group_permissions(self, project_key, group_name, permission):
498498
"""
499-
Grant the specified project permission to an specific group
499+
Grant the specified project permission to a specific group
500500
:param project_key: The project key
501501
:param group_name: group to be granted
502502
:param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
@@ -801,7 +801,7 @@ def reindex_repo(self, project_key, repository_slug):
801801

802802
def reindex_repo_dev_panel(self, project_key, repository_slug):
803803
"""
804-
Reindex all of the Jira issues related to this repository_slug, including branches and pull requests.
804+
Reindex all the Jira issues related to this repository_slug, including branches and pull requests.
805805
This automatically happens as part of an upgrade, and calling this manually should only be required
806806
if something unforeseen happens and the index becomes out of sync.
807807
The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
@@ -917,7 +917,7 @@ def _url_repo_users(self, project_key, repo):
917917

918918
def repo_users(self, project_key, repo_key, start=0, limit=None, filter_str=None):
919919
"""
920-
Get users who has permission in repository
920+
Get users with permission in repository
921921
:param start:
922922
:param limit:
923923
:param project_key: The project key
@@ -937,7 +937,7 @@ def repo_users(self, project_key, repo_key, start=0, limit=None, filter_str=None
937937

938938
def repo_grant_user_permissions(self, project_key, repo_key, username, permission):
939939
"""
940-
Grant the specified repository permission to an specific user
940+
Grant the specified repository permission to a specific user
941941
:param project_key: The project key
942942
:param repo_key: The repository key (slug)
943943
:param username: user name to be granted
@@ -1032,7 +1032,7 @@ def repo_groups_with_administrator_permissions(self, project_key, repo_key):
10321032

10331033
def repo_grant_group_permissions(self, project_key, repo_key, groupname, permission):
10341034
"""
1035-
Grant the specified repository permission to an specific group
1035+
Grant the specified repository permission to a specific group
10361036
Promote or demote a group's permission level for the specified repository. Available repository permissions are:
10371037
REPO_READ
10381038
REPO_WRITE
@@ -1830,9 +1830,9 @@ def delete_pull_request_comment(self, project_key, repository_slug, pull_request
18301830
Delete a comment.
18311831
Only the repository admin or user who created a comment may update it.
18321832
1833-
Note: the supplied supplied JSON object must contain a version
1833+
Note: the supplied JSON object must contain a version
18341834
that must match the server's version of the comment
1835-
or the delete will fail.
1835+
or delete will fail.
18361836
"""
18371837
url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
18381838
data = {"version": comment_version}

atlassian/bitbucket/cloud/repositories/pipelines.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,4 @@ def log(self, start=None, end=None):
256256

257257
if start is None:
258258
return response.content
259-
return (response.headers["Content-Range"].split("/")[1], response.content)
259+
return response.headers["Content-Range"].split("/")[1], response.content

atlassian/bitbucket/server/projects/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ def create(self, name, key, description, avatar=None):
3737
3838
API docs: https://docs.atlassian.com/bitbucket-server/rest/7.8.0/bitbucket-rest.html#idp148
3939
"""
40-
return self.__get_object(self.post(None, data={"name": name, "key": key, "description": description}))
40+
data = {"name": name, "key": key, "description": description}
41+
if avatar:
42+
data["avatar"] = avatar
43+
return self.__get_object(self.post(None, data=data))
4144

4245
def each(self, name=None, permission=None):
4346
"""

atlassian/confluence.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ def update_page(
14931493
minor_edit=False,
14941494
version_comment=None,
14951495
always_update=False,
1496+
full_width=False,
14961497
):
14971498
"""
14981499
Update page if already exist
@@ -1506,9 +1507,10 @@ def update_page(
15061507
If False then notifications will be sent.
15071508
:param version_comment: Version comment
15081509
:param always_update: Whether always to update (suppress content check)
1510+
:param full_width: OPTIONAL: Default False
15091511
:return:
15101512
"""
1511-
log.info('Updating {type} "{title}"'.format(title=title, type=type))
1513+
log.info('Updating {type} "{title}" with {parent_id}'.format(title=title, type=type, parent_id=parent_id))
15121514

15131515
if not always_update and body is not None and self.is_page_content_is_already_updated(page_id, body, title):
15141516
return self.get_page_by_id(page_id)
@@ -1537,6 +1539,9 @@ def update_page(
15371539
if version_comment:
15381540
data["version"]["message"] = version_comment
15391541

1542+
if full_width is True:
1543+
data["metadata"]["properties"]["content-appearance-draft"] = {"value": "full-width"}
1544+
data["metadata"]["properties"]["content-appearance-published"] = {"value": "full-width"}
15401545
try:
15411546
response = self.put("rest/api/content/{0}".format(page_id), data=data)
15421547
except HTTPError as e:
@@ -1699,6 +1704,7 @@ def update_or_create(
16991704
minor_edit=False,
17001705
version_comment=None,
17011706
editor=None,
1707+
full_width=False,
17021708
):
17031709
"""
17041710
Update page or create a page if it is not exists
@@ -1709,6 +1715,7 @@ def update_or_create(
17091715
:param minor_edit: Update page without notification
17101716
:param version_comment: Version comment
17111717
:param editor: OPTIONAL: v2 to be created in the new editor
1718+
:param full_width: OPTIONAL: Default is False
17121719
:return:
17131720
"""
17141721
space = self.get_page_space(parent_id)
@@ -1724,6 +1731,7 @@ def update_or_create(
17241731
representation=representation,
17251732
minor_edit=minor_edit,
17261733
version_comment=version_comment,
1734+
full_width=full_width,
17271735
)
17281736
else:
17291737
result = self.create_page(
@@ -1733,6 +1741,7 @@ def update_or_create(
17331741
body=body,
17341742
representation=representation,
17351743
editor=editor,
1744+
full_width=full_width,
17361745
)
17371746

17381747
log.info(

atlassian/insight.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from .rest_client import AtlassianRestAPI
5+
from deprecated import deprecated
56

67
log = logging.getLogger(__name__)
78

@@ -197,7 +198,7 @@ def start_import_configuration(self, import_id):
197198
:param import_id:
198199
:return:
199200
"""
200-
url = self.url_joiner(self.api_root, "import/start/{import_id}")
201+
url = self.url_joiner(self.api_root, "import/start/{import_id}".format(import_id=import_id))
201202
return self.post(url)
202203

203204
# Index
@@ -279,22 +280,22 @@ def get_object(self, object_id):
279280
url = self.url_joiner(self.api_root, "object/{id}".format(id=object_id))
280281
return self.get(url)
281282

282-
def update_object(self, object_id, objectTypeId, attributes, hasAvatar=False, avatarUUID=""):
283+
def update_object(self, object_id, object_type_id, attributes, has_avatar=False, avatar_UUID=""):
283284
"""
284285
Update an existing object in Insight
285286
286287
:param object_id:
287-
:param objectTypeId:
288+
:param object_type_id:
288289
:param attributes:
289-
:param hasAvatar:
290-
:param avatarUUID:
290+
:param has_avatar:
291+
:param avatar_UUID:
291292
:return:
292293
"""
293294
body = {
294295
"attributes": attributes,
295-
"objectTypeId": objectTypeId,
296-
"avatarUUID": avatarUUID,
297-
"hasAvatar": hasAvatar,
296+
"objectTypeId": object_type_id,
297+
"avatarUUID": avatar_UUID,
298+
"hasAvatar": has_avatar,
298299
}
299300
url = self.url_joiner(self.api_root, "object/{id}".format(id=object_id))
300301
return self.put(url, data=body)
@@ -313,7 +314,7 @@ def get_object_attributes(self, object_id):
313314
"""
314315
List all attributes for the given object
315316
316-
:param id:
317+
:param object_id:
317318
:return:
318319
"""
319320
url = self.url_joiner(self.api_root, "object/{id}/attributes".format(id=object_id))
@@ -323,7 +324,7 @@ def get_object_history(self, object_id, asc=False, abbreviate=True):
323324
"""
324325
Retrieve the history entries for this object
325326
326-
:param id:
327+
:param object_id:
327328
:param asc:
328329
:param abbreviate:
329330
:return:
@@ -332,11 +333,17 @@ def get_object_history(self, object_id, asc=False, abbreviate=True):
332333
url = self.url_joiner(self.api_root, "object/{id}/history".format(id=object_id))
333334
return self.get(url, params=params)
334335

336+
@deprecated(version="3.29.0", reason="Use get_object_reference_info()")
335337
def get_object_referenceinfo(self, object_id):
338+
"""Let's use the get_object_reference_info()"""
339+
log.warning("Please, be informed that is deprecated as typo naming")
340+
self.get_object_reference_info(object_id)
341+
342+
def get_object_reference_info(self, object_id):
336343
"""
337344
Find all references for an object
338345
339-
:param id:
346+
:param object_id:
340347
:return:
341348
"""
342349
url = self.url_joiner(self.api_root, "object/{id}/referenceinfo".format(id=object_id))
@@ -439,7 +446,7 @@ def list_objectschema(self):
439446
url = self.url_joiner(self.api_root, "objectschema/list")
440447
return self.get(url)
441448

442-
def create_objectschema(self, objectSchemaKey, description):
449+
def create_objectschema(self, object_schema_key, description):
443450
raise NotImplementedError
444451

445452
def get_objectschema(self, schema_id):

atlassian/jira.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ def user_property(self, username=None, account_id=None, key_property=None):
16531653
:param key_property:
16541654
:return:
16551655
"""
1656+
params = {}
16561657
if username or not self.cloud:
16571658
params = {"username": username}
16581659
elif account_id or self.cloud:
@@ -2731,7 +2732,7 @@ def add_field(self, field_id, screen_id, tab_id):
27312732
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/search
27322733
"""
27332734

2734-
def jql(self, jql, fields="*all", start=0, limit=None, expand=None, validate_query=None, advanced_mode=None):
2735+
def jql(self, jql, fields="*all", start=0, limit=None, expand=None, validate_query=None):
27352736
"""
27362737
Get issues from jql search result with all related fields
27372738
:param jql:
@@ -2740,7 +2741,7 @@ def jql(self, jql, fields="*all", start=0, limit=None, expand=None, validate_que
27402741
:param limit: OPTIONAL: The limit of the number of issues to return, this may be restricted by
27412742
fixed system limits. Default by built-in method: 50
27422743
:param expand: OPTIONAL: expand the search result
2743-
:param validate_query: Whether to validate the JQL query
2744+
:param validate_query: OPTIONAL: Whether to validate the JQL query
27442745
:return:
27452746
"""
27462747
params = {}
@@ -3750,6 +3751,7 @@ def tempo_timesheets_get_worklogs(
37503751
url = "rest/tempo-timesheets/3/worklogs/"
37513752
return self.get(url, params=params)
37523753

3754+
# noinspection PyIncorrectDocstring
37533755
def tempo_4_timesheets_find_worklogs(self, **params):
37543756
"""
37553757
Find existing worklogs with searching parameters.

atlassian/rest_client.py

+21
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,14 @@ def post(
304304
advanced_mode=False,
305305
):
306306
"""
307+
:param path:
308+
:param data:
309+
:param json:
310+
:param headers:
311+
:param files:
312+
:param params:
313+
:param trailing:
314+
:param absolute:
307315
:param advanced_mode: bool, OPTIONAL: Return the raw response
308316
:return: if advanced_mode is not set - returns dictionary. If it is set - returns raw response.
309317
"""
@@ -334,6 +342,13 @@ def put(
334342
advanced_mode=False,
335343
):
336344
"""
345+
:param path: Path of request
346+
:param data:
347+
:param headers: adjusted headers, usually it's default
348+
:param files:
349+
:param trailing:
350+
:param params:
351+
:param absolute:
337352
:param advanced_mode: bool, OPTIONAL: Return the raw response
338353
:return: if advanced_mode is not set - returns dictionary. If it is set - returns raw response.
339354
"""
@@ -363,6 +378,12 @@ def delete(
363378
):
364379
"""
365380
Deletes resources at given paths.
381+
:param path:
382+
:param data:
383+
:param headers:
384+
:param params:
385+
:param trailing:
386+
:param absolute:
366387
:param advanced_mode: bool, OPTIONAL: Return the raw response
367388
:rtype: dict
368389
:return: Empty dictionary to have consistent interface.

docs/confluence.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Page actions
7070
.. code-block:: python
7171
7272
# Create page from scratch
73-
confluence.create_page(space, title, body, parent_id=None, type='page', representation='storage', editor='v2')
73+
confluence.create_page(space, title, body, parent_id=None, type='page', representation='storage', editor='v2', full_width=False)
7474
7575
# This method removes a page, if it has recursive flag, method removes including child pages
7676
confluence.remove_page(page_id, status=None, recursive=False)
@@ -85,10 +85,10 @@ Page actions
8585
confluence.remove_page_as_draft(page_id)
8686
8787
# Update page if already exist
88-
confluence.update_page(page_id, title, body, parent_id=None, type='page', representation='storage', minor_edit=False)
88+
confluence.update_page(page_id, title, body, parent_id=None, type='page', representation='storage', minor_edit=False, full_width=False)
8989
9090
# Update page or create page if it is not exists
91-
confluence.update_or_create(parent_id, title, body, representation='storage')
91+
confluence.update_or_create(parent_id, title, body, representation='storage', full_width=False)
9292
9393
# Append body to page if already exist
9494
confluence.append_page(page_id, title, append_body, parent_id=None, type='page', representation='storage', minor_edit=False)

0 commit comments

Comments
 (0)