Commit 8437890a authored by Jaime Martinez's avatar Jaime Martinez

Use GitRefValidator in CI releases

parent 061dec45
---
title: Remove ref validation for release yaml node
merge_request: 36256
author:
type: fixed
......@@ -42,6 +42,13 @@ module Gitlab
errors.add(:released_at, "must be a valid datetime")
end
end
validate do
next unless config[:ref]
unless Gitlab::GitRefValidator.validate(config[:ref])
errors.add(:ref, "must be a valid ref")
end
end
end
def value
......
......@@ -117,12 +117,40 @@ RSpec.describe Gitlab::Ci::Config::Entry::Release do
tag_name: 'v0.06',
description: "./release_changelog.txt",
name: "Release $CI_TAG_NAME",
ref: 'b3235930aa443112e639f941c69c578912189bdd'
ref: ref
}
end
context "when 'ref' is a full commit SHA" do
let(:ref) { 'b3235930aa443112e639f941c69c578912189bdd' }
it_behaves_like 'a valid entry'
end
context "when 'ref' is a short commit SHA" do
let(:ref) { 'b3235930'}
it_behaves_like 'a valid entry'
end
context "when 'ref' is a branch name" do
let(:ref) { 'fix/123-branch-name'}
it_behaves_like 'a valid entry'
end
context "when 'ref' is a semantic versioning tag" do
let(:ref) { 'v1.2.3'}
it_behaves_like 'a valid entry'
end
context "when 'ref' is a semantic versioning tag rc" do
let(:ref) { 'v1.2.3-rc'}
it_behaves_like 'a valid entry'
end
end
context "when value includes 'released_at' keyword" do
let(:config) do
......@@ -192,16 +220,10 @@ RSpec.describe Gitlab::Ci::Config::Entry::Release do
it_behaves_like 'reports error', 'release released at must be a valid datetime'
end
context 'when `milestones` is not an array of strings' do
let(:config) { { milestones: [1, 2, 3] } }
it_behaves_like 'reports error', 'release milestones should be an array of strings or a string'
end
context 'when `released_at` is not a valid date' do
let(:config) { { released_at: 'ABC123' } }
context 'when `ref` is not valid' do
let(:config) { { ref: 'invalid\branch' } }
it_behaves_like 'reports error', 'release released at must be a valid datetime'
it_behaves_like 'reports error', 'release ref must be a valid ref'
end
context 'when `milestones` is not an array of strings' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment