atlassian-python-api 5.0.2__py3-none-any.whl → 5.0.3__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 CHANGED
@@ -1 +1 @@
1
- 5.0.2
1
+ 5.0.3
atlassian/__init__.py CHANGED
@@ -6,12 +6,13 @@ from .bamboo import Bamboo
6
6
  from .bitbucket import Bitbucket
7
7
  from .bitbucket import Bitbucket as Stash
8
8
  from .cloud_admin import CloudAdmin, CloudAdminOrgs, CloudAdminUsers
9
+ from .compass import Compass
9
10
  from .confluence import Confluence, ConfluenceBase, ConfluenceCloud, ConfluenceServer
10
11
  from .confluence.cloud.cloud import ConfluenceCloud as ConfluenceV2
11
12
  from .crowd import Crowd
12
13
  from .insight import Insight
13
14
  from .insight import Insight as Assets # used for Insight on-premise
14
- from .assets import AssetsCloud # used for Insight Cloud
15
+ from .assets import AssetsCloud, AssetsDataCenter, AssetsServer # Assets Cloud and Data Center
15
16
  from .jira import Jira, JiraCloud, JiraServer, JiraServiceManagement, JiraSoftware, create_jira_cloud
16
17
  from .marketplace import MarketPlace
17
18
  from .portfolio import Portfolio
@@ -46,6 +47,7 @@ __all__ = [
46
47
  "CloudAdminOrgs",
47
48
  "CloudAdminUsers",
48
49
  "CloudAdmin",
50
+ "Compass",
49
51
  "Portfolio",
50
52
  "Bamboo",
51
53
  "Stash",
@@ -57,6 +59,8 @@ __all__ = [
57
59
  "Insight",
58
60
  "Assets",
59
61
  "AssetsCloud",
62
+ "AssetsDataCenter",
63
+ "AssetsServer",
60
64
  "TempoCloud",
61
65
  "TempoServer",
62
66
  "YogiJiraCloud",
@@ -0,0 +1,6 @@
1
+ """Assets clients for Jira Cloud and Jira Data Center."""
2
+
3
+ from .assets_cloud import AssetsCloud
4
+ from .assets_server import AssetsDataCenter, AssetsServer
5
+
6
+ __all__ = ["AssetsCloud", "AssetsDataCenter", "AssetsServer"]
@@ -1,7 +1,7 @@
1
1
  # coding=utf-8
2
2
  import logging
3
3
 
4
- from .rest_client import AtlassianRestAPI
4
+ from ..rest_client import AtlassianRestAPI
5
5
 
6
6
  # from deprecated import deprecated
7
7
 
@@ -72,6 +72,11 @@ class AssetsCloud(AtlassianRestAPI):
72
72
  """
73
73
  return next(iter(self._get_assets_workspace_ids()))
74
74
 
75
+ @staticmethod
76
+ def _params(**kwargs):
77
+ """Drop unset query parameters while preserving false/zero values."""
78
+ return {key: value for key, value in kwargs.items() if value is not None}
79
+
75
80
  # Attachments
76
81
  def get_attachments_of_objects(self, object_id):
77
82
  """
@@ -215,6 +220,11 @@ class AssetsCloud(AtlassianRestAPI):
215
220
  url = self.url_joiner(self.api_root, "icon/global")
216
221
  return self.get(url)
217
222
 
223
+ def get_icon_image(self, icon_id, not_json_response=True):
224
+ """Return the binary image for an Assets icon."""
225
+ url = self.url_joiner(self.api_root, f"icon/{icon_id}/icon.png")
226
+ return self.get(url, not_json_response=not_json_response)
227
+
218
228
  # Import
219
229
  # Start configured imports. To see an ongoing import see the Progress resource
220
230
  def start_import_configuration(self, import_id):
@@ -230,6 +240,62 @@ class AssetsCloud(AtlassianRestAPI):
230
240
  )
231
241
  return self.post(url)
232
242
 
243
+ def get_import_source(self, import_source_id):
244
+ return self.get(self.url_joiner(self.api_root, f"importsource/{import_source_id}"))
245
+
246
+ def update_import_source_mapping(self, import_source_id, data, partial=False):
247
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/mapping")
248
+ if partial:
249
+ return self.patch(url, data=data)
250
+ return self.put(url, data=data)
251
+
252
+ def get_import_mapping_progress(self, import_source_id, resource_id):
253
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/mapping/progress/{resource_id}")
254
+ return self.get(url)
255
+
256
+ def get_import_config_status(self, import_source_id):
257
+ return self.get(self.url_joiner(self.api_root, f"importsource/{import_source_id}/configstatus"))
258
+
259
+ def get_import_schema_and_mapping(self, import_source_id):
260
+ return self.get(self.url_joiner(self.api_root, f"importsource/{import_source_id}/schema-and-mapping"))
261
+
262
+ def create_import_execution(self, import_source_id, data=None):
263
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/executions")
264
+ return self.post(url, data=data)
265
+
266
+ def delete_import_execution(self, import_source_id, import_execution_id):
267
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/executions/{import_execution_id}")
268
+ return self.delete(url)
269
+
270
+ def update_import_execution_progress(self, import_source_id, import_execution_id, data=None):
271
+ url = self.url_joiner(
272
+ self.api_root, f"importsource/{import_source_id}/executions/{import_execution_id}/progress"
273
+ )
274
+ return self.put(url, data=data)
275
+
276
+ def add_import_execution_data(self, import_source_id, import_execution_id, data=None):
277
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/executions/{import_execution_id}/data")
278
+ return self.post(url, data=data)
279
+
280
+ def get_import_execution_status(self, import_source_id, import_execution_id):
281
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/executions/{import_execution_id}/status")
282
+ return self.get(url)
283
+
284
+ def get_import_executions_status(self, import_source_id):
285
+ return self.get(self.url_joiner(self.api_root, f"importsource/{import_source_id}/executions/status"))
286
+
287
+ def add_failed_import_execution_history(self, import_source_id, execution_id, data=None):
288
+ url = self.url_joiner(
289
+ self.api_root, f"importsource/{import_source_id}/executions/{execution_id}/history/failed"
290
+ )
291
+ return self.post(url, data=data)
292
+
293
+ def create_import_token(self, import_source_id, data=None):
294
+ return self.post(self.url_joiner(self.api_root, f"importsource/{import_source_id}/token"), data=data)
295
+
296
+ def get_import_schedule(self, import_source_id):
297
+ return self.get(self.url_joiner(self.api_root, f"importsource/{import_source_id}/schedule"))
298
+
233
299
  # Index
234
300
  # Handle the indexing of Assets
235
301
  def reindex_assets(self):
@@ -275,6 +341,55 @@ class AssetsCloud(AtlassianRestAPI):
275
341
  url = self.url_joiner(self.api_root, "object/aql")
276
342
  return self.post(url, params=params, data=data)
277
343
 
344
+ def get_aql_objects(
345
+ self,
346
+ query=None,
347
+ page=None,
348
+ result_per_page=None,
349
+ include_attributes=None,
350
+ include_attributes_deep=None,
351
+ include_type_attributes=None,
352
+ include_extended_info=None,
353
+ ):
354
+ """Retrieve objects through the legacy AQL collection endpoint."""
355
+ params = self._params(
356
+ qlQuery=query,
357
+ page=page,
358
+ resultPerPage=result_per_page,
359
+ includeAttributes=include_attributes,
360
+ includeAttributesDeep=include_attributes_deep,
361
+ includeTypeAttributes=include_type_attributes,
362
+ includeExtendedInfo=include_extended_info,
363
+ )
364
+ return self.get(self.url_joiner(self.api_root, "aql/objects"), params=params or None)
365
+
366
+ def get_iql_objects(
367
+ self,
368
+ query=None,
369
+ page=None,
370
+ result_per_page=None,
371
+ include_attributes=None,
372
+ include_attributes_deep=None,
373
+ include_type_attributes=None,
374
+ include_extended_info=None,
375
+ ):
376
+ """Retrieve objects through the IQL collection endpoint."""
377
+ params = self._params(
378
+ iql=query,
379
+ page=page,
380
+ resultPerPage=result_per_page,
381
+ includeAttributes=include_attributes,
382
+ includeAttributesDeep=include_attributes_deep,
383
+ includeTypeAttributes=include_type_attributes,
384
+ includeExtendedInfo=include_extended_info,
385
+ )
386
+ return self.get(self.url_joiner(self.api_root, "iql/objects"), params=params or None)
387
+
388
+ def iql(self, query, start=0, max_results=25, include_attributes=True):
389
+ """Find Assets objects using the IQL-compatible Cloud endpoint."""
390
+ params = self._params(startAt=start, maxResults=max_results, includeAttributes=include_attributes)
391
+ return self.post(self.url_joiner(self.api_root, "object/aql"), params=params, data={"qlQuery": query})
392
+
278
393
  # Navlist AQL
279
394
  # Retrieve a list of objects based on an AQL query
280
395
  # Server-only. Cloud use aql()
@@ -387,6 +502,44 @@ class AssetsCloud(AtlassianRestAPI):
387
502
  url = self.url_joiner(self.api_root, f"object/{object_id}/attributes")
388
503
  return self.get(url)
389
504
 
505
+ def get_object_attribute_value(self, object_id, attribute_id, default=None):
506
+ """Return the first value for an object type attribute.
507
+
508
+ Assets exposes object attributes as a collection rather than a
509
+ dedicated value endpoint. This helper fetches that collection and
510
+ selects the entry whose ``objectTypeAttributeId`` matches
511
+ ``attribute_id``. ``None`` (or ``default``) is returned when the
512
+ attribute is absent or has no values.
513
+
514
+ :param object_id: Assets object ID
515
+ :param attribute_id: object type attribute ID
516
+ :param default: value returned when no matching value exists
517
+ """
518
+ attributes = self.get_object_attributes(object_id)
519
+ if isinstance(attributes, dict):
520
+ attributes = attributes.get("objectAttributeBeans", attributes.get("values", []))
521
+ if not isinstance(attributes, list):
522
+ return default
523
+
524
+ for attribute in attributes:
525
+ if not isinstance(attribute, dict):
526
+ continue
527
+ object_type_attribute = attribute.get("objectTypeAttribute") or {}
528
+ current_id = attribute.get("objectTypeAttributeId", object_type_attribute.get("id"))
529
+ if str(current_id) != str(attribute_id):
530
+ continue
531
+
532
+ values = attribute.get("objectAttributeValues")
533
+ if values is None:
534
+ values = attribute.get("values")
535
+ if values:
536
+ value = values[0]
537
+ return value.get("value") if isinstance(value, dict) else value
538
+ if "value" in attribute:
539
+ return attribute["value"]
540
+ return default
541
+ return default
542
+
390
543
  def get_object_history(self, object_id, asc=False, abbreviate=True):
391
544
  """
392
545
  Retrieve the history entries for this object
@@ -410,6 +563,21 @@ class AssetsCloud(AtlassianRestAPI):
410
563
  url = self.url_joiner(self.api_root, f"object/{object_id}/referenceinfo")
411
564
  return self.get(url)
412
565
 
566
+ def search_objects_aql(self, query, start=0, max_results=25, include_attributes=True):
567
+ return self.aql(query, start=start, max_results=max_results, include_attributes=include_attributes)
568
+
569
+ def search_objects_iql(self, query, start=0, max_results=25, include_attributes=True):
570
+ return self.iql(query, start=start, max_results=max_results, include_attributes=include_attributes)
571
+
572
+ def search_objects_aql_navigation(self, data=None):
573
+ return self.post(self.url_joiner(self.api_root, "object/navlist/aql"), data=data)
574
+
575
+ def search_objects_iql_navigation(self, data=None):
576
+ return self.post(self.url_joiner(self.api_root, "object/navlist/iql"), data=data)
577
+
578
+ def get_object_aql_total_count(self, query):
579
+ return self.post(self.url_joiner(self.api_root, "object/aql/totalcount"), data={"qlQuery": query})
580
+
413
581
  def create_object(self, object_type_id, attributes, has_avatar=False, avatar_uuid=""):
414
582
  """
415
583
  Create a new object in Assets
@@ -467,7 +635,8 @@ class AssetsCloud(AtlassianRestAPI):
467
635
  return self.get(url)
468
636
 
469
637
  def create_object_schema(self, object_schema_key, description):
470
- raise NotImplementedError
638
+ data = {"objectSchemaKey": object_schema_key, "description": description}
639
+ return self.post(self.url_joiner(self.api_root, "objectschema/create"), data=data)
471
640
 
472
641
  def get_object_schema(self, schema_id):
473
642
  """
@@ -477,23 +646,26 @@ class AssetsCloud(AtlassianRestAPI):
477
646
  url = self.url_joiner(self.api_root, f"objectschema/{schema_id}")
478
647
  return self.get(url)
479
648
 
480
- def update_object_schema(self, schema_id):
649
+ def update_object_schema(self, schema_id, data=None):
481
650
  """
482
651
  Update an object schema
483
652
  """
484
- raise NotImplementedError
653
+ return self.put(self.url_joiner(self.api_root, f"objectschema/{schema_id}"), data=data)
485
654
 
486
655
  def delete_object_schema(self, schema_id):
487
656
  """
488
657
  Delete a schema
489
658
  """
490
- raise NotImplementedError
659
+ return self.delete(self.url_joiner(self.api_root, f"objectschema/{schema_id}"))
491
660
 
492
661
  def get_object_schema_attributes(self, schema_id):
493
662
  """
494
663
  Find all object type attributes for this object schema
495
664
  """
496
- raise NotImplementedError
665
+ return self.get(self.url_joiner(self.api_root, f"objectschema/{schema_id}/attributes"))
666
+
667
+ def get_object_schema_object_types(self, schema_id):
668
+ return self.get(self.url_joiner(self.api_root, f"objectschema/{schema_id}/objecttypes"))
497
669
 
498
670
  def get_object_schema_object_types_flat(self, schema_id, query=None, exclude=None, includeObjectCounts=None):
499
671
  """
@@ -596,6 +768,10 @@ class AssetsCloud(AtlassianRestAPI):
596
768
  url = self.url_joiner(self.api_root, f"progress/category/imports/{import_id}")
597
769
  return self.get(url)
598
770
 
771
+ def get_import_progress(self, import_id):
772
+ """Return progress for a Cloud import."""
773
+ return self.get(self.url_joiner(self.api_root, f"progress/category/imports/{import_id}"))
774
+
599
775
  # Assets Config API
600
776
  # TODO: Get config statustype:
601
777
  # https://developer.atlassian.com/cloud/assets/rest/api-group-config/#api-config-statustype-get
@@ -631,3 +807,85 @@ class AssetsCloud(AtlassianRestAPI):
631
807
  }
632
808
  data = {"fields": {field_id: [{"key": i} for i in assets_keys]}}
633
809
  return self.put(f"{base_url}/{key}", data=data)
810
+
811
+ # Object type and configuration resources
812
+ def get_object_type(self, object_type_id):
813
+ return self.get(self.url_joiner(self.api_root, f"objecttype/{object_type_id}"))
814
+
815
+ def update_object_type(self, object_type_id, data=None):
816
+ return self.put(self.url_joiner(self.api_root, f"objecttype/{object_type_id}"), data=data)
817
+
818
+ def delete_object_type(self, object_type_id):
819
+ return self.delete(self.url_joiner(self.api_root, f"objecttype/{object_type_id}"))
820
+
821
+ def create_object_type(self, data=None):
822
+ return self.post(self.url_joiner(self.api_root, "objecttype/create"), data=data)
823
+
824
+ def move_object_type(self, object_type_id, data=None):
825
+ return self.post(self.url_joiner(self.api_root, f"objecttype/{object_type_id}/position"), data=data)
826
+
827
+ def create_object_type_attribute(self, object_type_id, data=None):
828
+ return self.post(self.url_joiner(self.api_root, f"objecttypeattribute/{object_type_id}"), data=data)
829
+
830
+ def update_object_type_attribute(self, object_type_id, attribute_id, data=None):
831
+ url = self.url_joiner(self.api_root, f"objecttypeattribute/{object_type_id}/{attribute_id}")
832
+ return self.put(url, data=data)
833
+
834
+ def delete_object_type_attribute(self, attribute_id):
835
+ return self.delete(self.url_joiner(self.api_root, f"objecttypeattribute/{attribute_id}"))
836
+
837
+ def get_status_types(self):
838
+ return self.get(self.url_joiner(self.api_root, "config/statustype"))
839
+
840
+ def create_status_type(self, data=None):
841
+ return self.post(self.url_joiner(self.api_root, "config/statustype"), data=data)
842
+
843
+ def get_status_type(self, status_type_id):
844
+ return self.get(self.url_joiner(self.api_root, f"config/statustype/{status_type_id}"))
845
+
846
+ def update_status_type(self, status_type_id, data=None):
847
+ return self.put(self.url_joiner(self.api_root, f"config/statustype/{status_type_id}"), data=data)
848
+
849
+ def delete_status_type(self, status_type_id):
850
+ return self.delete(self.url_joiner(self.api_root, f"config/statustype/{status_type_id}"))
851
+
852
+ def get_reference_types(self):
853
+ return self.get(self.url_joiner(self.api_root, "config/referencetype"))
854
+
855
+ def create_reference_type(self, data=None):
856
+ return self.post(self.url_joiner(self.api_root, "config/referencetype"), data=data)
857
+
858
+ def set_object_schema_property(self, schema_id, data=None):
859
+ url = self.url_joiner(self.api_root, f"global/config/objectschema/{schema_id}/property")
860
+ return self.post(url, data=data)
861
+
862
+ def create_import_schedule(self, import_source_id, data=None):
863
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/importschedule")
864
+ return self.post(url, data=data)
865
+
866
+ def get_import_schedule_by_id(self, import_source_id, import_schedule_id):
867
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/importschedule/{import_schedule_id}")
868
+ return self.get(url)
869
+
870
+ def update_import_schedule(self, import_source_id, import_schedule_id, data=None):
871
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/importschedule/{import_schedule_id}")
872
+ return self.put(url, data=data)
873
+
874
+ def delete_import_schedule(self, import_source_id, import_schedule_id):
875
+ url = self.url_joiner(self.api_root, f"importsource/{import_source_id}/importschedule/{import_schedule_id}")
876
+ return self.delete(url)
877
+
878
+ def get_usage(self):
879
+ return self.get(self.url_joiner(self.api_root, "usage"))
880
+
881
+ def export_dataset(self, **filters):
882
+ """Export dataset information as CSV."""
883
+ allowed = {"testIssueId", "testIssueKey", "testVersion", "contextIssueId", "contextIssueKey", "resolved"}
884
+ params = self._params(**{key: value for key, value in filters.items() if key in allowed})
885
+ return self.get(self.url_joiner(self.api_root, "dataset/export"), params=params or None, not_json_response=True)
886
+
887
+ def import_dataset(self, files=None, **filters):
888
+ """Import a dataset CSV using optional entity context filters."""
889
+ allowed = {"testIssueId", "testIssueKey", "testVersion", "contextIssueId", "contextIssueKey"}
890
+ params = self._params(**{key: value for key, value in filters.items() if key in allowed})
891
+ return self.post(self.url_joiner(self.api_root, "dataset/import"), params=params or None, files=files)
@@ -0,0 +1,24 @@
1
+ """Jira Service Management Assets Server/Data Center client."""
2
+
3
+ from .assets_cloud import AssetsCloud
4
+
5
+
6
+ class AssetsServer(AssetsCloud):
7
+ """Assets REST client for Jira Server/Data Center installations.
8
+
9
+ Assets Data Center 10.x exposes the REST resources below
10
+ ``/rest/assets/1.0``. The implementation shares the resource methods
11
+ with :class:`~atlassian.assets.assets_cloud.AssetsCloud`; only workspace
12
+ discovery and the Cloud gateway are skipped.
13
+ """
14
+
15
+ def __init__(self, *args, **kwargs):
16
+ # Explicitly force the server path even if a caller reuses a config
17
+ # dictionary that contains ``cloud=True``.
18
+ kwargs["cloud"] = False
19
+ super().__init__(*args, **kwargs)
20
+
21
+
22
+ # Data Center is the current product name; retain this descriptive alias for
23
+ # callers that used the previous class name.
24
+ AssetsDataCenter = AssetsServer
@@ -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
@@ -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: Query string to narrow down the response.
24
- See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
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)