All files / modules/75-cd/components/PipelineSteps/K8sServiceSpec K8sServiceSpecHelper.ts

78.26% Statements 18/23
27.27% Branches 3/11
66.67% Functions 4/6
72.22% Lines 13/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43              119x 119x   119x   119x                     119x 24x         119x         119x 353x   119x 38x   119x 121x  
/*
 * Copyright 2021 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import { get } from 'lodash-es'
import { getMultiTypeFromValue, MultiTypeInputType } from '@wings-software/uicore'
import type { PipelineInfoConfig, ServiceSpec } from 'services/cd-ng'
import { StepViewType } from '@pipeline/components/AbstractSteps/Step'
 
export const getNonRuntimeFields = (spec: { [key: string]: any } = {}, template: { [key: string]: any }): string => {
  const fields: { [key: string]: any } = {}
 
  Object.entries(spec).forEach(([key]): void => {
    if (getMultiTypeFromValue(template?.[key]) !== MultiTypeInputType.RUNTIME) {
      fields[key] = spec[key]
    }
  })
  return JSON.stringify(fields, null, 2)
}
 
export const clearRuntimeInputValue = (template: PipelineInfoConfig): PipelineInfoConfig => {
  return JSON.parse(
    JSON.stringify(template || {}).replace(/"<\+input>.?(?:allowedValues\((.*?)\)|regex\((.*?)\))?"/g, '""')
  )
}
 
export const setupMode = {
  PROPAGATE: 'PROPAGATE',
  DIFFERENT: 'DIFFERENT'
}
 
export const isFieldRuntime = (fieldPath: string, template?: ServiceSpec): boolean =>
  getMultiTypeFromValue(get(template, fieldPath)) === MultiTypeInputType.RUNTIME
 
export const isFieldFixedType = (fieldPath: string, initialValues?: ServiceSpec): boolean =>
  getMultiTypeFromValue(get(initialValues, fieldPath)) === MultiTypeInputType.FIXED
 
export const isRuntimeMode = (stepViewType?: string): boolean =>
  stepViewType === StepViewType.InputSet || stepViewType === StepViewType.DeploymentForm