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,483 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from ..base import BitbucketCloudBase
|
|
4
|
+
from .diffstat import DiffStat
|
|
5
|
+
from ...cloud.repositories.commits import Commit
|
|
6
|
+
from ..common.builds import Build
|
|
7
|
+
from ..common.comments import Comment
|
|
8
|
+
from ..common.users import User, Participant
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PullRequests(BitbucketCloudBase):
|
|
12
|
+
"""
|
|
13
|
+
Bitbucket Cloud pull requests
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, url, *args, **kwargs):
|
|
17
|
+
super(PullRequests, self).__init__(url, *args, **kwargs)
|
|
18
|
+
|
|
19
|
+
def __get_object(self, data):
|
|
20
|
+
return PullRequest(data, **self._new_session_args)
|
|
21
|
+
|
|
22
|
+
def create(
|
|
23
|
+
self,
|
|
24
|
+
title,
|
|
25
|
+
source_branch,
|
|
26
|
+
destination_branch=None,
|
|
27
|
+
description=None,
|
|
28
|
+
close_source_branch=None,
|
|
29
|
+
reviewers=None,
|
|
30
|
+
):
|
|
31
|
+
"""
|
|
32
|
+
Creates a new pull requests for a given source branch
|
|
33
|
+
Be careful, adding this multiple times for the same source branch updates the pull request!
|
|
34
|
+
|
|
35
|
+
:param title: string: pull request title
|
|
36
|
+
:param source_branch: string: name of the source branch
|
|
37
|
+
:param destination_branch: string: name of the destination branch, if None the repository main branch is used
|
|
38
|
+
:param description: string: pull request description
|
|
39
|
+
:param close_source_branch: bool: specifies if the source branch should be closed upon merging
|
|
40
|
+
:param reviewers: list: list of user uuids in curly brackets
|
|
41
|
+
|
|
42
|
+
:return: Pull Request Object
|
|
43
|
+
|
|
44
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests#post
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
rv = [{"uuid": x} for x in reviewers] if reviewers else []
|
|
48
|
+
data = {
|
|
49
|
+
"title": title,
|
|
50
|
+
"source": {"branch": {"name": source_branch}},
|
|
51
|
+
"description": description,
|
|
52
|
+
"close_source_branch": close_source_branch,
|
|
53
|
+
"reviewers": rv,
|
|
54
|
+
}
|
|
55
|
+
if destination_branch:
|
|
56
|
+
data["destination"] = {"branch": {"name": destination_branch}}
|
|
57
|
+
|
|
58
|
+
return self.__get_object(self.post(None, data))
|
|
59
|
+
|
|
60
|
+
def each(self, q=None, sort=None):
|
|
61
|
+
"""
|
|
62
|
+
Returns the list of pull requests in this repository.
|
|
63
|
+
|
|
64
|
+
:param q: string: Query string to narrow down the response.
|
|
65
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
66
|
+
:param sort: string: Name of a response property to sort results.
|
|
67
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
68
|
+
|
|
69
|
+
:return: A generator for the PullRequest objects
|
|
70
|
+
|
|
71
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests#get
|
|
72
|
+
"""
|
|
73
|
+
params = {}
|
|
74
|
+
if sort is not None:
|
|
75
|
+
params["sort"] = sort
|
|
76
|
+
if q is not None:
|
|
77
|
+
params["q"] = q
|
|
78
|
+
for pr in self._get_paged(None, trailing=True, params=params):
|
|
79
|
+
yield self.__get_object(super(PullRequests, self).get(pr.get("id")))
|
|
80
|
+
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
def get(self, id):
|
|
84
|
+
"""
|
|
85
|
+
Returns the pull requests with the requested id in this repository.
|
|
86
|
+
|
|
87
|
+
:param id: int: The requested pull request id
|
|
88
|
+
|
|
89
|
+
:return: The requested PullRequest object
|
|
90
|
+
|
|
91
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D#get
|
|
92
|
+
"""
|
|
93
|
+
return self.__get_object(super(PullRequests, self).get(id))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PullRequest(BitbucketCloudBase):
|
|
97
|
+
"""
|
|
98
|
+
Bitbucket Cloud pull request endpoint
|
|
99
|
+
|
|
100
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
MERGE_COMMIT = "merge_commit"
|
|
104
|
+
MERGE_SQUASH = "squash"
|
|
105
|
+
MERGE_FF = "fast_forward"
|
|
106
|
+
MERGE_STRATEGIES = [
|
|
107
|
+
MERGE_COMMIT,
|
|
108
|
+
MERGE_SQUASH,
|
|
109
|
+
MERGE_FF,
|
|
110
|
+
]
|
|
111
|
+
STATE_OPEN = "OPEN"
|
|
112
|
+
STATE_DECLINED = "DECLINED"
|
|
113
|
+
STATE_MERGED = "MERGED"
|
|
114
|
+
STATE_SUPERSEDED = "SUPERSEDED"
|
|
115
|
+
|
|
116
|
+
def __init__(self, data, *args, **kwargs):
|
|
117
|
+
super(PullRequest, self).__init__(None, *args, data=data, expected_type="pullrequest", **kwargs)
|
|
118
|
+
|
|
119
|
+
def _check_if_open(self):
|
|
120
|
+
if not self.is_open:
|
|
121
|
+
raise Exception("Pull Request isn't open")
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def id(self):
|
|
126
|
+
"""unique pull request id"""
|
|
127
|
+
return self.get_data("id")
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def title(self):
|
|
131
|
+
"""pull request title"""
|
|
132
|
+
return self.get_data("title")
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def description(self):
|
|
136
|
+
"""pull request description"""
|
|
137
|
+
return self.get_data("description")
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def is_declined(self):
|
|
141
|
+
"""True if the pull request was declined"""
|
|
142
|
+
return self.get_data("state") == self.STATE_DECLINED
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def is_merged(self):
|
|
146
|
+
"""True if the pull request was merged"""
|
|
147
|
+
return self.get_data("state") == self.STATE_MERGED
|
|
148
|
+
|
|
149
|
+
@property
|
|
150
|
+
def is_open(self):
|
|
151
|
+
"""True if the pull request is open"""
|
|
152
|
+
return self.get_data("state") == self.STATE_OPEN
|
|
153
|
+
|
|
154
|
+
@property
|
|
155
|
+
def is_superseded(self):
|
|
156
|
+
"""True if the pull request was superseded"""
|
|
157
|
+
return self.get_data("state") == self.STATE_SUPERSEDED
|
|
158
|
+
|
|
159
|
+
@property
|
|
160
|
+
def created_on(self):
|
|
161
|
+
"""time of creation"""
|
|
162
|
+
return self.get_time("created_on")
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def updated_on(self):
|
|
166
|
+
"""time of last update"""
|
|
167
|
+
return self.get_time("updated_on")
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def close_source_branch(self):
|
|
171
|
+
"""close source branch flag"""
|
|
172
|
+
return self.get_data("close_source_branch")
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def source_branch(self):
|
|
176
|
+
"""source branch"""
|
|
177
|
+
return self.get_data("source")["branch"]["name"]
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def destination_branch(self):
|
|
181
|
+
"""destination branch"""
|
|
182
|
+
return self.get_data("destination")["branch"]["name"]
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def source_commit(self):
|
|
186
|
+
"""Source commit."""
|
|
187
|
+
return self.get_data("source")["commit"]["hash"]
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def destination_commit(self):
|
|
191
|
+
"""Destination commit."""
|
|
192
|
+
return self.get_data("destination")["commit"]["hash"]
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def comment_count(self):
|
|
196
|
+
"""number of comments"""
|
|
197
|
+
return self.get_data("comment_count")
|
|
198
|
+
|
|
199
|
+
@property
|
|
200
|
+
def task_count(self):
|
|
201
|
+
"""number of tasks"""
|
|
202
|
+
return self.get_data("task_count")
|
|
203
|
+
|
|
204
|
+
@property
|
|
205
|
+
def declined_reason(self):
|
|
206
|
+
"""reason for declining"""
|
|
207
|
+
return self.get_data("reason")
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def author(self):
|
|
211
|
+
"""User object of the author"""
|
|
212
|
+
return User(None, self.get_data("author"))
|
|
213
|
+
|
|
214
|
+
@property
|
|
215
|
+
def has_conflict(self):
|
|
216
|
+
"""Returns True if any of the changes in the PR cause conflicts."""
|
|
217
|
+
for diffstat in self.diffstat():
|
|
218
|
+
if diffstat.has_conflict:
|
|
219
|
+
return True
|
|
220
|
+
return False
|
|
221
|
+
|
|
222
|
+
def diffstat(self):
|
|
223
|
+
"""
|
|
224
|
+
Returns a generator object of diffstats
|
|
225
|
+
|
|
226
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/diffstat
|
|
227
|
+
"""
|
|
228
|
+
for diffstat in self._get_paged("diffstat"):
|
|
229
|
+
yield DiffStat(diffstat, **self._new_session_args)
|
|
230
|
+
|
|
231
|
+
return
|
|
232
|
+
|
|
233
|
+
def diff(self, encoding="utf-8"):
|
|
234
|
+
"""
|
|
235
|
+
Returns PR diff
|
|
236
|
+
|
|
237
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/diff
|
|
238
|
+
"""
|
|
239
|
+
return str(self.get("diff", not_json_response=True), encoding=encoding)
|
|
240
|
+
|
|
241
|
+
def patch(self, encoding="utf-8"):
|
|
242
|
+
"""
|
|
243
|
+
Returns PR patch
|
|
244
|
+
|
|
245
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/patch
|
|
246
|
+
"""
|
|
247
|
+
return str(self.get("patch", not_json_response=True), encoding=encoding)
|
|
248
|
+
|
|
249
|
+
def statuses(self):
|
|
250
|
+
"""
|
|
251
|
+
Returns generator object of the statuses endpoint
|
|
252
|
+
|
|
253
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/statuses
|
|
254
|
+
"""
|
|
255
|
+
return self._get_paged("statuses")
|
|
256
|
+
|
|
257
|
+
def participants(self):
|
|
258
|
+
"""Returns a generator object of participants"""
|
|
259
|
+
for participant in self.get_data("participants"):
|
|
260
|
+
yield Participant(participant, **self._new_session_args)
|
|
261
|
+
|
|
262
|
+
return
|
|
263
|
+
|
|
264
|
+
def reviewers(self):
|
|
265
|
+
"""Returns a generator object of reviewers"""
|
|
266
|
+
for reviewer in self.get_data("reviewers"):
|
|
267
|
+
yield User(None, reviewer, **self._new_session_args)
|
|
268
|
+
|
|
269
|
+
return
|
|
270
|
+
|
|
271
|
+
def builds(self):
|
|
272
|
+
"""Returns the latest Build objects for the pull request."""
|
|
273
|
+
builds = [b for b in self.statuses() if b["type"] == "build"]
|
|
274
|
+
for build in builds:
|
|
275
|
+
yield Build(build, **self._new_session_args)
|
|
276
|
+
|
|
277
|
+
return
|
|
278
|
+
|
|
279
|
+
def comments(self, q=None, sort=None):
|
|
280
|
+
"""
|
|
281
|
+
Returns generator object of the comments endpoint
|
|
282
|
+
|
|
283
|
+
:param q: string: Query string to narrow down the response.
|
|
284
|
+
:param sort: string: Name of a response property to sort results.
|
|
285
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
|
|
286
|
+
for details on filtering and sorting.
|
|
287
|
+
|
|
288
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/comments#get
|
|
289
|
+
"""
|
|
290
|
+
params = {}
|
|
291
|
+
if sort is not None:
|
|
292
|
+
params["sort"] = sort
|
|
293
|
+
if q is not None:
|
|
294
|
+
params["q"] = q
|
|
295
|
+
for comment in self._get_paged("comments", params=params):
|
|
296
|
+
yield Comment(comment, **self._new_session_args)
|
|
297
|
+
|
|
298
|
+
def comment(self, raw_message):
|
|
299
|
+
"""
|
|
300
|
+
Commenting the pull request in raw format
|
|
301
|
+
|
|
302
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/comments#post
|
|
303
|
+
"""
|
|
304
|
+
if not raw_message:
|
|
305
|
+
raise ValueError("No message set")
|
|
306
|
+
|
|
307
|
+
data = {
|
|
308
|
+
"content": {
|
|
309
|
+
"raw": raw_message,
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return self.post("comments", data)
|
|
314
|
+
|
|
315
|
+
@property
|
|
316
|
+
def commits(self):
|
|
317
|
+
"""Returns generator object for the Commits in the PullRequest"""
|
|
318
|
+
for commit in self._get_paged("commits"):
|
|
319
|
+
yield Commit(commit, **self._new_session_args)
|
|
320
|
+
|
|
321
|
+
def tasks(self):
|
|
322
|
+
"""
|
|
323
|
+
Returns generator object of the tasks endpoint
|
|
324
|
+
|
|
325
|
+
This is feature currently undocumented.
|
|
326
|
+
But confirmed by an Atlassian employee (BCLOUD-16682).
|
|
327
|
+
"""
|
|
328
|
+
for task in self._get_paged("tasks"):
|
|
329
|
+
yield Task(task, **self._new_session_args)
|
|
330
|
+
|
|
331
|
+
def add_task(self, raw_message):
|
|
332
|
+
"""
|
|
333
|
+
Adding a task to the pull request in raw format.
|
|
334
|
+
|
|
335
|
+
This is feature currently undocumented.
|
|
336
|
+
But confirmed by an Atlassian employee (BCLOUD-16682).
|
|
337
|
+
"""
|
|
338
|
+
if not raw_message:
|
|
339
|
+
raise ValueError("No message set")
|
|
340
|
+
|
|
341
|
+
data = {
|
|
342
|
+
"content": {
|
|
343
|
+
"raw": raw_message,
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return Task(self.post("tasks", data), **self._new_session_args)
|
|
348
|
+
|
|
349
|
+
def approve(self):
|
|
350
|
+
"""
|
|
351
|
+
Approve a pull request if open
|
|
352
|
+
|
|
353
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/approve#post
|
|
354
|
+
"""
|
|
355
|
+
self._check_if_open()
|
|
356
|
+
data = {"approved": True}
|
|
357
|
+
return self.post("approve", data)
|
|
358
|
+
|
|
359
|
+
def unapprove(self):
|
|
360
|
+
"""
|
|
361
|
+
Unapprove a pull request if open
|
|
362
|
+
|
|
363
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/approve#delete
|
|
364
|
+
"""
|
|
365
|
+
self._check_if_open()
|
|
366
|
+
return super(BitbucketCloudBase, self).delete("approve")
|
|
367
|
+
|
|
368
|
+
def request_changes(self):
|
|
369
|
+
"""
|
|
370
|
+
Request changes for the pull request if open
|
|
371
|
+
|
|
372
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/request-changes#post
|
|
373
|
+
"""
|
|
374
|
+
self._check_if_open()
|
|
375
|
+
data = {"request-changes": True}
|
|
376
|
+
return self.post("request-changes", data)
|
|
377
|
+
|
|
378
|
+
def unrequest_changes(self):
|
|
379
|
+
"""
|
|
380
|
+
Unrequest changes for the pull request if open
|
|
381
|
+
|
|
382
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/request-changes#delete
|
|
383
|
+
"""
|
|
384
|
+
self._check_if_open()
|
|
385
|
+
return super(BitbucketCloudBase, self).delete("request-changes")
|
|
386
|
+
|
|
387
|
+
def decline(self):
|
|
388
|
+
"""
|
|
389
|
+
Decline a pull request
|
|
390
|
+
|
|
391
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/decline
|
|
392
|
+
"""
|
|
393
|
+
self._check_if_open()
|
|
394
|
+
# decline endpoint needs data, but it's not possible to set a decline reason by api (frontend only)
|
|
395
|
+
data = {"id": self.id}
|
|
396
|
+
return self.post("decline", data)
|
|
397
|
+
|
|
398
|
+
def merge(self, merge_strategy=None, close_source_branch=None):
|
|
399
|
+
"""
|
|
400
|
+
Merges the pull request if it's open
|
|
401
|
+
:param merge_strategy: string: Merge strategy (one of PullRequest.MERGE_COMMIT, PullRequest.MERGE_SQUASH, PullRequest.MERGE_FF), if None default merge strategy will be used
|
|
402
|
+
:param close_source_branch: boolean: Close the source branch after merge, default PR option
|
|
403
|
+
|
|
404
|
+
API docs: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/merge
|
|
405
|
+
"""
|
|
406
|
+
self._check_if_open()
|
|
407
|
+
|
|
408
|
+
if merge_strategy is not None and merge_strategy not in self.MERGE_STRATEGIES:
|
|
409
|
+
raise ValueError("merge_strategy must be {}".format(self.MERGE_STRATEGIES))
|
|
410
|
+
|
|
411
|
+
data = {
|
|
412
|
+
"close_source_branch": close_source_branch or self.close_source_branch,
|
|
413
|
+
"merge_strategy": merge_strategy,
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return self.post("merge", data)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class Task(BitbucketCloudBase):
|
|
420
|
+
STATE_RESOLVED = "RESOLVED"
|
|
421
|
+
STATE_UNRESOLVED = "UNRESOLVED"
|
|
422
|
+
|
|
423
|
+
def __init__(self, data, *args, **kwargs):
|
|
424
|
+
super().__init__(None, None, *args, data=data, **kwargs)
|
|
425
|
+
|
|
426
|
+
@property
|
|
427
|
+
def id(self):
|
|
428
|
+
"""Task id."""
|
|
429
|
+
return self.get_data("id")
|
|
430
|
+
|
|
431
|
+
@property
|
|
432
|
+
def description(self):
|
|
433
|
+
"""The task description."""
|
|
434
|
+
return self.get_data("content")["raw"]
|
|
435
|
+
|
|
436
|
+
@property
|
|
437
|
+
def created_on(self):
|
|
438
|
+
"""time of creation"""
|
|
439
|
+
return self.get_time("created_on")
|
|
440
|
+
|
|
441
|
+
@property
|
|
442
|
+
def resolved_on(self):
|
|
443
|
+
"""resolve timestamp"""
|
|
444
|
+
return self.get_time("resolved_on")
|
|
445
|
+
|
|
446
|
+
@property
|
|
447
|
+
def is_resolved(self):
|
|
448
|
+
"""True if the task was already resolved."""
|
|
449
|
+
return self.get_data("state") == self.STATE_RESOLVED
|
|
450
|
+
|
|
451
|
+
@property
|
|
452
|
+
def creator(self):
|
|
453
|
+
"""User object with user information of the task creator"""
|
|
454
|
+
return User(None, self.get_data("creator"), **self._new_session_args)
|
|
455
|
+
|
|
456
|
+
@property
|
|
457
|
+
def resolved_by(self):
|
|
458
|
+
"""User object with user information of the task resolver"""
|
|
459
|
+
return User(None, self.get_data("resolved_by"), **self._new_session_args)
|
|
460
|
+
|
|
461
|
+
def update(self, raw_message):
|
|
462
|
+
"""
|
|
463
|
+
Update a task in raw format
|
|
464
|
+
|
|
465
|
+
This is feature currently undocumented.
|
|
466
|
+
"""
|
|
467
|
+
if not raw_message:
|
|
468
|
+
raise ValueError("No message set")
|
|
469
|
+
|
|
470
|
+
data = {
|
|
471
|
+
"content": {
|
|
472
|
+
"raw": raw_message,
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return self._update_data(self.put(None, data=data))
|
|
476
|
+
|
|
477
|
+
def delete(self):
|
|
478
|
+
"""
|
|
479
|
+
Delete the pullrequest task.
|
|
480
|
+
|
|
481
|
+
This is feature currently undocumented.
|
|
482
|
+
"""
|
|
483
|
+
return super(Task, self).delete(None)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
|
|
3
|
+
from ..base import BitbucketCloudBase
|
|
4
|
+
from ..common.users import User
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Refs(BitbucketCloudBase):
|
|
8
|
+
"""
|
|
9
|
+
Bitbucket Cloud Refs.
|
|
10
|
+
|
|
11
|
+
Generic base object for any type of ref list.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self, url, *args, **kwargs):
|
|
15
|
+
"""See BitbucketCloudBase."""
|
|
16
|
+
super(Refs, self).__init__(url, *args, **kwargs)
|
|
17
|
+
|
|
18
|
+
def create(
|
|
19
|
+
self,
|
|
20
|
+
name,
|
|
21
|
+
commit,
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
Creates a ref with the given target commit
|
|
25
|
+
:param name: string: name
|
|
26
|
+
:param commit: string: commit hash
|
|
27
|
+
|
|
28
|
+
:return: Ref
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
data = {"name": name, "target": {"hash": commit}}
|
|
32
|
+
|
|
33
|
+
return self._get_object(self.post(None, data))
|
|
34
|
+
|
|
35
|
+
def each(self, q=None, sort=None):
|
|
36
|
+
"""
|
|
37
|
+
Returns the list of refs in this repository.
|
|
38
|
+
|
|
39
|
+
:param q: string: Query string to narrow down the response.
|
|
40
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
41
|
+
:param sort: string: Name of a response property to sort results.
|
|
42
|
+
See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for details.
|
|
43
|
+
|
|
44
|
+
:return: A generator for the Ref objects
|
|
45
|
+
"""
|
|
46
|
+
params = {}
|
|
47
|
+
if sort is not None:
|
|
48
|
+
params["sort"] = sort
|
|
49
|
+
if q is not None:
|
|
50
|
+
params["q"] = q
|
|
51
|
+
for ref in self._get_paged(None, trailing=True, params=params):
|
|
52
|
+
yield self._get_object(super(Refs, self).get(ref.get("name")))
|
|
53
|
+
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
def get(self, name):
|
|
57
|
+
"""
|
|
58
|
+
Returns the Ref with the requested name in the repository.
|
|
59
|
+
|
|
60
|
+
:param name: string: The requested name
|
|
61
|
+
|
|
62
|
+
:return: The requested Ref object
|
|
63
|
+
"""
|
|
64
|
+
return self._get_object(super(Refs, self).get(name))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Branches(Refs):
|
|
68
|
+
"""
|
|
69
|
+
BitBucket Cloud branches endpoint.
|
|
70
|
+
|
|
71
|
+
See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-branches-get
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
def _get_object(self, data):
|
|
75
|
+
return Branch(data, **self._new_session_args)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class Tags(Refs):
|
|
79
|
+
"""
|
|
80
|
+
BitBucket Cloud tags endpoint.
|
|
81
|
+
|
|
82
|
+
See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-get
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
def _get_object(self, data):
|
|
86
|
+
return Tag(data, **self._new_session_args)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class Ref(BitbucketCloudBase):
|
|
90
|
+
"""
|
|
91
|
+
Base object for individual refs.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def name(self):
|
|
96
|
+
"""Ref name."""
|
|
97
|
+
return self.get_data("name")
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def hash(self):
|
|
101
|
+
"""Commit hash."""
|
|
102
|
+
return self.get_data("target")["hash"]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class Branch(Ref):
|
|
106
|
+
"""
|
|
107
|
+
Bitbucket Cloud branch endpoint.
|
|
108
|
+
|
|
109
|
+
See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-branches-name-get
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
def __init__(self, data, *args, **kwargs):
|
|
113
|
+
"""See BitbucketCloudBase."""
|
|
114
|
+
super(Branch, self).__init__(None, *args, data=data, expected_type="branch", **kwargs)
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def author(self):
|
|
118
|
+
"""User object of the author."""
|
|
119
|
+
return User(None, self.get_data("author"))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class Tag(Ref):
|
|
123
|
+
"""
|
|
124
|
+
Bitbucket Cloud tags endpoint.
|
|
125
|
+
|
|
126
|
+
See https://developer.atlassian.com/cloud/bitbucket/rest/api-group-refs/#api-repositories-workspace-repo-slug-refs-tags-name-get
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
def __init__(self, data, *args, **kwargs):
|
|
130
|
+
"""See BitbucketCloudBase."""
|
|
131
|
+
super(Tag, self).__init__(None, *args, data=data, expected_type="tag", **kwargs)
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def author(self):
|
|
135
|
+
"""User object of the author."""
|
|
136
|
+
return User(None, self.get_data("tagger"))
|