Skip to content

Commit 5d9f253

Browse files
sti0gonchik
authored andcommitted
Fix missing data when using pullRequests.each() (#861)
* Delivers full data when using PRs.each() The pullrequests endpoint won't deliver the whole PullRequest object (e.g. participants, reviewers missing). So we need to load all the data for the PR object. * add fixture * make black happy * adding testcase to prove participants are accessable
1 parent 4e1d61f commit 5d9f253

File tree

3 files changed

+262
-1
lines changed

3 files changed

+262
-1
lines changed

atlassian/bitbucket/cloud/repositories/pullRequests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def each(self, q=None, sort=None):
7272
if q is not None:
7373
params["q"] = q
7474
for pr in self._get_paged(None, trailing=True, params=params):
75-
yield self.__get_object(pr)
75+
yield self.__get_object(super(PullRequests, self).get(pr.get("id")))
7676

7777
return
7878

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
responses[None] = {
2+
"rendered": {
3+
"description": {
4+
"raw": "PRDescription",
5+
"markup": "markdown",
6+
"html": "<p>PRDescription</p>",
7+
"type": "rendered",
8+
},
9+
"title": {"raw": "PRTitle", "markup": "markdown", "html": "<p>PRTitle</p>", "type": "rendered"},
10+
},
11+
"type": "pullrequest",
12+
"description": "PRDescription",
13+
"links": {
14+
"decline": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/decline"},
15+
"diffstat": {
16+
"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/diffstat/TestWorkspace1/testrepository1:16182c4698fb%0D1fbd047cd123?from_pullrequest_id=25"
17+
},
18+
"commits": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/commits"},
19+
"self": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25"},
20+
"comments": {
21+
"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/comments"
22+
},
23+
"merge": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/merge"},
24+
"html": {"href": "https://bitbucket.org/TestWorkspace1/testrepository1/pull-requests/25"},
25+
"activity": {
26+
"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/activity"
27+
},
28+
"request-changes": {
29+
"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/request-changes"
30+
},
31+
"diff": {
32+
"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/diff/TestWorkspace1/testrepository1:16182c4698fb%0D1fbd047cd123?from_pullrequest_id=25"
33+
},
34+
"approve": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/approve"},
35+
"statuses": {
36+
"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/pullrequests/25/statuses"
37+
},
38+
},
39+
"title": "PRTitle",
40+
"close_source_branch": true,
41+
"reviewers": [
42+
{
43+
"display_name": "User04DisplayName",
44+
"uuid": "{User04UUID}",
45+
"links": {
46+
"self": {"href": "users/%7BUser04UUID%7D"},
47+
"html": {"href": "https://bitbucket.org/%7BUser04UUID%7D/"},
48+
"avatar": {
49+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU4-2.png"
50+
},
51+
},
52+
"nickname": "User04Nickname",
53+
"type": "user",
54+
"account_id": "User04AccountID",
55+
},
56+
{
57+
"display_name": "User02DisplayName",
58+
"uuid": "{User02UUID}",
59+
"links": {
60+
"self": {"href": "users/%7BUser02UUID%7D"},
61+
"html": {"href": "https://bitbucket.org/%7BUser02UUID%7D/"},
62+
"avatar": {
63+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU2-3.png"
64+
},
65+
},
66+
"nickname": "User02Nickname",
67+
"type": "user",
68+
"account_id": "User02AccountID",
69+
},
70+
{
71+
"display_name": "User01DisplayName",
72+
"uuid": "{User01UUID}",
73+
"links": {
74+
"self": {"href": "users/%7BUser01UUID%7D"},
75+
"html": {"href": "https://bitbucket.org/%7BUser01UUID%7D/"},
76+
"avatar": {
77+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU1-3.png"
78+
},
79+
},
80+
"nickname": "User01Nickname",
81+
"type": "user",
82+
"account_id": "User01AccountID",
83+
},
84+
],
85+
"id": 25,
86+
"destination": {
87+
"commit": {
88+
"hash": "1fbd047cd99a",
89+
"type": "commit",
90+
"links": {
91+
"self": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/commit/1fbd047cd99a"},
92+
"html": {"href": "https://bitbucket.org/TestWorkspace1/testrepository1/commits/1fbd047cd99a"},
93+
},
94+
},
95+
"repository": {
96+
"links": {
97+
"self": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1"},
98+
"html": {"href": "https://bitbucket.org/TestWorkspace1/testrepository1"},
99+
"avatar": {"href": "https://bytebucket.org/ravatar/%7BRepoUUID%7D?ts=default"},
100+
},
101+
"type": "repository",
102+
"name": "testrepository1",
103+
"full_name": "TestWorkspace1/testrepository1",
104+
"uuid": "{RepoUUID}",
105+
},
106+
"branch": {"name": "master"},
107+
},
108+
"created_on": "2020-03-19T12:00:03.494356+00:00",
109+
"summary": {"raw": "PRDescription", "markup": "markdown", "html": "<p>PRDescription</p>", "type": "rendered"},
110+
"source": {
111+
"commit": {
112+
"hash": "16182c4123fb",
113+
"type": "commit",
114+
"links": {
115+
"self": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1/commit/16182c4123fb"},
116+
"html": {"href": "https://bitbucket.org/TestWorkspace1/testrepository1/commits/16182c4123fb"},
117+
},
118+
},
119+
"repository": {
120+
"links": {
121+
"self": {"href": "bitbucket/cloud/2.0/repositories/TestWorkspace1/testrepository1"},
122+
"html": {"href": "https://bitbucket.org/TestWorkspace1/testrepository1"},
123+
"avatar": {"href": "https://bytebucket.org/ravatar/%7BRepoUUID%7D?ts=default"},
124+
},
125+
"type": "repository",
126+
"name": "testrepository1",
127+
"full_name": "TestWorkspace1/testrepository1",
128+
"uuid": "{RepoUUID}",
129+
},
130+
"branch": {"name": "feature/test-branch"},
131+
},
132+
"comment_count": 5,
133+
"state": "OPEN",
134+
"task_count": 0,
135+
"participants": [
136+
{
137+
"participated_on": "2020-03-19T14:29:24.928709+00:00",
138+
"state": null,
139+
"role": "PARTICIPANT",
140+
"user": {
141+
"display_name": "User05DisplayName",
142+
"uuid": "{User05UUID}",
143+
"links": {
144+
"self": {"href": "users/%7BUser05UUID%7D"},
145+
"html": {"href": "https://bitbucket.org/%7BUser05UUID%7D/"},
146+
"avatar": {
147+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2U5-5.png"
148+
},
149+
},
150+
"nickname": "User05Nickname",
151+
"type": "user",
152+
"account_id": "User05AccountID",
153+
},
154+
"type": "participant",
155+
"approved": false,
156+
},
157+
{
158+
"participated_on": "2020-07-09T07:00:54.416331+00:00",
159+
"state": null,
160+
"role": "PARTICIPANT",
161+
"user": {
162+
"display_name": "User03DisplayName",
163+
"uuid": "{User03UUID}",
164+
"links": {
165+
"self": {"href": "users/%7BUser03UUID%7D"},
166+
"html": {"href": "https://bitbucket.org/%7BUser03UUID%7D/"},
167+
"avatar": {
168+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU3-0.png"
169+
},
170+
},
171+
"nickname": "User03Nickname",
172+
"type": "user",
173+
"account_id": "User03AccountID",
174+
},
175+
"type": "participant",
176+
"approved": false,
177+
},
178+
{
179+
"participated_on": "2020-12-27T14:09:14.660262+00:00",
180+
"state": "approved",
181+
"role": "REVIEWER",
182+
"user": {
183+
"display_name": "User04DisplayName",
184+
"uuid": "{User04UUID}",
185+
"links": {
186+
"self": {"href": "users/%7BUser04UUID%7D"},
187+
"html": {"href": "https://bitbucket.org/%7BUser04UUID%7D/"},
188+
"avatar": {
189+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU4-2.png"
190+
},
191+
},
192+
"nickname": "User04Nickname",
193+
"type": "user",
194+
"account_id": "User04AccountID",
195+
},
196+
"type": "participant",
197+
"approved": true,
198+
},
199+
{
200+
"participated_on": "2020-12-27T14:05:58.999476+00:00",
201+
"state": "changes_requested",
202+
"role": "REVIEWER",
203+
"user": {
204+
"display_name": "User01DisplayName",
205+
"uuid": "{User01UUID}",
206+
"links": {
207+
"self": {"href": "users/%7BUser01UUID%7D"},
208+
"html": {"href": "https://bitbucket.org/%7BUser01UUID%7D/"},
209+
"avatar": {
210+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU1-3.png"
211+
},
212+
},
213+
"nickname": "User01Nickname",
214+
"type": "user",
215+
"account_id": "User01AccountID",
216+
},
217+
"type": "participant",
218+
"approved": false,
219+
},
220+
{
221+
"participated_on": null,
222+
"state": null,
223+
"role": "REVIEWER",
224+
"user": {
225+
"display_name": "User02DisplayName",
226+
"uuid": "{User02UUID}",
227+
"links": {
228+
"self": {"href": "users/%7BUser02UUID%7D"},
229+
"html": {"href": "https://bitbucket.org/%7BUser02UUID%7D/"},
230+
"avatar": {
231+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU2-3.png"
232+
},
233+
},
234+
"nickname": "User02Nickname",
235+
"type": "user",
236+
"account_id": "User02AccountID",
237+
},
238+
"type": "participant",
239+
"approved": false,
240+
},
241+
],
242+
"reason": "",
243+
"updated_on": "2020-12-27T14:09:14.660262+00:00",
244+
"author": {
245+
"display_name": "User03DisplayName",
246+
"uuid": "{User03UUID}",
247+
"links": {
248+
"self": {"href": "users/%7BUser03UUID%7D"},
249+
"html": {"href": "https://bitbucket.org/%7BUser03UUID%7D/"},
250+
"avatar": {
251+
"href": "https://secure.gravatar.com/avatar/ad2424dafaasdssaew12232344434432?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FU3-0.png"
252+
},
253+
},
254+
"nickname": "User03Nickname",
255+
"type": "user",
256+
"account_id": "User03AccountID",
257+
},
258+
"merge_commit": null,
259+
"closed_by": null,
260+
}

tests/test_bitbucket_cloud_oo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def test_each(self, tc2):
317317
assert isinstance(prs[0], PullRequest)
318318
assert prs[0].id == 1
319319
assert prs[1].id == 25
320+
assert len(list(prs[1].participants())) == 5
320321

321322
def test_create(self, tc2):
322323
reviewers = ["{User04UUID}", "{User02UUID}", "{User01UUID}"]

0 commit comments

Comments
 (0)