Here I am trying to create a review with 2 required reviewers
required=['bob', 'charlie']
review = client.reviews.create(
change,
reviewers=required,
required_reviewers=required
)
pprint(review)
This is giving me:
{'review': {'approvals': None,
'author': 'alice',
'changes': [1234567],
'commitStatus': [],
'commits': [],
'created': 1629563212,
'deployDetails': [],
'deployStatus': None,
'description': 'Testing Swarm API\n',
'groups': [],
'id': 45678,
'participants': {'alice': [], 'charlie': []},
'pending': True,
'projects': [],
'reviewerGroups': [],
'state': 'needsReview',
'stateLabel': 'Needs Review',
'testDetails': [],
'testStatus': None,
'type': 'default',
'updated': 1629563212,
'versions': []}}
Essentially, only the last person in required
is being added as a reviewer, and they are not marked as a required reviewer in the created review.
I turned on logging in the requests
library so I could inspect the POST
:
send: b'POST /api/v9/reviews HTTP/1.1\r\nHost: swarm.domain.com\r\nUser-Agent: python-requests/2.26.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 102\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic <omitted>\r\n\r\n'
send: b'change=1234567&reviewers=bob&reviewers=charlie&requiredReviewers=bob&requiredReviewers=charlie'
reply: 'HTTP/1.1 200 OK\r\n'
The parameters don't look right for an "array of strings" as described in the Swarm API docs.
change=1234567&reviewers=bob&reviewers=charlie&requiredReviewers=bob&requiredReviewers=charlie
Doing some digging, this line is doing using the data
argument to requests.request
instead of json
.
return self.swarm._request('POST', 'reviews', data=data)
See this Stack Overflow question for why json
should be used instead of data
when you are sending an array in your POST.
Information about my environment:
- Python 3.6.2 (yeah, I know... ๐คฃ)
- helix-swarm version 0.6.2
>>> print(client.get_version())
{'apiVersions': [1, 1.1, 1.2, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'version': 'SWARM/2020.1/1999242 (2020/08/20)', 'year': '2020'}