gitlabr
gitlabr copied to clipboard
Fix handling of HTTP parameter arrays
This commit fixes a bug in gitlab that prevents passing arrays of arguments to the GitLab API.
In particular, prior to this PR, attempting to pass an array of parameters to gitlab, as in e.g.:
gitlab("projects", name = "foo", path = "test/foo", topics = c("topic a", "topic b"), verb = httr::POST)
… would result in the following serialisation (using JSON here, but the same is true for form-encoded):
{"name": "foo", "path": "test/foo", "topics1": "topic a", "topics2": "topic b"}
But the GitLab API would expect an actual JSON array, and would not recognise the topics array in the above. With this PR, the data is sent correctly as
{"name": "foo", "path": "test/foo", "topics": ["topic a", "topic b"]}
The reason for this is due to the way that c(...) flattens named parameters. To avoid flattening, use list(...).