150f7c1e9c
In ebf16ada85
we introduced a SHA validator, to ensure that the data provided in
merge request diffs, was legit. Nevertheless, the validator
assumed that the SHA should be 40 chars long.
When we import a project from BitBucket, the retrieved SHA is
shorter (12 chars long). Therefore, this validator prevented to
create a valid MergeRequestDiff for ever MergeRequest (triggering
an exception).
9 lines
247 B
Ruby
9 lines
247 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ShaValidator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
return if value.blank? || Commit.valid_hash?(value)
|
|
|
|
record.errors.add(attribute, 'is not a valid SHA')
|
|
end
|
|
end
|