Ensure MergeRequestDiff is valid after creating it
In ebf16ada we introduced a SHA validator to ensure that the data provided in merge request diffs when importing, was legit. But, in #58804 (closed) we realized that, even if the
MergeRequestDiff validation fails, a default ("valid") record was added to a
MergeRequest when it was created.
"Valid" doesn't mean that the values are right, it only means that the validation process doesn't fail. For example, a "valid"
MergeRequestDiff can be a record with
commits_count set to
nil. These attributes are basic and we use them in several places assuming they are not
We should replace the
save method in
save!, and then handle that exception in all those places where it can be raised. Besides, we should check the importers, because if the
MergeRequestDiff is not valid we should abort the creation of the
MergeRequest. For example, in the Bitbucket importer we first create the
MergeRequest but, if any exception is raised, the
MergeRequest is not deleted.