Commit 06f01073 authored by Shinya Maeda's avatar Shinya Maeda

pipeline_schedule_variables model/db

parent 8bc8e01f
......@@ -176,12 +176,9 @@ module Ci
# * Lowercased
# * Anything not matching [a-z0-9-] is replaced with a -
# * Maximum length is 63 bytes
# * First/Last Character is not a hyphen
def ref_slug
ref.to_s
.downcase
.gsub(/[^a-z0-9]/, '-')[0..62]
.gsub(/(\A-+|-+\z)/, '')
slugified = ref.to_s.downcase
slugified.gsub(/[^a-z0-9]/, '-')[0..62]
end
# Variables whose value does not depend on environment
......@@ -195,8 +192,11 @@ module Ci
variables += yaml_variables
variables += user_variables
variables += project.secret_variables_for(ref).map(&:to_runner_variable)
variables += trigger_request.user_variables if trigger_request
variables += pipeline.pipeline_schedule.job_variables if pipeline.pipeline_schedule
if trigger_request
variables += trigger_request.user_variables
elsif pipeline.pipeline_schedule
variables += pipeline.pipeline_schedule.variables.map(&:to_runner_variable)
end
variables
end
......
......@@ -4,7 +4,6 @@ module Ci
include HasVariable
belongs_to :pipeline_schedule
validates :key, uniqueness: { scope: :pipeline_schedule_id }
end
end
......@@ -10,7 +10,7 @@ class CreateCiPipelineScheduleVariables < ActiveRecord::Migration
t.string :encrypted_value_iv
t.integer :pipeline_schedule_id, null: false
t.timestamps_with_timezone null: true
t.timestamps null: false
end
add_index :ci_pipeline_schedule_variables,
......
......@@ -998,17 +998,13 @@ describe Ci::Build, :models do
describe '#ref_slug' do
{
'master' => 'master',
'1-foo' => '1-foo',
'fix/1-foo' => 'fix-1-foo',
'fix-1-foo' => 'fix-1-foo',
'a' * 63 => 'a' * 63,
'a' * 64 => 'a' * 63,
'FOO' => 'foo',
'-' + 'a' * 61 + '-' => 'a' * 61,
'-' + 'a' * 62 + '-' => 'a' * 62,
'-' + 'a' * 63 + '-' => 'a' * 62,
'a' * 62 + ' ' => 'a' * 62
'master' => 'master',
'1-foo' => '1-foo',
'fix/1-foo' => 'fix-1-foo',
'fix-1-foo' => 'fix-1-foo',
'a' * 63 => 'a' * 63,
'a' * 64 => 'a' * 63,
'FOO' => 'foo'
}.each do |ref, slug|
it "transforms #{ref} to #{slug}" do
build.ref = ref
......@@ -1373,21 +1369,20 @@ describe Ci::Build, :models do
it { is_expected.to include(predefined_trigger_variable) }
end
context 'when a job was triggered by a pipeline schedule' do
let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
let!(:pipeline_schedule_variable) do
create(:ci_pipeline_schedule_variable,
key: 'SCHEDULE_VARIABLE_KEY',
pipeline_schedule: pipeline_schedule)
context 'when build was triggered by scheduled pipeline' do
let(:secret_variable) do
{ key: 'SECRET_KEY', value: 'secret_value', public: false }
end
let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
before do
pipeline_schedule.pipelines << pipeline
pipeline_schedule.reload
create(:ci_pipeline_schedule_variable,
secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule))
end
it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) }
it { is_expected.to include(secret_variable) }
end
context 'when yaml_variables are undefined' do
......
......@@ -3,6 +3,6 @@ require 'spec_helper'
describe Ci::PipelineScheduleVariable, models: true do
subject { build(:ci_pipeline_schedule_variable) }
it { is_expected.to include_module(HasVariable) }
it { is_expected.to be_kind_of(HasVariable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) }
end
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