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.
Files changed (54) hide show
  1. atlassian/VERSION +1 -0
  2. atlassian/__init__.py +32 -0
  3. atlassian/bamboo.py +1343 -0
  4. atlassian/bitbucket/__init__.py +3572 -0
  5. atlassian/bitbucket/base.py +198 -0
  6. atlassian/bitbucket/cloud/__init__.py +24 -0
  7. atlassian/bitbucket/cloud/base.py +123 -0
  8. atlassian/bitbucket/cloud/common/__init__.py +1 -0
  9. atlassian/bitbucket/cloud/common/builds.py +85 -0
  10. atlassian/bitbucket/cloud/common/comments.py +50 -0
  11. atlassian/bitbucket/cloud/common/users.py +79 -0
  12. atlassian/bitbucket/cloud/repositories/__init__.py +437 -0
  13. atlassian/bitbucket/cloud/repositories/branchRestrictions.py +175 -0
  14. atlassian/bitbucket/cloud/repositories/commits.py +188 -0
  15. atlassian/bitbucket/cloud/repositories/defaultReviewers.py +94 -0
  16. atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py +264 -0
  17. atlassian/bitbucket/cloud/repositories/diffstat.py +92 -0
  18. atlassian/bitbucket/cloud/repositories/groupPermissions.py +81 -0
  19. atlassian/bitbucket/cloud/repositories/hooks.py +117 -0
  20. atlassian/bitbucket/cloud/repositories/issues.py +164 -0
  21. atlassian/bitbucket/cloud/repositories/pipelines.py +274 -0
  22. atlassian/bitbucket/cloud/repositories/pullRequests.py +483 -0
  23. atlassian/bitbucket/cloud/repositories/refs.py +136 -0
  24. atlassian/bitbucket/cloud/repositories/repositoryVariables.py +146 -0
  25. atlassian/bitbucket/cloud/workspaces/__init__.py +146 -0
  26. atlassian/bitbucket/cloud/workspaces/members.py +62 -0
  27. atlassian/bitbucket/cloud/workspaces/permissions.py +125 -0
  28. atlassian/bitbucket/cloud/workspaces/projects.py +215 -0
  29. atlassian/bitbucket/server/__init__.py +46 -0
  30. atlassian/bitbucket/server/base.py +63 -0
  31. atlassian/bitbucket/server/common/__init__.py +1 -0
  32. atlassian/bitbucket/server/common/permissions.py +220 -0
  33. atlassian/bitbucket/server/globalPermissions.py +198 -0
  34. atlassian/bitbucket/server/projects/__init__.py +244 -0
  35. atlassian/bitbucket/server/projects/repos/__init__.py +327 -0
  36. atlassian/cloud_admin.py +32 -0
  37. atlassian/confluence.py +3336 -0
  38. atlassian/crowd.py +266 -0
  39. atlassian/errors.py +27 -0
  40. atlassian/insight.py +678 -0
  41. atlassian/jira.py +5324 -0
  42. atlassian/marketplace.py +84 -0
  43. atlassian/portfolio.py +108 -0
  44. atlassian/request_utils.py +39 -0
  45. atlassian/rest_client.py +558 -0
  46. atlassian/service_desk.py +911 -0
  47. atlassian/statuspage.py +3133 -0
  48. atlassian/utils.py +327 -0
  49. atlassian/xray.py +632 -0
  50. atlassian_python_api-3.41.13.dist-info/LICENSE +201 -0
  51. atlassian_python_api-3.41.13.dist-info/METADATA +261 -0
  52. atlassian_python_api-3.41.13.dist-info/RECORD +54 -0
  53. atlassian_python_api-3.41.13.dist-info/WHEEL +5 -0
  54. atlassian_python_api-3.41.13.dist-info/top_level.txt +1 -0
@@ -0,0 +1,188 @@
1
+ # coding=utf-8
2
+
3
+ from ..base import BitbucketCloudBase
4
+ from ..common.builds import Build
5
+ from ..common.comments import Comment
6
+ from ..common.users import User, Participant
7
+
8
+
9
+ class Commits(BitbucketCloudBase):
10
+ """Bitbucket Cloud commits."""
11
+
12
+ def __init__(self, url, *args, **kwargs):
13
+ super(Commits, self).__init__(url, *args, **kwargs)
14
+
15
+ def __get_object(self, data):
16
+ return Commit(data, **self._new_session_args)
17
+
18
+ def each(self, top=None, q=None, sort=None):
19
+ """
20
+ Return the list of commits in this repository.
21
+
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.
25
+ :param sort: string: Name of a response property to sort results.
26
+ See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
27
+
28
+ :return: A generator for the Commit objects
29
+
30
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get
31
+ """
32
+ params = {}
33
+ if sort is not None:
34
+ params["sort"] = sort
35
+ if q is not None:
36
+ params["q"] = q
37
+ trailing = True
38
+ if top is not None:
39
+ trailing = False
40
+ for commit in self._get_paged(top, trailing=trailing, params=params):
41
+ yield self.__get_object(commit)
42
+
43
+ def get(self, commit_hash):
44
+ """
45
+ Return the commit with the requested commit id in this repository.
46
+
47
+ :param commit_hash: str: The requested commit id
48
+
49
+ :return: The requested Commit object
50
+
51
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-get
52
+ """
53
+ return self.__get_object(
54
+ super(Commits, self).get(
55
+ self.url_joiner(self.get_link("commit"), commit_hash),
56
+ absolute=True,
57
+ )
58
+ )
59
+
60
+
61
+ class Commit(BitbucketCloudBase):
62
+ """
63
+ Bitbucket Cloud commit endpoint.
64
+
65
+ See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-get
66
+ """
67
+
68
+ def __init__(self, data, *args, **kwargs):
69
+ super(Commit, self).__init__(None, *args, data=data, expected_type="commit", **kwargs)
70
+
71
+ @property
72
+ def hash(self):
73
+ """Commit id."""
74
+ return self.get_data("hash")
75
+
76
+ @property
77
+ def message(self):
78
+ """Commit message."""
79
+ return self.get_data("message")
80
+
81
+ @property
82
+ def date(self):
83
+ """Commit date."""
84
+ return self.get_time("date")
85
+
86
+ @property
87
+ def author(self):
88
+ """User object of the author."""
89
+ return User(None, self.get_data("author").get("user"))
90
+
91
+ def parents(self):
92
+ """Return a generator object of parent commits."""
93
+ for commit in self.get_data("parents"):
94
+ yield Commit(commit, **self._new_session_args)
95
+
96
+ def statuses(self):
97
+ """
98
+ Return generator object of the status's endpoint.
99
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-get
100
+ """
101
+ return self._get_paged("statuses")
102
+
103
+ def participants(self):
104
+ """Return a generator object of participants."""
105
+ for participant in self.get_data("participants"):
106
+ yield Participant(participant, **self._new_session_args)
107
+
108
+ def builds(self):
109
+ """Return the Build objects for the commit."""
110
+ builds = [b for b in self.statuses() if b["type"] == "build"]
111
+ for build in builds:
112
+ yield Build(build, **self._new_session_args)
113
+
114
+ def add_build(
115
+ self,
116
+ key,
117
+ url=None,
118
+ description=None,
119
+ refname=None,
120
+ state=Build.STATE_INPROGRESS,
121
+ ):
122
+ """
123
+ Add new build status to commit.
124
+
125
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-post
126
+ """
127
+ data = {
128
+ "key": key,
129
+ "state": state,
130
+ "description": description,
131
+ "url": url,
132
+ "refname": refname,
133
+ }
134
+
135
+ return self.post("statuses/build", data)
136
+
137
+ def get_build(self, key):
138
+ """
139
+ Return a specific build for the commit.
140
+
141
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commit-statuses/#api-repositories-workspace-repo-slug-commit-commit-statuses-build-key-get
142
+ """
143
+ return Build(
144
+ super(Commit, self).get(self.url_joiner("statuses/build", key)),
145
+ **self._new_session_args
146
+ ) # fmt: skip
147
+
148
+ def comments(self):
149
+ """
150
+ Return generator object endpoint of the comment.
151
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-get
152
+ """
153
+ for comment in self._get_paged("comments"):
154
+ yield Comment(comment, **self._new_session_args)
155
+
156
+ def comment(self, raw_message):
157
+ """
158
+ Add a comment to the pull request in raw format.
159
+
160
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-comments-post
161
+ """
162
+ if not raw_message:
163
+ raise ValueError("No message set")
164
+
165
+ data = {
166
+ "content": {
167
+ "raw": raw_message,
168
+ }
169
+ }
170
+
171
+ return self.post("comments", data)
172
+
173
+ def approve(self):
174
+ """
175
+ Approve a commit.
176
+
177
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-post
178
+ """
179
+ data = {"approved": True}
180
+ return self.post("approve", data)
181
+
182
+ def unapprove(self):
183
+ """
184
+ Unapprove a commit.
185
+
186
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commit-commit-approve-delete
187
+ """
188
+ return super(BitbucketCloudBase, self).delete("approve")
@@ -0,0 +1,94 @@
1
+ # coding=utf-8
2
+
3
+ from requests import HTTPError
4
+
5
+ from ..base import BitbucketCloudBase
6
+ from ..common.users import User
7
+
8
+
9
+ class DefaultReviewers(BitbucketCloudBase):
10
+ def __init__(self, url, *args, **kwargs):
11
+ super(DefaultReviewers, self).__init__(url, *args, **kwargs)
12
+
13
+ def __get_object(self, data):
14
+ return DefaultReviewer(
15
+ self.url_joiner(self.url, data["uuid"]),
16
+ data,
17
+ **self._new_session_args
18
+ ) # fmt: skip
19
+
20
+ def add(self, user):
21
+ """
22
+ Adds the specified user to the repository's list of default reviewers.
23
+
24
+ This method is idempotent. Adding a user a second time has no effect.
25
+
26
+ :param user: string: The user to add
27
+
28
+ :return: The added DefaultReviewer object
29
+
30
+ API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/default-reviewers/%7Btarget_username%7D#put
31
+ """
32
+ # the mention_id parameter is undocumented but if missed, leads to 400 statuses
33
+ return self.__get_object(self.put(user, data={"mention_id": user}))
34
+
35
+ def each(self, q=None, sort=None):
36
+ """
37
+ Returns the repository's default reviewers.
38
+ These are the users that are automatically added as reviewers on every new pull request
39
+ that is created.
40
+
41
+ :param q: string: Query string to narrow down the response.
42
+ See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
43
+ :param sort: string: Name of a response property to sort results.
44
+ See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
45
+
46
+ :return: A generator for the DefaultReviewer objects
47
+
48
+ API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/default-reviewers#get
49
+ """
50
+ params = {}
51
+ if sort is not None:
52
+ params["sort"] = sort
53
+ if q is not None:
54
+ params["q"] = q
55
+ for default_reviewer in self._get_paged(None, params=params):
56
+ yield self.__get_object(default_reviewer)
57
+
58
+ return
59
+
60
+ def get(self, user):
61
+ """
62
+ Returns the default reviewer in this repository.
63
+
64
+ :param user: string: The requested username
65
+
66
+ :return: The requested DefaultReviewer object, None if not a default reviewer
67
+
68
+ API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/default-reviewers/%7Btarget_username%7D#get
69
+ """
70
+ default_reviewer = None
71
+ try:
72
+ default_reviewer = self.__get_object(super(DefaultReviewers, self).get(user))
73
+ except HTTPError as e:
74
+ # A 404 indicates that the specified user is not a default reviewer.
75
+ if not e.response.status_code == 404:
76
+ # Rethrow the exception
77
+ raise
78
+
79
+ return default_reviewer
80
+
81
+
82
+ class DefaultReviewer(User):
83
+ def __init__(self, url, data, *args, **kwargs):
84
+ super(DefaultReviewer, self).__init__(url, data, *args, **kwargs)
85
+
86
+ def delete(self):
87
+ """
88
+ Delete the default reviewer.
89
+
90
+ :return: The response on success
91
+
92
+ API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/default-reviewers/%7Btarget_username%7D#delete
93
+ """
94
+ return super(DefaultReviewer, self).delete(None)
@@ -0,0 +1,264 @@
1
+ # coding=utf-8
2
+
3
+ from ..base import BitbucketCloudBase
4
+
5
+ from six.moves.urllib.parse import urlunsplit, urlsplit
6
+
7
+
8
+ class DeploymentEnvironments(BitbucketCloudBase):
9
+ def __init__(self, url, *args, **kwargs):
10
+ super(DeploymentEnvironments, self).__init__(url, *args, **kwargs)
11
+
12
+ def __get_object(self, data):
13
+ return DeploymentEnvironment(
14
+ self.url_joiner(self.url, data["uuid"]),
15
+ data,
16
+ **self._new_session_args
17
+ ) # fmt: skip
18
+
19
+ def each(self):
20
+ """
21
+ Returns the list of environments in this repository.
22
+
23
+ :return: A list of the DeploymentEnvironment objects
24
+
25
+ API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/environments/#get
26
+ """
27
+
28
+ # workaround for this issue
29
+ # https://jira.atlassian.com/browse/BCLOUD-20796
30
+ response = super(BitbucketCloudBase, self).get(None)
31
+
32
+ deployment_environments = []
33
+
34
+ for value in response.get("values", []):
35
+ deployment_environments.append(self.__get_object(value))
36
+
37
+ return deployment_environments
38
+
39
+ def get(self, uuid):
40
+ """
41
+ Returns the environment with the uuid in this repository.
42
+
43
+ :param uuid: string: The requested environment uuid
44
+
45
+ :return: The requested DeploymentEnvironment objects
46
+
47
+ API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/environments/%7Benvironment_uuid%7D#get
48
+ """
49
+ return self.__get_object(super(DeploymentEnvironments, self).get(uuid))
50
+
51
+
52
+ class DeploymentEnvironment(BitbucketCloudBase):
53
+ def __init__(self, url, data, *args, **kwargs):
54
+ super(DeploymentEnvironment, self).__init__(
55
+ url, *args, data=data, expected_type="deployment_environment", **kwargs
56
+ )
57
+ deployment_environment_url = self.get_deployment_environment_variable_url(self.url)
58
+ self.__deployment_environment_variables = DeploymentEnvironmentVariables(
59
+ "{}/variables".format(deployment_environment_url), **self._new_session_args
60
+ )
61
+
62
+ @property
63
+ def uuid(self):
64
+ """The deployment environment uuid"""
65
+ return self.get_data("uuid")
66
+
67
+ @property
68
+ def category(self):
69
+ """The deployment environment category"""
70
+ return self.get_data("category")
71
+
72
+ @property
73
+ def deployment_gate_enabled(self):
74
+ """The deployment environment deployment gate enabled"""
75
+ return self.get_data("deployment_gate_enabled")
76
+
77
+ @property
78
+ def environment_lock_enabled(self):
79
+ """The deployment environment environment lock enabled"""
80
+ return self.get_data("environment_lock_enabled")
81
+
82
+ @property
83
+ def environment_type(self):
84
+ """The deployment environment environment type"""
85
+ return self.get_data("environment_type")
86
+
87
+ @property
88
+ def hidden(self):
89
+ """The deployment environment hidden"""
90
+ return self.get_data("hidden")
91
+
92
+ @property
93
+ def lock(self):
94
+ """The deployment environment lock"""
95
+ return self.get_data("lock")
96
+
97
+ @property
98
+ def name(self):
99
+ """The deployment environment name"""
100
+ return self.get_data("name")
101
+
102
+ @property
103
+ def rank(self):
104
+ """The deployment environment rank"""
105
+ return self.get_data("rank")
106
+
107
+ @property
108
+ def restrictions(self):
109
+ """The deployment environment restrictions"""
110
+ return self.get_data("restrictions")
111
+
112
+ @property
113
+ def slug(self):
114
+ """The deployment environment slug"""
115
+ return self.get_data("slug")
116
+
117
+ @property
118
+ def type(self):
119
+ """The deployment environment type"""
120
+ return self.get_data("type")
121
+
122
+ @property
123
+ def deployment_environment_variables(self):
124
+ """The deployment environment variables"""
125
+ return self.__deployment_environment_variables
126
+
127
+ def get_deployment_environment_variable_url(self, url):
128
+ parsed_url = urlsplit(url)
129
+ path = parsed_url.path.split("/environments/")
130
+ new_path = "{}/deployments_config/environments/{}".format(path[0], path[1])
131
+ list_parsed_url = list(parsed_url[:])
132
+ list_parsed_url[2] = new_path
133
+ return urlunsplit(tuple(list_parsed_url))
134
+
135
+
136
+ class DeploymentEnvironmentVariables(BitbucketCloudBase):
137
+ def __init__(self, url, *args, **kwargs):
138
+ super(DeploymentEnvironmentVariables, self).__init__(url, *args, **kwargs)
139
+
140
+ def __get_object(self, data):
141
+ return DeploymentEnvironmentVariable(
142
+ self.url,
143
+ data,
144
+ **self._new_session_args
145
+ ) # fmt: skip
146
+
147
+ def create(self, key, value, secured):
148
+ """
149
+ Create a new deployment environment variable for the given repository.
150
+
151
+ :param key: string: The unique name of the variable.
152
+ :param value: string: The value of the variable. If the variable is secured, this will be empty.
153
+ :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.
154
+
155
+ :return: The created DeploymentEnvironment object
156
+
157
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-deployments-config-environments-environment-uuid-variables-post
158
+ """
159
+ data = {"key": key, "value": value, "secured": secured}
160
+ return self.__get_object(self.post(None, data=data))
161
+
162
+ def each(self, pagelen=10):
163
+ """
164
+ Returns the list of deployment environment variables in this repository.
165
+
166
+ :param pagelen: integer: Query string to return this number of items from api.
167
+ See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
168
+
169
+ :return: A list of DeploymentEnvironmentVariable objects
170
+
171
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-deployments-config-environments-environment-uuid-variables-get
172
+ """
173
+ params = {"pagelen": pagelen}
174
+
175
+ response = super(BitbucketCloudBase, self).get(None, params=params)
176
+
177
+ pagelen = response.get("pagelen")
178
+ size_total = response.get("size")
179
+ pagelen_total = response.get("pagelen")
180
+ page = 1
181
+
182
+ deployment_environment_variables = []
183
+
184
+ # workaround for this issue
185
+ # https://jira.atlassian.com/browse/BCLOUD-20796
186
+ while True:
187
+ for value in response.get("values", []):
188
+ deployment_environment_variables.append(self.__get_object(value))
189
+
190
+ if pagelen_total < size_total:
191
+ pagelen_total = pagelen_total + response["pagelen"]
192
+ page += 1
193
+ response = super(BitbucketCloudBase, self).get(None, params={"pagelen": pagelen, "page": page})
194
+ else:
195
+ break
196
+
197
+ return deployment_environment_variables
198
+
199
+
200
+ class DeploymentEnvironmentVariable(BitbucketCloudBase):
201
+ def __init__(self, url, data, *args, **kwargs):
202
+ # This is needed when creating a new environment variable
203
+ # since the API doesn't return a 'type'.
204
+ if data.get("type") is None:
205
+ data["type"] = "pipeline_variable"
206
+
207
+ super(DeploymentEnvironmentVariable, self).__init__(
208
+ url, *args, data=data, expected_type="pipeline_variable", **kwargs
209
+ )
210
+
211
+ def update(self, **kwargs):
212
+ """
213
+ Update the repository variable properties. Fields not present in the request body are ignored.
214
+
215
+ :param kwargs: dict: The data to update.
216
+
217
+ :return: The updated repository variable
218
+
219
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-deployments-config-environments-environment-uuid-variables-variable-uuid-put
220
+ """
221
+ return self._update_data(self.put("/{}".format(self.uuid), data=kwargs))
222
+
223
+ def delete(self):
224
+ """
225
+ Delete the repository variable.
226
+ :return: The response on success
227
+ API docs: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pipelines/#api-repositories-workspace-repo-slug-deployments-config-environments-environment-uuid-variables-variable-uuid-delete
228
+ """
229
+ return super(DeploymentEnvironmentVariable, self).delete("/{}".format(self.uuid))
230
+
231
+ @property
232
+ def uuid(self):
233
+ """The deployment environment variable uuid"""
234
+ return self.get_data("uuid")
235
+
236
+ @property
237
+ def key(self):
238
+ """The deployment environment variable key"""
239
+ return self.get_data("key")
240
+
241
+ @key.setter
242
+ def key(self, key):
243
+ """Setter for the deployment environment variable key"""
244
+ return self.update(key=key)
245
+
246
+ @property
247
+ def secured(self):
248
+ """The deployment environment variable is secured"""
249
+ return self.get_data("secured")
250
+
251
+ @property
252
+ def type(self):
253
+ """The deployment environment variable type"""
254
+ return self.get_data("type")
255
+
256
+ @property
257
+ def value(self):
258
+ """The deployment environment variable value"""
259
+ return self.get_data("value")
260
+
261
+ @value.setter
262
+ def value(self, value):
263
+ """Setter for the deployment environment variable value"""
264
+ return self.update(value=value)
@@ -0,0 +1,92 @@
1
+ from ..base import BitbucketCloudBase
2
+
3
+
4
+ class DiffStat(BitbucketCloudBase):
5
+ """
6
+ Bitbucket Cloud repository diffstat entry.
7
+
8
+ This represents the changes for one specific file in a diff.
9
+
10
+ See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-diffstat-spec-get
11
+ """
12
+
13
+ MODIFIED = "modified"
14
+ ADDED = "added"
15
+ REMOVED = "removed"
16
+ LOCAL_DELETED = "local deleted"
17
+ REMOTE_DELETED = "remote deleted"
18
+ MERGE_CONFLICT = "merge conflict"
19
+ RENAME_CONFLICT = "rename conflict"
20
+ RENAME_DELETE_CONFLICT = "rename/delete conflict"
21
+ SUBREPO_CONFLICT = "subrepo conflict"
22
+
23
+ def __init__(self, data, *args, **kwargs):
24
+ """See BitbucketCloudBase."""
25
+ super(DiffStat, self).__init__(None, None, *args, data=data, expected_type="diffstat", **kwargs)
26
+
27
+ @property
28
+ def lines_removed(self):
29
+ """Lines removed."""
30
+ return self.get_data("lines_removed")
31
+
32
+ @property
33
+ def lines_added(self):
34
+ """Lines added."""
35
+ return self.get_data("lines_added")
36
+
37
+ @property
38
+ def old(self):
39
+ """A CommitFile object, representing a file at a commit in a repository."""
40
+ return CommitFile(self.get_data("old"), **self._new_session_args)
41
+
42
+ @property
43
+ def new(self):
44
+ """A CommitFile object, representing a file at a commit in a repository."""
45
+ return CommitFile(self.get_data("new"), **self._new_session_args)
46
+
47
+ @property
48
+ def has_conflict(self):
49
+ """True if the change causes a conflict."""
50
+ return str(self.get_data("status")) in [
51
+ self.MERGE_CONFLICT,
52
+ self.RENAME_CONFLICT,
53
+ self.RENAME_DELETE_CONFLICT,
54
+ self.SUBREPO_CONFLICT,
55
+ self.LOCAL_DELETED,
56
+ self.REMOTE_DELETED,
57
+ ]
58
+
59
+
60
+ class CommitFile(BitbucketCloudBase):
61
+ """
62
+ Bitbucket Cloud repository diffstat file.
63
+
64
+ File reference from a diffstat entry.
65
+
66
+ See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-diffstat-spec-get
67
+ """
68
+
69
+ def __init__(self, data, *args, **kwargs):
70
+ """See BitbucketCloudBase."""
71
+ if data is None: # handles add/remove
72
+ data = {
73
+ "path": None,
74
+ "escaped_path": None,
75
+ "links": {},
76
+ "type": "commit_file",
77
+ }
78
+ super(CommitFile, self).__init__(None, None, *args, data=data, expected_type="commit_file", **kwargs)
79
+
80
+ @property
81
+ def path(self):
82
+ """The path in the repository."""
83
+ return self.get_data("path")
84
+
85
+ @property
86
+ def escaped_path(self):
87
+ """
88
+ The escaped version of the path as it appears in a diff.
89
+
90
+ If the path does not require escaping this will be the same as path.
91
+ """
92
+ return self.get_data("escaped_path")