atlassian-python-api 5.0.1__py3-none-any.whl → 5.0.2__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 +13 -2
- atlassian/assets.py +10 -3
- atlassian/bamboo.py +178 -2
- atlassian/bitbucket/__init__.py +87 -1
- atlassian/bitbucket/base.py +9 -2
- atlassian/bitbucket/server/__init__.py +11 -0
- atlassian/cloud_admin.py +418 -0
- atlassian/confluence/__init__.py +9 -0
- atlassian/confluence/base.py +32 -10
- atlassian/confluence/cloud/__init__.py +19 -0
- atlassian/confluence/cloud/classification_levels.py +77 -0
- atlassian/confluence/cloud/cloud.py +43 -5
- atlassian/confluence/cloud/content_properties.py +71 -0
- atlassian/confluence/cloud/graphql.py +99 -0
- atlassian/confluence/server/__init__.py +274 -74
- atlassian/crowd.py +78 -0
- atlassian/jira/__init__.py +21 -0
- atlassian/jira/core_methods.py +11698 -0
- atlassian/jira/jira_cloud.py +160 -0
- atlassian/{jira.py → jira/jira_server.py} +333 -6
- atlassian/jira/service_management_methods.py +1381 -0
- atlassian/jira/software_methods.py +2114 -0
- atlassian/rest_client.py +26 -1
- atlassian/service_desk.py +10 -3
- atlassian/yogi/__init__.py +17 -0
- atlassian/yogi/base.py +11 -0
- atlassian/yogi/cloud.py +2367 -0
- atlassian/yogi/yogi_confluence_cloud.py +10 -0
- atlassian/yogi/yogi_confluence_dc.py +94 -0
- atlassian/yogi/yogi_jira_cloud.py +10 -0
- atlassian/yogi/yogi_jira_dc.py +64 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/METADATA +80 -10
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/RECORD +37 -22
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/WHEEL +0 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/licenses/LICENSE +0 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/top_level.txt +0 -0
atlassian/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.0.
|
|
1
|
+
5.0.2
|
atlassian/__init__.py
CHANGED
|
@@ -5,20 +5,21 @@ Atlassian Python API
|
|
|
5
5
|
from .bamboo import Bamboo
|
|
6
6
|
from .bitbucket import Bitbucket
|
|
7
7
|
from .bitbucket import Bitbucket as Stash
|
|
8
|
-
from .cloud_admin import CloudAdminOrgs, CloudAdminUsers
|
|
8
|
+
from .cloud_admin import CloudAdmin, CloudAdminOrgs, CloudAdminUsers
|
|
9
9
|
from .confluence import Confluence, ConfluenceBase, ConfluenceCloud, ConfluenceServer
|
|
10
10
|
from .confluence.cloud.cloud import ConfluenceCloud as ConfluenceV2
|
|
11
11
|
from .crowd import Crowd
|
|
12
12
|
from .insight import Insight
|
|
13
13
|
from .insight import Insight as Assets # used for Insight on-premise
|
|
14
14
|
from .assets import AssetsCloud # used for Insight Cloud
|
|
15
|
-
from .jira import Jira
|
|
15
|
+
from .jira import Jira, JiraCloud, JiraServer, JiraServiceManagement, JiraSoftware, create_jira_cloud
|
|
16
16
|
from .marketplace import MarketPlace
|
|
17
17
|
from .portfolio import Portfolio
|
|
18
18
|
from .service_desk import ServiceDesk
|
|
19
19
|
from .service_desk import ServiceDesk as ServiceManagement
|
|
20
20
|
from .tempo import TempoCloud, TempoServer
|
|
21
21
|
from .xray import Xray
|
|
22
|
+
from .yogi import YogiConfluenceCloud, YogiConfluenceDC, YogiJiraCloud, YogiJiraDC
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
# Confluence REST API v2 client. The existing ``Confluence`` class remains
|
|
@@ -36,9 +37,15 @@ __all__ = [
|
|
|
36
37
|
"ConfluenceV2",
|
|
37
38
|
"create_confluence",
|
|
38
39
|
"Jira",
|
|
40
|
+
"JiraServer",
|
|
41
|
+
"JiraCloud",
|
|
42
|
+
"JiraSoftware",
|
|
43
|
+
"JiraServiceManagement",
|
|
44
|
+
"create_jira_cloud",
|
|
39
45
|
"Bitbucket",
|
|
40
46
|
"CloudAdminOrgs",
|
|
41
47
|
"CloudAdminUsers",
|
|
48
|
+
"CloudAdmin",
|
|
42
49
|
"Portfolio",
|
|
43
50
|
"Bamboo",
|
|
44
51
|
"Stash",
|
|
@@ -52,4 +59,8 @@ __all__ = [
|
|
|
52
59
|
"AssetsCloud",
|
|
53
60
|
"TempoCloud",
|
|
54
61
|
"TempoServer",
|
|
62
|
+
"YogiJiraCloud",
|
|
63
|
+
"YogiJiraDC",
|
|
64
|
+
"YogiConfluenceCloud",
|
|
65
|
+
"YogiConfluenceDC",
|
|
55
66
|
]
|
atlassian/assets.py
CHANGED
|
@@ -538,9 +538,16 @@ class AssetsCloud(AtlassianRestAPI):
|
|
|
538
538
|
order_by_required (bool, optional): Order by required fields, defaults to None (Use API default)
|
|
539
539
|
"""
|
|
540
540
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
541
|
+
params = {
|
|
542
|
+
"onlyValueEditable": only_value_editable,
|
|
543
|
+
"orderByName": order_by_name,
|
|
544
|
+
"query": query,
|
|
545
|
+
"includeValuesExist": include_values_exist,
|
|
546
|
+
"excludeParentAttributes": exclude_parent_attributes,
|
|
547
|
+
"includeChildren": include_children,
|
|
548
|
+
"orderByRequired": order_by_required,
|
|
549
|
+
}
|
|
550
|
+
params = {k: v for k, v in params.items() if v is not None}
|
|
544
551
|
|
|
545
552
|
return self.get(
|
|
546
553
|
f"{self.api_root}/objecttype/{type_id}/attributes",
|
atlassian/bamboo.py
CHANGED
|
@@ -82,7 +82,10 @@ class Bamboo(AtlassianRestAPI):
|
|
|
82
82
|
if clover_enabled:
|
|
83
83
|
flags.append("cloverEnabled")
|
|
84
84
|
if label:
|
|
85
|
-
|
|
85
|
+
# Requests serializes a sequence value as repeated query
|
|
86
|
+
# parameters (``label=one&label=two``), which is the Bamboo REST
|
|
87
|
+
# API representation for filtering by multiple labels.
|
|
88
|
+
params["label"] = label if isinstance(label, str) else list(label)
|
|
86
89
|
params.update(kwargs)
|
|
87
90
|
if "elements_key" in kwargs and "element_key" in kwargs:
|
|
88
91
|
return self._get_generator(
|
|
@@ -227,6 +230,59 @@ class Bamboo(AtlassianRestAPI):
|
|
|
227
230
|
resource = f"rest/api/latest/plan/{plan_key}"
|
|
228
231
|
return self.get(resource, params=params)
|
|
229
232
|
|
|
233
|
+
def get_plan_specs(self, plan_key, package=None, format="YAML"):
|
|
234
|
+
"""Export a plan as Bamboo Specs source code.
|
|
235
|
+
|
|
236
|
+
Bamboo does not provide a repositories-only REST endpoint. The
|
|
237
|
+
response's ``spec.code`` field contains the plan definition, including
|
|
238
|
+
its ``repositories`` section. ``YAML`` is the most convenient format
|
|
239
|
+
for repository audits; Bamboo also supports ``JAVA`` on compatible
|
|
240
|
+
releases.
|
|
241
|
+
|
|
242
|
+
:param plan_key: Full plan key, for example ``PROJECT-PLAN``.
|
|
243
|
+
:param package: Optional Java package name when exporting Java Specs.
|
|
244
|
+
:param format: Export format, normally ``YAML`` or ``JAVA``.
|
|
245
|
+
:return: The ``RestPlanSpec`` response containing ``spec.code``.
|
|
246
|
+
"""
|
|
247
|
+
params = {"format": format}
|
|
248
|
+
if package is not None:
|
|
249
|
+
params["package"] = package
|
|
250
|
+
return self.get(self.resource_url(f"plan/{plan_key}/specs"), params=params)
|
|
251
|
+
|
|
252
|
+
def search_linked_repositories(self, search_term=None):
|
|
253
|
+
"""Search globally configured Bamboo linked repositories.
|
|
254
|
+
|
|
255
|
+
The public Bamboo REST API can search existing linked repositories but
|
|
256
|
+
does not create or update their connection configuration. Create those
|
|
257
|
+
connections in Bamboo administration, then use the returned repository
|
|
258
|
+
ID with :meth:`link_repository_to_project`.
|
|
259
|
+
|
|
260
|
+
:param search_term: Optional repository-name fragment.
|
|
261
|
+
:return: Bamboo's paged linked-repository response.
|
|
262
|
+
"""
|
|
263
|
+
params = {}
|
|
264
|
+
if search_term is not None:
|
|
265
|
+
params["searchTerm"] = search_term
|
|
266
|
+
return self.get(self.resource_url("repository"), params=params)
|
|
267
|
+
|
|
268
|
+
def get_project_linked_repositories(self, project_key):
|
|
269
|
+
"""Return linked repositories authorized for Bamboo Specs in a project."""
|
|
270
|
+
return self.get(self.resource_url(f"project/{project_key}/repository"))
|
|
271
|
+
|
|
272
|
+
def link_repository_to_project(self, project_key, repository_id):
|
|
273
|
+
"""Authorize an existing linked repository for Bamboo Specs in a project.
|
|
274
|
+
|
|
275
|
+
This grants a repository-stored Bamboo Specs repository permission to
|
|
276
|
+
create or edit plans in ``project_key``. It does not change the
|
|
277
|
+
repositories checked out by an existing plan; update and apply that
|
|
278
|
+
plan's Bamboo Specs for plan-level repository changes.
|
|
279
|
+
"""
|
|
280
|
+
return self.post(self.resource_url(f"project/{project_key}/repository"), data={"id": repository_id})
|
|
281
|
+
|
|
282
|
+
def unlink_repository_from_project(self, project_key, repository_id):
|
|
283
|
+
"""Remove a project-level Bamboo Specs repository authorization."""
|
|
284
|
+
return self.delete(self.resource_url(f"project/{project_key}/repository/{repository_id}"))
|
|
285
|
+
|
|
230
286
|
def search_plans(self, search_term, fuzzy=True, start_index=0, max_results=25):
|
|
231
287
|
"""
|
|
232
288
|
Search plans by name
|
|
@@ -397,6 +453,7 @@ class Bamboo(AtlassianRestAPI):
|
|
|
397
453
|
start_index=0,
|
|
398
454
|
max_results=25,
|
|
399
455
|
include_all_states=False,
|
|
456
|
+
build_state=None,
|
|
400
457
|
):
|
|
401
458
|
"""
|
|
402
459
|
Get results as generic method
|
|
@@ -408,10 +465,12 @@ class Bamboo(AtlassianRestAPI):
|
|
|
408
465
|
:param favourite:
|
|
409
466
|
:param clover_enabled:
|
|
410
467
|
:param issue_key:
|
|
411
|
-
:param label:
|
|
468
|
+
:param label: A label string or an iterable of labels.
|
|
412
469
|
:param start_index:
|
|
413
470
|
:param max_results:
|
|
414
471
|
:param include_all_states:
|
|
472
|
+
:param build_state: Optional Bamboo result state, such as
|
|
473
|
+
``Successful`` or ``Failed``.
|
|
415
474
|
:return:
|
|
416
475
|
"""
|
|
417
476
|
resource = "result"
|
|
@@ -429,6 +488,8 @@ class Bamboo(AtlassianRestAPI):
|
|
|
429
488
|
params["issueKey"] = issue_key
|
|
430
489
|
if include_all_states:
|
|
431
490
|
params["includeAllStates"] = include_all_states
|
|
491
|
+
if build_state is not None:
|
|
492
|
+
params["buildstate"] = build_state
|
|
432
493
|
return self.base_list_call(
|
|
433
494
|
resource,
|
|
434
495
|
expand=expand,
|
|
@@ -525,6 +586,7 @@ class Bamboo(AtlassianRestAPI):
|
|
|
525
586
|
start_index=0,
|
|
526
587
|
max_results=25,
|
|
527
588
|
include_all_states=False,
|
|
589
|
+
build_state=None,
|
|
528
590
|
):
|
|
529
591
|
"""
|
|
530
592
|
Get Plan results
|
|
@@ -538,6 +600,8 @@ class Bamboo(AtlassianRestAPI):
|
|
|
538
600
|
:param start_index:
|
|
539
601
|
:param max_results:
|
|
540
602
|
:param include_all_states:
|
|
603
|
+
:param build_state: Optional Bamboo result state, such as
|
|
604
|
+
``Successful`` or ``Failed``.
|
|
541
605
|
:return:
|
|
542
606
|
"""
|
|
543
607
|
return self.results(
|
|
@@ -551,8 +615,71 @@ class Bamboo(AtlassianRestAPI):
|
|
|
551
615
|
start_index=start_index,
|
|
552
616
|
max_results=max_results,
|
|
553
617
|
include_all_states=include_all_states,
|
|
618
|
+
build_state=build_state,
|
|
554
619
|
)
|
|
555
620
|
|
|
621
|
+
def ordered_plan_results(
|
|
622
|
+
self,
|
|
623
|
+
project_key,
|
|
624
|
+
plan_key,
|
|
625
|
+
order="descending",
|
|
626
|
+
build_state=None,
|
|
627
|
+
max_results=25,
|
|
628
|
+
**kwargs,
|
|
629
|
+
):
|
|
630
|
+
"""Return retrieved plan results ordered by completion time.
|
|
631
|
+
|
|
632
|
+
Bamboo's result API does not expose a server-side sort parameter. This
|
|
633
|
+
helper orders the result page client-side by ``buildCompletedTime``.
|
|
634
|
+
Set ``max_results`` high enough to include the history being compared;
|
|
635
|
+
this method returns a list rather than the lazy generator returned by
|
|
636
|
+
:meth:`plan_results`.
|
|
637
|
+
|
|
638
|
+
:param order: ``"ascending"`` for oldest first or ``"descending"``
|
|
639
|
+
for newest first.
|
|
640
|
+
:param build_state: Optional ``Successful`` or ``Failed`` filter.
|
|
641
|
+
:param max_results: Number of results Bamboo should return to sort.
|
|
642
|
+
:return: A list of build results ordered by completion time.
|
|
643
|
+
"""
|
|
644
|
+
if order not in {"ascending", "descending"}:
|
|
645
|
+
raise ValueError("order must be 'ascending' or 'descending'")
|
|
646
|
+
|
|
647
|
+
results = self.plan_results(
|
|
648
|
+
project_key,
|
|
649
|
+
plan_key,
|
|
650
|
+
build_state=build_state,
|
|
651
|
+
max_results=max_results,
|
|
652
|
+
**kwargs,
|
|
653
|
+
)
|
|
654
|
+
return sorted(
|
|
655
|
+
results,
|
|
656
|
+
key=lambda result: result.get("buildCompletedTime") or "",
|
|
657
|
+
reverse=order == "descending",
|
|
658
|
+
)
|
|
659
|
+
|
|
660
|
+
def latest_successful_plan_result(self, project_key, plan_key, max_results=25, **kwargs):
|
|
661
|
+
"""Return the newest successful plan result, or ``None`` when absent."""
|
|
662
|
+
results = self.ordered_plan_results(
|
|
663
|
+
project_key,
|
|
664
|
+
plan_key,
|
|
665
|
+
build_state="Successful",
|
|
666
|
+
max_results=max_results,
|
|
667
|
+
**kwargs,
|
|
668
|
+
)
|
|
669
|
+
return results[0] if results else None
|
|
670
|
+
|
|
671
|
+
def oldest_failed_plan_result(self, project_key, plan_key, max_results=25, **kwargs):
|
|
672
|
+
"""Return the oldest failed plan result, or ``None`` when absent."""
|
|
673
|
+
results = self.ordered_plan_results(
|
|
674
|
+
project_key,
|
|
675
|
+
plan_key,
|
|
676
|
+
order="ascending",
|
|
677
|
+
build_state="Failed",
|
|
678
|
+
max_results=max_results,
|
|
679
|
+
**kwargs,
|
|
680
|
+
)
|
|
681
|
+
return results[0] if results else None
|
|
682
|
+
|
|
556
683
|
def build_result(
|
|
557
684
|
self,
|
|
558
685
|
build_key,
|
|
@@ -654,6 +781,23 @@ class Bamboo(AtlassianRestAPI):
|
|
|
654
781
|
|
|
655
782
|
return self.post(self.resource_url(resource), params=params)
|
|
656
783
|
|
|
784
|
+
def queue_build(self, plan_key, params=None):
|
|
785
|
+
"""Add a plan to the Bamboo build queue.
|
|
786
|
+
|
|
787
|
+
``params`` maps directly to Bamboo's queue request parameters. For
|
|
788
|
+
example, pass ``{"bamboo.variable.release": "1.2.3"}`` to set a
|
|
789
|
+
custom plan variable. Builds execute all stages by default; provide an
|
|
790
|
+
explicit ``executeAllStages`` or ``stage`` value to override that
|
|
791
|
+
behavior. The supplied mapping is never modified.
|
|
792
|
+
|
|
793
|
+
:param plan_key: Full plan key, for example ``PROJECT-PLAN``.
|
|
794
|
+
:param params: Optional queue parameters and custom variables.
|
|
795
|
+
:return: The queued build response.
|
|
796
|
+
"""
|
|
797
|
+
queue_params = dict(params or {})
|
|
798
|
+
queue_params.setdefault("executeAllStages", "true")
|
|
799
|
+
return self.post(self.resource_url(f"queue/{plan_key}"), params=queue_params)
|
|
800
|
+
|
|
657
801
|
def stop_build(self, plan_key):
|
|
658
802
|
"""
|
|
659
803
|
Stop the build which is in progress at the moment.
|
|
@@ -1203,6 +1347,38 @@ class Bamboo(AtlassianRestAPI):
|
|
|
1203
1347
|
params={"includeShared": include_shared},
|
|
1204
1348
|
)
|
|
1205
1349
|
|
|
1350
|
+
def add_agent_capability(self, agent_id, data):
|
|
1351
|
+
"""Add a capability to an agent using Bamboo's capability payload."""
|
|
1352
|
+
return self.post(self.resource_url(f"agent/{agent_id}/capability"), data=data)
|
|
1353
|
+
|
|
1354
|
+
def delete_agent_capability(self, agent_id, capability_key):
|
|
1355
|
+
"""Delete one agent capability by its Bamboo capability key."""
|
|
1356
|
+
return self.delete(self.resource_url(f"agent/{agent_id}/capability/{capability_key}"))
|
|
1357
|
+
|
|
1358
|
+
def delete_all_agent_capabilities(self, agent_id):
|
|
1359
|
+
"""Delete every capability assigned directly to an agent."""
|
|
1360
|
+
return self.delete(self.resource_url(f"agent/{agent_id}/capability"))
|
|
1361
|
+
|
|
1362
|
+
def get_plan_variables(self, plan_key):
|
|
1363
|
+
"""Return variables configured for a plan."""
|
|
1364
|
+
return self.get(self.resource_url(f"plan/{plan_key}/variable"))
|
|
1365
|
+
|
|
1366
|
+
def get_plan_variable(self, plan_key, variable_name):
|
|
1367
|
+
"""Return one plan variable by name."""
|
|
1368
|
+
return self.get(self.resource_url(f"plan/{plan_key}/variable/{variable_name}"))
|
|
1369
|
+
|
|
1370
|
+
def create_plan_variable(self, plan_key, data):
|
|
1371
|
+
"""Create a plan variable from Bamboo's variable request body."""
|
|
1372
|
+
return self.post(self.resource_url(f"plan/{plan_key}/variable"), data=data)
|
|
1373
|
+
|
|
1374
|
+
def update_plan_variable(self, plan_key, variable_name, data):
|
|
1375
|
+
"""Update a plan variable."""
|
|
1376
|
+
return self.put(self.resource_url(f"plan/{plan_key}/variable/{variable_name}"), data=data)
|
|
1377
|
+
|
|
1378
|
+
def delete_plan_variable(self, plan_key, variable_name):
|
|
1379
|
+
"""Delete a plan variable."""
|
|
1380
|
+
return self.delete(self.resource_url(f"plan/{plan_key}/variable/{variable_name}"))
|
|
1381
|
+
|
|
1206
1382
|
def activity(self, busy=None):
|
|
1207
1383
|
"""Return active online agents and their current build activity.
|
|
1208
1384
|
|
atlassian/bitbucket/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
import logging
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import Optional
|
|
4
|
+
from typing import Any, Dict, List, Optional
|
|
5
5
|
|
|
6
6
|
from deprecated import deprecated
|
|
7
7
|
from requests import HTTPError
|
|
@@ -290,6 +290,82 @@ class Bitbucket(BitbucketBase):
|
|
|
290
290
|
files = {"plugin": open(plugin_path, "rb")}
|
|
291
291
|
return self.post(url, files=files, headers=self.no_check_headers)
|
|
292
292
|
|
|
293
|
+
################################################################################################
|
|
294
|
+
# Hook scripts (Bitbucket Data Center 8+)
|
|
295
|
+
################################################################################################
|
|
296
|
+
def _url_hook_scripts(self):
|
|
297
|
+
return self.resource_url("hook-scripts", api_version="latest")
|
|
298
|
+
|
|
299
|
+
def create_hook_script(self, content: bytes, name: str, hook_type: str, description: Optional[str] = None):
|
|
300
|
+
"""Register a global hook script on Bitbucket Data Center.
|
|
301
|
+
|
|
302
|
+
``hook_type`` must be ``PRE`` or ``POST``. The caller must be a system
|
|
303
|
+
administrator, and Bitbucket Data Center 8.18+ requires hook scripts to
|
|
304
|
+
be explicitly enabled with ``feature.hook.scripts=true``.
|
|
305
|
+
|
|
306
|
+
The API expects a multipart form. ``content`` is the executable script
|
|
307
|
+
bytes; no temporary file is created by the client.
|
|
308
|
+
"""
|
|
309
|
+
if hook_type not in ("PRE", "POST"):
|
|
310
|
+
raise ValueError("hook_type must be 'PRE' or 'POST'")
|
|
311
|
+
|
|
312
|
+
files: Dict[str, Any] = {
|
|
313
|
+
"content": ("hook-script", content, "application/octet-stream"),
|
|
314
|
+
"name": (None, name),
|
|
315
|
+
"type": (None, hook_type),
|
|
316
|
+
}
|
|
317
|
+
if description is not None:
|
|
318
|
+
files["description"] = (None, description)
|
|
319
|
+
return self.post(self._url_hook_scripts(), files=files, headers=self.no_check_headers)
|
|
320
|
+
|
|
321
|
+
def configure_project_hook_script(self, project_key: str, script_id: int, trigger_ids: Optional[List[str]] = None):
|
|
322
|
+
"""Configure a registered hook script for every repository in a project.
|
|
323
|
+
|
|
324
|
+
Requires project administrator permission. ``trigger_ids`` controls the
|
|
325
|
+
hook triggers to which the script is bound.
|
|
326
|
+
"""
|
|
327
|
+
url = f"{self._url_project(project_key, api_version='latest')}/hook-scripts/{script_id}"
|
|
328
|
+
return self.put(url, data={"triggerIds": trigger_ids or []})
|
|
329
|
+
|
|
330
|
+
def configure_repo_hook_script(
|
|
331
|
+
self, project_key: str, repository_slug: str, script_id: int, trigger_ids: Optional[List[str]] = None
|
|
332
|
+
):
|
|
333
|
+
"""Configure a registered hook script for a repository.
|
|
334
|
+
|
|
335
|
+
Requires repository administrator permission. ``trigger_ids`` controls
|
|
336
|
+
the hook triggers to which the script is bound.
|
|
337
|
+
"""
|
|
338
|
+
url = f"{self._url_repo(project_key, repository_slug, api_version='latest')}/hook-scripts/{script_id}"
|
|
339
|
+
return self.put(url, data={"triggerIds": trigger_ids or []})
|
|
340
|
+
|
|
341
|
+
def get_project_hook_scripts(self, project_key: str, start: int = 0, limit: Optional[int] = None):
|
|
342
|
+
"""Yield hook-script configurations for a project."""
|
|
343
|
+
params: Dict[str, int] = {"start": start}
|
|
344
|
+
if limit is not None:
|
|
345
|
+
params["limit"] = limit
|
|
346
|
+
url = f"{self._url_project(project_key, api_version='latest')}/hook-scripts"
|
|
347
|
+
return self._get_paged(url, params=params)
|
|
348
|
+
|
|
349
|
+
def get_repo_hook_scripts(
|
|
350
|
+
self, project_key: str, repository_slug: str, start: int = 0, limit: Optional[int] = None
|
|
351
|
+
):
|
|
352
|
+
"""Yield hook-script configurations for a repository."""
|
|
353
|
+
params: Dict[str, int] = {"start": start}
|
|
354
|
+
if limit is not None:
|
|
355
|
+
params["limit"] = limit
|
|
356
|
+
url = f"{self._url_repo(project_key, repository_slug, api_version='latest')}/hook-scripts"
|
|
357
|
+
return self._get_paged(url, params=params)
|
|
358
|
+
|
|
359
|
+
def delete_project_hook_script(self, project_key: str, script_id: int):
|
|
360
|
+
"""Remove a hook-script configuration from a project."""
|
|
361
|
+
url = f"{self._url_project(project_key, api_version='latest')}/hook-scripts/{script_id}"
|
|
362
|
+
return self.delete(url)
|
|
363
|
+
|
|
364
|
+
def delete_repo_hook_script(self, project_key: str, repository_slug: str, script_id: int):
|
|
365
|
+
"""Remove a hook-script configuration from a repository."""
|
|
366
|
+
url = f"{self._url_repo(project_key, repository_slug, api_version='latest')}/hook-scripts/{script_id}"
|
|
367
|
+
return self.delete(url)
|
|
368
|
+
|
|
293
369
|
def get_categories(self, project_key, repository_slug=None):
|
|
294
370
|
"""
|
|
295
371
|
Get a list of categories assigned to a project or repository.
|
|
@@ -762,6 +838,16 @@ class Bitbucket(BitbucketBase):
|
|
|
762
838
|
return self._get_paged(url, params=params)
|
|
763
839
|
|
|
764
840
|
def _url_repos(self, project_key, api_root=None, api_version=None):
|
|
841
|
+
"""Return the repository collection URL for a project or personal owner.
|
|
842
|
+
|
|
843
|
+
Bitbucket Server/Data Center addresses personal repositories through a
|
|
844
|
+
user-centric route. Pass the owner's user slug with a leading ``~``
|
|
845
|
+
(for example, ``~alice``) wherever a ``project_key`` is accepted by a
|
|
846
|
+
repository method. Project repositories continue to use the existing
|
|
847
|
+
``projects/{projectKey}/repos`` route.
|
|
848
|
+
"""
|
|
849
|
+
if not self.cloud and str(project_key).startswith("~"):
|
|
850
|
+
return self.resource_url(f"users/{project_key}/repos", api_root, api_version)
|
|
765
851
|
return f"{self._url_project(project_key, api_root, api_version)}/repos"
|
|
766
852
|
|
|
767
853
|
def repo_list(self, project_key, start=0, limit=25):
|
atlassian/bitbucket/base.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
|
+
import re
|
|
4
5
|
from datetime import datetime
|
|
5
6
|
from pprint import PrettyPrinter
|
|
6
7
|
|
|
@@ -158,8 +159,14 @@ class BitbucketBase(AtlassianRestAPI):
|
|
|
158
159
|
if isinstance(value_str, str):
|
|
159
160
|
# Bitbucket Cloud returns ISO 8601 timestamps with optional
|
|
160
161
|
# fractional seconds and either an offset or a trailing ``Z``.
|
|
161
|
-
#
|
|
162
|
-
#
|
|
162
|
+
# Python 3.10 and older only accept 0, 3, or 6 fractional digits,
|
|
163
|
+
# while Bitbucket may return another precision. Clamp the fraction
|
|
164
|
+
# to microsecond precision without touching the UTC offset.
|
|
165
|
+
value_str = re.sub(
|
|
166
|
+
r"\.(\d+)(?=(?:Z|[+-]\d{2}:?\d{2})?$)",
|
|
167
|
+
lambda match: "." + match.group(1)[:6].ljust(6, "0"),
|
|
168
|
+
value_str,
|
|
169
|
+
)
|
|
163
170
|
value = datetime.fromisoformat(value_str.replace("Z", "+00:00"))
|
|
164
171
|
else:
|
|
165
172
|
value = value_str
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from .base import BitbucketServerBase
|
|
4
4
|
from .globalPermissions import Groups, Users
|
|
5
5
|
from .projects import Projects
|
|
6
|
+
from .projects.repos import Repositories
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class Server(BitbucketServerBase):
|
|
@@ -44,3 +45,13 @@ class Server(BitbucketServerBase):
|
|
|
44
45
|
Reference: https://docs.atlassian.com/bitbucket-server/rest/7.8.0/bitbucket-rest.html#idp147
|
|
45
46
|
"""
|
|
46
47
|
return self.__projects
|
|
48
|
+
|
|
49
|
+
def personal_repositories(self, username):
|
|
50
|
+
"""Return repositories owned by a Bitbucket Server/Data Center user.
|
|
51
|
+
|
|
52
|
+
``username`` may be supplied with or without the leading ``~``. The
|
|
53
|
+
returned collection has the same API as ``project.repos`` and uses
|
|
54
|
+
Bitbucket's user-centric ``/users/{userSlug}/repos`` endpoint.
|
|
55
|
+
"""
|
|
56
|
+
user_slug = username if username.startswith("~") else f"~{username}"
|
|
57
|
+
return Repositories(self._sub_url(f"users/{user_slug}/repos"), **self._new_session_args)
|