Skip to content

Refactor Snippets::CreateService to allow multiple files

What does this MR do?

With this MR we start the process of refactoring the snippet services to accept multiple files. At the moment, the info used to commit the file to the repository is retrieved from single params like content and file_name.

In this first step, we assume a new param snippet_file can be sent to the Snippets::CreateService. This new param is an array of the following hash:

  • action
  • previous_path
  • file_path
  • content

Depending on the action set in the snippet_files param, some of the other attributes might or might not be required, or a transformation needed. That's why we introduce the SnippetInputAction model. This model can handle the validation logic by itself, instead of adding it to different services. At the moment, it has some basic validations, and we will add more in the future when we define the whole flow of information.

Because snippet_files will be an array (remember that we are going to accept multiple files) we need to build a structure with this info. Instead of adding the logic to the services, we implemented SnippetInputActionCollection to handle all the hashes as a whole and perform operations over all of them.

We need to ensure as well that, when snippet_files is present, the content and file_name params are not present. This way we can avoid confusion from users sending all information.

At the same time, and temporarily, when snippet_files are present, we need to still assign a content and file_name to the snippet because there is a presence validation (that we will remove soon). For this, we will pick the first file in the array of files.

This new param is not used yet, and we might not use it for a couple of milestones while we build other functionality.

Refs #217730 (closed)

Does this MR meet the acceptance criteria?

Conformity

Edited by 🤖 GitLab Bot 🤖

Merge request reports