BigW Consortium Gitlab

Commit efebdba2 by Lin Jen-Shin

Frontend implementation, tests, and changelog

parent 9f6dc8b2
......@@ -42,6 +42,7 @@ class Projects::VariablesController < Projects::ApplicationController
private
def project_params
params.require(:variable).permit([:id, :key, :value, :_destroy])
params.require(:variable)
.permit([:id, :key, :value, :protected, :_destroy])
end
end
......@@ -42,7 +42,7 @@
= f.label :build_timeout_in_minutes, 'Timeout', class: 'label-light'
= f.number_field :build_timeout_in_minutes, class: 'form-control', min: '0'
%p.help-block
Per job in minutes. If a job passes this threshold, it will be marked as failed.
Per job in minutes. If a job passes this threshold, it will be marked as failed
= link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout'), target: '_blank'
%hr
......
......@@ -7,4 +7,13 @@
.form-group
= f.label :value, "Value", class: "label-light"
= f.text_area :value, class: "form-control", placeholder: "PROJECT_VARIABLE"
.form-group
.checkbox
= f.label :protected do
= f.check_box :protected
%strong Protected
.help-block
This variable will be passed only to pipelines running on protected branches and tags
= link_to icon('question-circle'), help_page_path('ci/variables/README', anchor: 'protected-variables'), target: '_blank'
= f.submit btn_text, class: "btn btn-save"
......@@ -3,10 +3,12 @@
%colgroup
%col
%col
%col
%col{ width: 100 }
%thead
%th Key
%th Value
%th Protected
%th
%tbody
- @project.variables.order_key_asc.each do |variable|
......@@ -14,6 +16,7 @@
%tr
%td.variable-key= variable.key
%td.variable-value{ "data-value" => variable.value }******
%td.variable-protected= Gitlab::Utils.boolean_to_yes_no(variable.protected)
%td.variable-menu
= link_to namespace_project_variable_path(@project.namespace, @project, variable), class: "btn btn-transparent btn-variable-edit" do
%span.sr-only
......
---
title: Add protected variables which would only be passed to protected branches or
protected tags
merge_request: 11688
author:
......@@ -21,5 +21,13 @@ module Gitlab
nil
end
def boolean_to_yes_no(bool)
if bool
'Yes'
else
'No'
end
end
end
end
......@@ -19,7 +19,7 @@ describe 'Project variables', js: true do
end
end
it 'adds new variable' do
it 'adds new secret variable' do
fill_in('variable_key', with: 'key')
fill_in('variable_value', with: 'key value')
click_button('Add new variable')
......@@ -27,6 +27,7 @@ describe 'Project variables', js: true do
expect(page).to have_content('Variables were successfully updated.')
page.within('.variables-table') do
expect(page).to have_content('key')
expect(page).to have_content('No')
end
end
......@@ -41,6 +42,19 @@ describe 'Project variables', js: true do
end
end
it 'adds new protected variable' do
fill_in('variable_key', with: 'key')
fill_in('variable_value', with: 'value')
check('Protected')
click_button('Add new variable')
expect(page).to have_content('Variables were successfully updated.')
page.within('.variables-table') do
expect(page).to have_content('key')
expect(page).to have_content('Yes')
end
end
it 'reveals and hides new variable' do
fill_in('variable_key', with: 'key')
fill_in('variable_value', with: 'key value')
......@@ -100,4 +114,32 @@ describe 'Project variables', js: true do
expect(page).to have_content('Variable was successfully updated.')
expect(project.variables.first.value).to eq('')
end
it 'edits variable to be protected' do
page.within('.variables-table') do
find('.btn-variable-edit').click
end
expect(page).to have_content('Update variable')
check('Protected')
click_button('Save variable')
expect(page).to have_content('Variable was successfully updated.')
expect(project.variables.first).to be_protected
end
it 'edits variable to be unprotected' do
project.variables.first.update(protected: true)
page.within('.variables-table') do
find('.btn-variable-edit').click
end
expect(page).to have_content('Update variable')
check('Protected')
click_button('Save variable')
expect(page).to have_content('Variable was successfully updated.')
expect(project.variables.first).not_to be_protected
end
end
......@@ -29,5 +29,10 @@ describe Gitlab::Utils, lib: true do
expect(to_boolean('')).to be_nil
expect(to_boolean(nil)).to be_nil
end
it 'converts booleans to Yes or No' do
expect(boolean_to_yes_no(true)).to eq('Yes')
expect(boolean_to_yes_no(false)).to eq('No')
end
end
end
......@@ -1726,7 +1726,7 @@ describe Project, models: true do
expect(project.secret_variables).to eq(
[{ key: secret_variable.key,
value: secret_variable.value,
public: false } ])
public: false }])
end
end
......@@ -1735,7 +1735,7 @@ describe Project, models: true do
expect(project.protected_variables).to eq(
[{ key: protected_variable.key,
value: protected_variable.value,
public: false } ])
public: false }])
end
end
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