atlassian-python-api 3.41.13__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 -0
- atlassian/__init__.py +32 -0
- atlassian/bamboo.py +1343 -0
- atlassian/bitbucket/__init__.py +3572 -0
- atlassian/bitbucket/base.py +198 -0
- atlassian/bitbucket/cloud/__init__.py +24 -0
- atlassian/bitbucket/cloud/base.py +123 -0
- atlassian/bitbucket/cloud/common/__init__.py +1 -0
- atlassian/bitbucket/cloud/common/builds.py +85 -0
- atlassian/bitbucket/cloud/common/comments.py +50 -0
- atlassian/bitbucket/cloud/common/users.py +79 -0
- atlassian/bitbucket/cloud/repositories/__init__.py +437 -0
- atlassian/bitbucket/cloud/repositories/branchRestrictions.py +175 -0
- atlassian/bitbucket/cloud/repositories/commits.py +188 -0
- atlassian/bitbucket/cloud/repositories/defaultReviewers.py +94 -0
- atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py +264 -0
- atlassian/bitbucket/cloud/repositories/diffstat.py +92 -0
- atlassian/bitbucket/cloud/repositories/groupPermissions.py +81 -0
- atlassian/bitbucket/cloud/repositories/hooks.py +117 -0
- atlassian/bitbucket/cloud/repositories/issues.py +164 -0
- atlassian/bitbucket/cloud/repositories/pipelines.py +274 -0
- atlassian/bitbucket/cloud/repositories/pullRequests.py +483 -0
- atlassian/bitbucket/cloud/repositories/refs.py +136 -0
- atlassian/bitbucket/cloud/repositories/repositoryVariables.py +146 -0
- atlassian/bitbucket/cloud/workspaces/__init__.py +146 -0
- atlassian/bitbucket/cloud/workspaces/members.py +62 -0
- atlassian/bitbucket/cloud/workspaces/permissions.py +125 -0
- atlassian/bitbucket/cloud/workspaces/projects.py +215 -0
- atlassian/bitbucket/server/__init__.py +46 -0
- atlassian/bitbucket/server/base.py +63 -0
- atlassian/bitbucket/server/common/__init__.py +1 -0
- atlassian/bitbucket/server/common/permissions.py +220 -0
- atlassian/bitbucket/server/globalPermissions.py +198 -0
- atlassian/bitbucket/server/projects/__init__.py +244 -0
- atlassian/bitbucket/server/projects/repos/__init__.py +327 -0
- atlassian/cloud_admin.py +32 -0
- atlassian/confluence.py +3336 -0
- atlassian/crowd.py +266 -0
- atlassian/errors.py +27 -0
- atlassian/insight.py +678 -0
- atlassian/jira.py +5324 -0
- atlassian/marketplace.py +84 -0
- atlassian/portfolio.py +108 -0
- atlassian/request_utils.py +39 -0
- atlassian/rest_client.py +558 -0
- atlassian/service_desk.py +911 -0
- atlassian/statuspage.py +3133 -0
- atlassian/utils.py +327 -0
- atlassian/xray.py +632 -0
- atlassian_python_api-3.41.13.dist-info/LICENSE +201 -0
- atlassian_python_api-3.41.13.dist-info/METADATA +261 -0
- atlassian_python_api-3.41.13.dist-info/RECORD +54 -0
- atlassian_python_api-3.41.13.dist-info/WHEEL +5 -0
- atlassian_python_api-3.41.13.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from ..base import BitbucketCloudBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RepositoryVariables(BitbucketCloudBase):
|
|
7
|
+
def __init__(self, url, *args, **kwargs):
|
|
8
|
+
super(RepositoryVariables, self).__init__(url, *args, **kwargs)
|
|
9
|
+
|
|
10
|
+
def __get_object(self, data):
|
|
11
|
+
return RepositoryVariable(
|
|
12
|
+
self.url_joiner(self.url, data["uuid"]),
|
|
13
|
+
data,
|
|
14
|
+
**self._new_session_args
|
|
15
|
+
) # fmt: skip
|
|
16
|
+
|
|
17
|
+
def create(self, key, value, secured):
|
|
18
|
+
"""
|
|
19
|
+
Create a new repository variable for the given repository.
|
|
20
|
+
|
|
21
|
+
:param key: string: The unique name of the variable.
|
|
22
|
+
:param value: string: The value of the variable. If the variable is secured, this will be empty.
|
|
23
|
+
:param secured: boolean: If true, this variable will be treated as secured. The value will never be exposed in the logs or the REST API.
|
|
24
|
+
|
|
25
|
+
:return: The created RepositoryVariable object
|
|
26
|
+
|
|
27
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-post
|
|
28
|
+
"""
|
|
29
|
+
data = {
|
|
30
|
+
"key": key,
|
|
31
|
+
"value": value,
|
|
32
|
+
"secured": secured,
|
|
33
|
+
}
|
|
34
|
+
return self.__get_object(self.post(None, data=data))
|
|
35
|
+
|
|
36
|
+
def each(self, q=None, sort=None):
|
|
37
|
+
"""
|
|
38
|
+
Returns the list of repository variables in this repository.
|
|
39
|
+
|
|
40
|
+
:param q: string: Query string to narrow down the response.
|
|
41
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
42
|
+
:param sort: string: Name of a response property to sort results.
|
|
43
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
44
|
+
|
|
45
|
+
:return: A generator for the RepositoryVariable objects
|
|
46
|
+
|
|
47
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-get
|
|
48
|
+
"""
|
|
49
|
+
params = {}
|
|
50
|
+
if sort is not None:
|
|
51
|
+
params["sort"] = sort
|
|
52
|
+
if q is not None:
|
|
53
|
+
params["q"] = q
|
|
54
|
+
for pipeline_variable in self._get_paged(
|
|
55
|
+
None,
|
|
56
|
+
trailing=True,
|
|
57
|
+
paging_workaround=True,
|
|
58
|
+
params=params,
|
|
59
|
+
):
|
|
60
|
+
yield self.__get_object(pipeline_variable)
|
|
61
|
+
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
def get(self, uuid):
|
|
65
|
+
"""
|
|
66
|
+
Returns the pipeline with the uuid in this repository.
|
|
67
|
+
|
|
68
|
+
:param uuid: string: The requested pipeline uuid
|
|
69
|
+
|
|
70
|
+
:return: The requested RepositoryVariable objects
|
|
71
|
+
|
|
72
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-variable-uuid-get
|
|
73
|
+
"""
|
|
74
|
+
return self.__get_object(super(RepositoryVariables, self).get(uuid))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class RepositoryVariable(BitbucketCloudBase):
|
|
78
|
+
def __init__(self, url, data, *args, **kwargs):
|
|
79
|
+
super(RepositoryVariable, self).__init__(url, *args, data=data, expected_type="pipeline_variable", **kwargs)
|
|
80
|
+
|
|
81
|
+
def update(self, **kwargs):
|
|
82
|
+
"""
|
|
83
|
+
Update the repository variable properties. Fields not present in the request body are ignored.
|
|
84
|
+
|
|
85
|
+
:param kwargs: dict: The data to update.
|
|
86
|
+
|
|
87
|
+
:return: The updated repository variable
|
|
88
|
+
|
|
89
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-variable-uuid-put
|
|
90
|
+
"""
|
|
91
|
+
return self._update_data(self.put(None, data=kwargs))
|
|
92
|
+
|
|
93
|
+
def delete(self):
|
|
94
|
+
"""
|
|
95
|
+
Delete the repository variable.
|
|
96
|
+
|
|
97
|
+
:return: The response on success
|
|
98
|
+
|
|
99
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-pipelines-config-variables-variable-uuid-delete
|
|
100
|
+
"""
|
|
101
|
+
return super(RepositoryVariable, self).delete(None)
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def uuid(self):
|
|
105
|
+
"""The repository variable uuid"""
|
|
106
|
+
return self.get_data("uuid")
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def key(self):
|
|
110
|
+
"""The repository variable key"""
|
|
111
|
+
return self.get_data("key")
|
|
112
|
+
|
|
113
|
+
@key.setter
|
|
114
|
+
def key(self, key):
|
|
115
|
+
"""Setter for the repository variable is key"""
|
|
116
|
+
return self.update(key=key)
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def scope(self):
|
|
120
|
+
"""The repository variable scope"""
|
|
121
|
+
return self.get_data("scope")
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def secured(self):
|
|
125
|
+
"""The repository variable secured"""
|
|
126
|
+
return self.get_data("secured")
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def system(self):
|
|
130
|
+
"""The repository variable system"""
|
|
131
|
+
return self.get_data("system")
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def type(self):
|
|
135
|
+
"""The repository variable type"""
|
|
136
|
+
return self.get_data("type")
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def value(self):
|
|
140
|
+
"""The repository variable value"""
|
|
141
|
+
return self.get_data("value")
|
|
142
|
+
|
|
143
|
+
@value.setter
|
|
144
|
+
def value(self, value):
|
|
145
|
+
"""Setter for the repository variable value"""
|
|
146
|
+
return self.update(value=value)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from requests import HTTPError
|
|
4
|
+
from ..base import BitbucketCloudBase
|
|
5
|
+
|
|
6
|
+
from .members import WorkspaceMembers
|
|
7
|
+
from .permissions import Permissions
|
|
8
|
+
from .projects import Projects
|
|
9
|
+
from ..repositories import WorkspaceRepositories
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Workspaces(BitbucketCloudBase):
|
|
13
|
+
def __init__(self, url, *args, **kwargs):
|
|
14
|
+
super(Workspaces, self).__init__(url, *args, **kwargs)
|
|
15
|
+
|
|
16
|
+
def __get_object(self, data):
|
|
17
|
+
return Workspace(data, **self._new_session_args)
|
|
18
|
+
|
|
19
|
+
def each(self, role=None, q=None, sort=None):
|
|
20
|
+
"""
|
|
21
|
+
Get all workspaces matching the criteria.
|
|
22
|
+
|
|
23
|
+
:param role: string (default is None):
|
|
24
|
+
Filters the workspaces based on the authenticated user's role on each workspace.
|
|
25
|
+
* member: returns a list of all the workspaces which the caller is a member of
|
|
26
|
+
at least one workspace group or repository
|
|
27
|
+
* collaborator: returns a list of workspaces which the caller has written access
|
|
28
|
+
to at least one repository in the workspace
|
|
29
|
+
* owner: returns a list of workspaces which the caller has administrator access
|
|
30
|
+
:param q: string (default is None):
|
|
31
|
+
Query string to narrow down the response.
|
|
32
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
33
|
+
:param sort: string (default is None):
|
|
34
|
+
Name of a response property to sort results.
|
|
35
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
36
|
+
|
|
37
|
+
:return: A generator for the Workspace objects
|
|
38
|
+
|
|
39
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces#get.
|
|
40
|
+
"""
|
|
41
|
+
params = {}
|
|
42
|
+
if role is not None:
|
|
43
|
+
params["role"] = role
|
|
44
|
+
if q is not None:
|
|
45
|
+
params["q"] = q
|
|
46
|
+
if sort is not None:
|
|
47
|
+
params["sort"] = sort
|
|
48
|
+
for workspace in self._get_paged(None, params):
|
|
49
|
+
yield self.__get_object(workspace)
|
|
50
|
+
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
def get(self, workspace):
|
|
54
|
+
"""
|
|
55
|
+
Returns the requested workspace
|
|
56
|
+
|
|
57
|
+
:param workspace: string: This can either be the workspace ID (slug) or the workspace UUID
|
|
58
|
+
surrounded by curly-braces, for example: {workspace UUID}.
|
|
59
|
+
|
|
60
|
+
:return: The requested Workspace objects
|
|
61
|
+
|
|
62
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D#get
|
|
63
|
+
"""
|
|
64
|
+
return self.__get_object(super(Workspaces, self).get(workspace))
|
|
65
|
+
|
|
66
|
+
def exists(self, workspace):
|
|
67
|
+
"""
|
|
68
|
+
Check if workspace exist.
|
|
69
|
+
|
|
70
|
+
:param workspace: string: The requested workspace.
|
|
71
|
+
|
|
72
|
+
:return: True if the workspace exists
|
|
73
|
+
|
|
74
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D#get
|
|
75
|
+
"""
|
|
76
|
+
exists = False
|
|
77
|
+
try:
|
|
78
|
+
self.get(workspace)
|
|
79
|
+
exists = True
|
|
80
|
+
except HTTPError as e:
|
|
81
|
+
if e.response.status_code in (401, 404):
|
|
82
|
+
pass
|
|
83
|
+
return exists
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class Workspace(BitbucketCloudBase):
|
|
87
|
+
def __init__(self, data, *args, **kwargs):
|
|
88
|
+
super(Workspace, self).__init__(None, *args, data=data, expected_type="workspace", **kwargs)
|
|
89
|
+
self.__permissions = Permissions(self.url_joiner(self.url, "permissions"), **self._new_session_args)
|
|
90
|
+
self.__projects = Projects(self.get_link("projects"), **self._new_session_args)
|
|
91
|
+
self.__repositories = WorkspaceRepositories(self.get_link("repositories"), **self._new_session_args)
|
|
92
|
+
self.__members = WorkspaceMembers(self.get_link("members"), **self._new_session_args)
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def name(self):
|
|
96
|
+
"""The workspace name"""
|
|
97
|
+
return self.get_data("name")
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def slug(self):
|
|
101
|
+
"""The workspace slug"""
|
|
102
|
+
return self.get_data("slug")
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def uuid(self):
|
|
106
|
+
"""The workspace uuid"""
|
|
107
|
+
return self.get_data("uuid")
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def is_private(self):
|
|
111
|
+
"""The workspace private flag"""
|
|
112
|
+
return self.get_data("is_private")
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def created_on(self):
|
|
116
|
+
"""The workspace creation time"""
|
|
117
|
+
return self.get_data("created_on")
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def updated_on(self):
|
|
121
|
+
"""The workspace last update time"""
|
|
122
|
+
return self.get_data("updated_on", "never updated")
|
|
123
|
+
|
|
124
|
+
def get_avatar(self):
|
|
125
|
+
"""The project avatar"""
|
|
126
|
+
return self.get(self.get_link("avatar"), absolute=True)
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def permissions(self):
|
|
130
|
+
"""The workspace permissions repositories"""
|
|
131
|
+
return self.__permissions
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def projects(self):
|
|
135
|
+
"""The workspace projects"""
|
|
136
|
+
return self.__projects
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def repositories(self):
|
|
140
|
+
"""The workspace repositories"""
|
|
141
|
+
return self.__repositories
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def members(self):
|
|
145
|
+
"""The workspace members"""
|
|
146
|
+
return self.__members
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from ..base import BitbucketCloudBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class WorkspaceMembers(BitbucketCloudBase):
|
|
7
|
+
def __init__(self, url, *args, **kwargs):
|
|
8
|
+
super(WorkspaceMembers, self).__init__(url, *args, **kwargs)
|
|
9
|
+
|
|
10
|
+
def __get_object(self, data):
|
|
11
|
+
return WorkspaceMember(data, **self._new_session_args)
|
|
12
|
+
|
|
13
|
+
def each(self):
|
|
14
|
+
"""
|
|
15
|
+
Get all members in the workspace
|
|
16
|
+
|
|
17
|
+
:return: A generator for the member objects
|
|
18
|
+
|
|
19
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-get
|
|
20
|
+
"""
|
|
21
|
+
for member in self._get_paged(None):
|
|
22
|
+
yield self.__get_object(member)
|
|
23
|
+
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
def get(self, member):
|
|
27
|
+
"""
|
|
28
|
+
Returns the requested member
|
|
29
|
+
|
|
30
|
+
:param member: string: Member's UUID or Atlassian ID.
|
|
31
|
+
|
|
32
|
+
:return: The requested Member object
|
|
33
|
+
|
|
34
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-members-member-get
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
return self.__get_object(super(WorkspaceMembers, self).get(member))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class WorkspaceMember(BitbucketCloudBase):
|
|
41
|
+
def __init__(self, data, *args, **kwargs):
|
|
42
|
+
super(WorkspaceMember, self).__init__(None, *args, data=data, expected_type="workspace_membership", **kwargs)
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def links(self):
|
|
46
|
+
"""The member links"""
|
|
47
|
+
return self.get_data("links")
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def type(self):
|
|
51
|
+
"""The member type"""
|
|
52
|
+
return self.get_data("type")
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def user(self):
|
|
56
|
+
"""The member user dictionary"""
|
|
57
|
+
return self.get_data("user")
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def workspace(self):
|
|
61
|
+
"""The member workspace dictionary"""
|
|
62
|
+
return self.get_data("workspace")
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from ..base import BitbucketCloudBase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Permissions(BitbucketCloudBase):
|
|
8
|
+
def __init__(self, url, *args, **kwargs):
|
|
9
|
+
super(Permissions, self).__init__(url, *args, **kwargs)
|
|
10
|
+
|
|
11
|
+
def __get_object_workspace_membership(self, data):
|
|
12
|
+
return WorkspaceMembership(
|
|
13
|
+
self.url,
|
|
14
|
+
data,
|
|
15
|
+
**self._new_session_args
|
|
16
|
+
) # fmt: skip
|
|
17
|
+
|
|
18
|
+
def __get_object_repository_permission(self, data):
|
|
19
|
+
return RepositoryPermission(self.url, data, **self._new_session_args)
|
|
20
|
+
|
|
21
|
+
def each(self, q=None, sort=None, pagelen=10):
|
|
22
|
+
"""
|
|
23
|
+
Returns the list of pipelines in this repository.
|
|
24
|
+
:param q: string: Query string to narrow down the response.
|
|
25
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
26
|
+
:param sort: string: Name of a response property to sort results.
|
|
27
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
28
|
+
:param pagelen: page length
|
|
29
|
+
:return: A generator for the Workspace Permission objects
|
|
30
|
+
|
|
31
|
+
API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-workspaces/#api-workspaces-workspace-permissions-get
|
|
32
|
+
"""
|
|
33
|
+
params = {}
|
|
34
|
+
if sort is not None:
|
|
35
|
+
params["sort"] = sort
|
|
36
|
+
if q is not None:
|
|
37
|
+
params["q"] = q
|
|
38
|
+
params["pagelen"] = pagelen
|
|
39
|
+
for workspace_membership in self._get_paged(
|
|
40
|
+
None,
|
|
41
|
+
trailing=True,
|
|
42
|
+
paging_workaround=True,
|
|
43
|
+
params=params,
|
|
44
|
+
):
|
|
45
|
+
yield self.__get_object_workspace_membership(workspace_membership)
|
|
46
|
+
|
|
47
|
+
return
|
|
48
|
+
|
|
49
|
+
def repositories(self, repo_slug="", pagelen=10):
|
|
50
|
+
for permissions in self._get_paged(
|
|
51
|
+
"repositories/{}".format(repo_slug), trailing=True, params={"pagelen": pagelen}
|
|
52
|
+
):
|
|
53
|
+
yield self.__get_object_repository_permission(permissions)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class WorkspaceMembership(BitbucketCloudBase):
|
|
57
|
+
def __init__(self, url, data, *args, **kwargs):
|
|
58
|
+
super(WorkspaceMembership, self).__init__(url, *args, data=data, expected_type="workspace_membership", **kwargs)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def uuid(self):
|
|
62
|
+
"""The workspace_membership uuid"""
|
|
63
|
+
return self.get_data("uuid")
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def type(self):
|
|
67
|
+
"""The workspace_membership type"""
|
|
68
|
+
return self.get_data("type")
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def user(self):
|
|
72
|
+
"""The workspace_membership user"""
|
|
73
|
+
return self.get_data("user")
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def workspace(self):
|
|
77
|
+
"""The workspace_membership workspace"""
|
|
78
|
+
return self.get_data("workspace")
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def links(self):
|
|
82
|
+
"""The workspace_membership links"""
|
|
83
|
+
return self.get_data("links")
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def added_on(self):
|
|
87
|
+
"""The workspace_membership added on"""
|
|
88
|
+
return self.get_time("added_on")
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def permission(self):
|
|
92
|
+
"""The workspace_membership permission"""
|
|
93
|
+
return self.get_data("permission")
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def last_accessed(self):
|
|
97
|
+
"""The workspace_membership last accessed"""
|
|
98
|
+
return self.get_time("last_accessed")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class RepositoryPermission(BitbucketCloudBase):
|
|
102
|
+
def __init__(self, url, data, *args, **kwargs):
|
|
103
|
+
super(RepositoryPermission, self).__init__(
|
|
104
|
+
url, *args, data=data, expected_type="repository_permission", **kwargs
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def repository(self):
|
|
109
|
+
"""The repository_permission uuid"""
|
|
110
|
+
return self.get_data("repository")
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def type(self):
|
|
114
|
+
"""The repository_permission type"""
|
|
115
|
+
return self.get_data("type")
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def permission(self):
|
|
119
|
+
"""The repository_permission permission"""
|
|
120
|
+
return self.get_data("permission")
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def user(self):
|
|
124
|
+
"""The repository_permission workspace"""
|
|
125
|
+
return self.get_data("user")
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from requests import HTTPError
|
|
4
|
+
from ..base import BitbucketCloudBase
|
|
5
|
+
|
|
6
|
+
from ..repositories import ProjectRepositories
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Projects(BitbucketCloudBase):
|
|
10
|
+
def __init__(self, url, *args, **kwargs):
|
|
11
|
+
super(Projects, self).__init__(url, *args, **kwargs)
|
|
12
|
+
|
|
13
|
+
def __get_object(self, data):
|
|
14
|
+
return Project(data, **self._new_session_args)
|
|
15
|
+
|
|
16
|
+
def create(self, name, key, description, is_private=True, avatar=None):
|
|
17
|
+
"""
|
|
18
|
+
Creates a new project with the given values
|
|
19
|
+
|
|
20
|
+
Note that the avatar has to be embedded as either a data-url or a URL to an external image as shown in
|
|
21
|
+
the examples below:
|
|
22
|
+
|
|
23
|
+
w.projects.create( "Mars Project", "MARS", "Software for colonizing mars.",
|
|
24
|
+
avatar="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/...",
|
|
25
|
+
is_private=False
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
w.projects.create( "Mars Project", "MARS", "Software for colonizing mars.",
|
|
29
|
+
avatar="http://i.imgur.com/72tRx4w.gif",
|
|
30
|
+
is_private=False
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
:param name: string: The name of the project.
|
|
34
|
+
:param key: string: The key of the project.
|
|
35
|
+
:param description: string: The description of the project.
|
|
36
|
+
:param is_private: bool (default is True): True if it is a private project.
|
|
37
|
+
:param avatar: string (default is None): The avatar of the project.
|
|
38
|
+
|
|
39
|
+
:return: The created project object
|
|
40
|
+
|
|
41
|
+
API docs:
|
|
42
|
+
https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects#post
|
|
43
|
+
"""
|
|
44
|
+
data = {
|
|
45
|
+
"name": name,
|
|
46
|
+
"key": key,
|
|
47
|
+
"description": description,
|
|
48
|
+
"is_private": is_private,
|
|
49
|
+
}
|
|
50
|
+
if avatar:
|
|
51
|
+
data["avatar"] = avatar
|
|
52
|
+
return self.__get_object(self.post(None, data=data))
|
|
53
|
+
|
|
54
|
+
def each(self, q=None, sort=None):
|
|
55
|
+
"""
|
|
56
|
+
Get all projects in the workspace matching the criteria.
|
|
57
|
+
:param q: string (default is None): Query string to narrow down the response.
|
|
58
|
+
See for details:
|
|
59
|
+
https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
|
|
60
|
+
:param sort: string (default is None): Name of a response property to sort results.
|
|
61
|
+
See for details:
|
|
62
|
+
https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
|
|
63
|
+
:return: A generator for the project objects
|
|
64
|
+
|
|
65
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects#get
|
|
66
|
+
"""
|
|
67
|
+
params = {}
|
|
68
|
+
if sort is not None:
|
|
69
|
+
params["sort"] = sort
|
|
70
|
+
if q is not None:
|
|
71
|
+
params["q"] = q
|
|
72
|
+
for project in self._get_paged(None, params=params):
|
|
73
|
+
yield self.__get_object(project)
|
|
74
|
+
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
def get(self, project, by="key"):
|
|
78
|
+
"""
|
|
79
|
+
Returns the requested project
|
|
80
|
+
|
|
81
|
+
:param project: string: The requested project.
|
|
82
|
+
:param by: string (default is "key"): How to interpret project, can be 'key' or 'name'.
|
|
83
|
+
|
|
84
|
+
:return: The requested Project object
|
|
85
|
+
|
|
86
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects/%7Bproject_key%7D#get
|
|
87
|
+
"""
|
|
88
|
+
if by == "key":
|
|
89
|
+
return self.__get_object(super(Projects, self).get(project))
|
|
90
|
+
elif by == "name":
|
|
91
|
+
for p in self.each():
|
|
92
|
+
if p.name == project:
|
|
93
|
+
return p
|
|
94
|
+
else:
|
|
95
|
+
ValueError("Unknown value '{}' for argument [by], expected 'key' or 'name'".format(by))
|
|
96
|
+
|
|
97
|
+
raise Exception("Unknown project {} '{}'".format(by, project))
|
|
98
|
+
|
|
99
|
+
def exists(self, project, by="key"):
|
|
100
|
+
"""
|
|
101
|
+
Check if project exist.
|
|
102
|
+
|
|
103
|
+
:param project: string: The requested project.
|
|
104
|
+
:param by: string (default is "key"): How to interpret project, can be 'key' or 'name'.
|
|
105
|
+
|
|
106
|
+
:return: True if the project exists
|
|
107
|
+
|
|
108
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects/%7Bproject_key%7D#get
|
|
109
|
+
"""
|
|
110
|
+
exists = False
|
|
111
|
+
try:
|
|
112
|
+
self.get(project, by)
|
|
113
|
+
exists = True
|
|
114
|
+
except HTTPError as e:
|
|
115
|
+
if e.response.status_code in (401, 404):
|
|
116
|
+
pass
|
|
117
|
+
except Exception as e:
|
|
118
|
+
if not str(e) == "Unknown project {} '{}'".format(by, project):
|
|
119
|
+
raise e
|
|
120
|
+
return exists
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class Project(BitbucketCloudBase):
|
|
124
|
+
def __init__(self, data, *args, **kwargs):
|
|
125
|
+
super(Project, self).__init__(None, *args, data=data, expected_type="project", **kwargs)
|
|
126
|
+
try:
|
|
127
|
+
url = self.get_link("repositories")
|
|
128
|
+
except KeyError:
|
|
129
|
+
workspace = self.get_data("workspace")
|
|
130
|
+
url = '{}/?q=project.key="{}"'.format(workspace["links"]["self"], workspace["slug"])
|
|
131
|
+
self.__repositories = ProjectRepositories(url, **self._new_session_args)
|
|
132
|
+
|
|
133
|
+
def update(self, **kwargs):
|
|
134
|
+
"""
|
|
135
|
+
Update the project properties. Fields not present in the request body are ignored.
|
|
136
|
+
|
|
137
|
+
:param kwargs: dict: The data to update.
|
|
138
|
+
|
|
139
|
+
:return: The updated project
|
|
140
|
+
|
|
141
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects/%7Bproject_key%7D#put
|
|
142
|
+
"""
|
|
143
|
+
return self._update_data(self.put(None, data=kwargs))
|
|
144
|
+
|
|
145
|
+
def delete(self):
|
|
146
|
+
"""
|
|
147
|
+
Delete the project.
|
|
148
|
+
|
|
149
|
+
:return: The response on success
|
|
150
|
+
|
|
151
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/workspaces/%7Bworkspace%7D/projects/%7Bproject_key%7D#delete
|
|
152
|
+
"""
|
|
153
|
+
data = super(Project, self).delete(None)
|
|
154
|
+
if data is None or "errors" in data:
|
|
155
|
+
return
|
|
156
|
+
return data
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def name(self):
|
|
160
|
+
"""The project name"""
|
|
161
|
+
return self.get_data("name")
|
|
162
|
+
|
|
163
|
+
@name.setter
|
|
164
|
+
def name(self, name):
|
|
165
|
+
"""Setter for the project name"""
|
|
166
|
+
return self.update(name=name)
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def key(self):
|
|
170
|
+
"""The project key"""
|
|
171
|
+
return self.get_data("key")
|
|
172
|
+
|
|
173
|
+
@key.setter
|
|
174
|
+
def key(self, key):
|
|
175
|
+
"""Setter for the project key"""
|
|
176
|
+
return self.update(key=key)
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def description(self):
|
|
180
|
+
"""The project description"""
|
|
181
|
+
return self.get_data("description")
|
|
182
|
+
|
|
183
|
+
@description.setter
|
|
184
|
+
def description(self, description):
|
|
185
|
+
"""Setter for the project description"""
|
|
186
|
+
return self.update(description=description)
|
|
187
|
+
|
|
188
|
+
@property
|
|
189
|
+
def is_private(self):
|
|
190
|
+
"""The project private flag"""
|
|
191
|
+
return self.get_data("is_private")
|
|
192
|
+
|
|
193
|
+
@is_private.setter
|
|
194
|
+
def is_private(self, is_private):
|
|
195
|
+
"""Setter for the project private flag"""
|
|
196
|
+
return self.update(is_private=is_private)
|
|
197
|
+
|
|
198
|
+
@property
|
|
199
|
+
def created_on(self):
|
|
200
|
+
"""The project creation time"""
|
|
201
|
+
return self.get_data("created_on")
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def updated_on(self):
|
|
205
|
+
"""The project last update time"""
|
|
206
|
+
return self.get_data("updated_on", "never updated")
|
|
207
|
+
|
|
208
|
+
def get_avatar(self):
|
|
209
|
+
"""The project avatar"""
|
|
210
|
+
return self.get(self.get_link("avatar"), absolute=True)
|
|
211
|
+
|
|
212
|
+
@property
|
|
213
|
+
def repositories(self):
|
|
214
|
+
"""The project repositories"""
|
|
215
|
+
return self.__repositories
|