Commit efebdba2 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Frontend implementation, tests, and changelog

parent 9f6dc8b2
...@@ -42,6 +42,7 @@ class Projects::VariablesController < Projects::ApplicationController ...@@ -42,6 +42,7 @@ class Projects::VariablesController < Projects::ApplicationController
private private
def project_params def project_params
params.require(:variable).permit([:id, :key, :value, :_destroy]) params.require(:variable)
.permit([:id, :key, :value, :protected, :_destroy])
end end
end end
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
= f.label :build_timeout_in_minutes, 'Timeout', class: 'label-light' = f.label :build_timeout_in_minutes, 'Timeout', class: 'label-light'
= f.number_field :build_timeout_in_minutes, class: 'form-control', min: '0' = f.number_field :build_timeout_in_minutes, class: 'form-control', min: '0'
%p.help-block %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' = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout'), target: '_blank'
%hr %hr
......
...@@ -7,4 +7,13 @@ ...@@ -7,4 +7,13 @@
.form-group .form-group
= f.label :value, "Value", class: "label-light" = f.label :value, "Value", class: "label-light"
= f.text_area :value, class: "form-control", placeholder: "PROJECT_VARIABLE" = 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" = f.submit btn_text, class: "btn btn-save"
.table-responsive.variables-table .table-responsive.variables-table
%table.table %table.table
%colgroup %colgroup
%col
%col %col
%col %col
%col{ width: 100 } %col{ width: 100 }
%thead %thead
%th Key %th Key
%th Value %th Value
%th Protected
%th %th
%tbody %tbody
- @project.variables.order_key_asc.each do |variable| - @project.variables.order_key_asc.each do |variable|
...@@ -14,6 +16,7 @@ ...@@ -14,6 +16,7 @@
%tr %tr
%td.variable-key= variable.key %td.variable-key= variable.key
%td.variable-value{ "data-value" => variable.value }****** %td.variable-value{ "data-value" => variable.value }******
%td.variable-protected= Gitlab::Utils.boolean_to_yes_no(variable.protected)
%td.variable-menu %td.variable-menu
= link_to namespace_project_variable_path(@project.namespace, @project, variable), class: "btn btn-transparent btn-variable-edit" do = link_to namespace_project_variable_path(@project.namespace, @project, variable), class: "btn btn-transparent btn-variable-edit" do
%span.sr-only %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 ...@@ -21,5 +21,13 @@ module Gitlab
nil nil
end end
def boolean_to_yes_no(bool)
if bool
'Yes'
else
'No'
end
end
end end
end end
...@@ -19,7 +19,7 @@ describe 'Project variables', js: true do ...@@ -19,7 +19,7 @@ describe 'Project variables', js: true do
end end
end end
it 'adds new variable' do it 'adds new secret variable' do
fill_in('variable_key', with: 'key') fill_in('variable_key', with: 'key')
fill_in('variable_value', with: 'key value') fill_in('variable_value', with: 'key value')
click_button('Add new variable') click_button('Add new variable')
...@@ -27,6 +27,7 @@ describe 'Project variables', js: true do ...@@ -27,6 +27,7 @@ describe 'Project variables', js: true do
expect(page).to have_content('Variables were successfully updated.') expect(page).to have_content('Variables were successfully updated.')
page.within('.variables-table') do page.within('.variables-table') do
expect(page).to have_content('key') expect(page).to have_content('key')
expect(page).to have_content('No')
end end
end end
...@@ -41,6 +42,19 @@ describe 'Project variables', js: true do ...@@ -41,6 +42,19 @@ describe 'Project variables', js: true do
end end
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 it 'reveals and hides new variable' do
fill_in('variable_key', with: 'key') fill_in('variable_key', with: 'key')
fill_in('variable_value', with: 'key value') fill_in('variable_value', with: 'key value')
...@@ -100,4 +114,32 @@ describe 'Project variables', js: true do ...@@ -100,4 +114,32 @@ describe 'Project variables', js: true do
expect(page).to have_content('Variable was successfully updated.') expect(page).to have_content('Variable was successfully updated.')
expect(project.variables.first.value).to eq('') expect(project.variables.first.value).to eq('')
end 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 end
...@@ -29,5 +29,10 @@ describe Gitlab::Utils, lib: true do ...@@ -29,5 +29,10 @@ describe Gitlab::Utils, lib: true do
expect(to_boolean('')).to be_nil expect(to_boolean('')).to be_nil
expect(to_boolean(nil)).to be_nil expect(to_boolean(nil)).to be_nil
end 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
end end
...@@ -1726,7 +1726,7 @@ describe Project, models: true do ...@@ -1726,7 +1726,7 @@ describe Project, models: true do
expect(project.secret_variables).to eq( expect(project.secret_variables).to eq(
[{ key: secret_variable.key, [{ key: secret_variable.key,
value: secret_variable.value, value: secret_variable.value,
public: false } ]) public: false }])
end end
end end
...@@ -1735,7 +1735,7 @@ describe Project, models: true do ...@@ -1735,7 +1735,7 @@ describe Project, models: true do
expect(project.protected_variables).to eq( expect(project.protected_variables).to eq(
[{ key: protected_variable.key, [{ key: protected_variable.key,
value: protected_variable.value, value: protected_variable.value,
public: false } ]) public: false }])
end end
end 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