I am just trying to set the labels of a GitLab merge request.
When I make this PUT request to GitLab
requests.put( https://gitlab.com/api/v4/projects/{}/merge_requests/{}".format(project_id, mr_num), {"labels":mr_new_labels}, headers={'PRIVATE-TOKEN': os.getenv("GITLAB_ACCESS_TOKEN", "")} )
,
it will work if mr_new_labels is any string or a list with 1 element - so if the request is just setting 1 label (or 0 labels, with an empty string).
Howevever, if mr_new_labels is a list with multiple elements, only the last element will be 'put' (perhaps the elements in the list are 'put' in turn and replace each other, rather than the list being put at once), so the merge request will only have 1 label.
I have tried using a POST request to do this instead, but for me a POST request with the same syntax as the PUT request, with any string or list value of mr_new_labels, ie
requests.post( https://gitlab.com/api/v4/projects/{}/merge_requests/{}".format(project_id, mr_num), {"labels":mr_new_labels}, headers={'PRIVATE-TOKEN': os.getenv("GITLAB_ACCESS_TOKEN", "")} )
, doesn't throw an error but doesn't work at all, even though wherever I have looked I have not seen any difference between the syntax of a PUT request and a POST request. So I thought that it might be to do with the GitLab API not accepting POST requests. (Should POST requests be written differently to PUT requests?)
So, I have no idea how I could possibly set 'labels' as a list with multiple values (which I know that it can be), either using PUT or POST requests. Any ideas would be much appreciated :)
Cheers, Milan
You can't PUT (or POST) a list value (as a HTTP query is just a string). However, {"labels":",".join(mr_new_labels)}
will work :)