Commit 41abe5ea authored by pburdette's avatar pburdette

Fixed filter variables bug

Ensure we do not filter out
variables that do not contain a
value.

Changelog: fixed
parent 9028f616
......@@ -22,6 +22,7 @@ import httpStatusCodes from '~/lib/utils/http_status';
import { redirectTo } from '~/lib/utils/url_utility';
import { s__, __, n__ } from '~/locale';
import { VARIABLE_TYPE, FILE_TYPE, CONFIG_VARIABLES_TIMEOUT } from '../constants';
import filterVariables from '../utils/filter_variables';
import RefsDropdown from './refs_dropdown.vue';
const i18n = {
......@@ -281,20 +282,13 @@ export default {
},
createPipeline() {
this.submitted = true;
const filteredVariables = this.variables
.filter(({ key, value }) => key !== '' && value !== '')
.map(({ variable_type, key, value }) => ({
variable_type,
key,
secret_value: value,
}));
return axios
.post(this.pipelinesPath, {
// send shortName as fall back for query params
// https://gitlab.com/gitlab-org/gitlab/-/issues/287815
ref: this.refValue.fullName || this.refShortName,
variables_attributes: filteredVariables,
variables_attributes: filterVariables(this.variables),
})
.then(({ data }) => {
redirectTo(`${this.pipelinesPath}/${data.id}`);
......
// We need to filter out blank variables
// and filter out variables that have no key
// before sending to the API to create a pipeline.
export default (variables) => {
return variables
.filter(({ key }) => key !== '')
.map(({ variable_type, key, value }) => ({
variable_type,
key,
secret_value: value,
}));
};
---
title: Fixes bug where variables are being filtered that do not have a value but a key.
merge_request: 60538
author:
type: fixed
......@@ -43,3 +43,19 @@ export const mockError = {
export const mockBranchRefs = ['main', 'dev', 'release'];
export const mockTagRefs = ['1.0.0', '1.1.0', '1.2.0'];
export const mockVariables = [
{
uniqueId: 'var-refs/heads/master2',
variable_type: 'env_var',
key: 'var_without_value',
value: '',
},
{
uniqueId: 'var-refs/heads/master3',
variable_type: 'env_var',
key: 'var_with_value',
value: 'test_value',
},
{ uniqueId: 'var-refs/heads/master4', variable_type: 'env_var', key: '', value: '' },
];
import filterVariables from '~/pipeline_new/utils/filter_variables';
import { mockVariables } from '../mock_data';
describe('Filter variables utility function', () => {
it('filters variables that do not contain a key', () => {
const expectedVaraibles = [
{
variable_type: 'env_var',
key: 'var_without_value',
secret_value: '',
},
{
variable_type: 'env_var',
key: 'var_with_value',
secret_value: 'test_value',
},
];
expect(filterVariables(mockVariables)).toEqual(expectedVaraibles);
});
});
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