Implementation of create commit endpoint
The endpoint for creating commits is missing: https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions
I started implementing a merge request for the endpoint, but run into an issue. The problem is the actions[]
array. I have found no other place in the code base where an array in a request is more than just strings.
Say I implement an Action
type. Would that type also need a builder, to stay in line with the rest? Do I need to implement ParamValue
so I can use CommaSeparatedList
with Action
s?
This is the form Action
needs to have in the resulting request.
--form "actions[][action]=create" \
--form "actions[][file_path]=foo/bar" \
--form "actions[][content]=</path/to/local.file" \
I doesn't seem like that would be possible with just implementing ParamValue
What I could/want to do is something like:
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
let mut params = FormParams::default();
params
.push("branch", self.branch.as_ref())
.push("commit_message", self.commit_message.as_ref())
.push_opt("start_branch", self.start_branch.as_ref())
.push_opt("start_sha", self.start_sha.as_ref())
.push_opt("start_project", self.start_project.as_ref())
.push_opt("author_email", self.author_email.as_ref())
.push_opt("author_name", self.author_name.as_ref())
.push_opt("stats", self.stats)
.push_opt("force", self.force);
// I don't think this works, because the square brackets are added by serde_urlencoded.
// We do need the second pair of square brackets with the field name
for action in self.actions.iter() {
params.push("actions[][action]", action.action.as_value())
.push("actions[][file_path]", action.file_path.as_value())
.push_opt("actions[][previous_path]", action.previous_path.as_ref())
.push_opt("actions[][encoding]", action.encoding)
.push_opt("actions[][last_commit_id]", action.last_commit_id.as_ref())
.push_opt("actions[][execute_filemode]", action.execute_filemode);
}
params.into_body()
}
@ben.boeckel Do you have a preferred way or an idea on how to proceed with this? I would rather not implement a hacked together solution, that doesn't conform to the rest of the code base.