16
16
17
17
import { MutableRefObject } from 'react'
18
18
import moment from 'moment'
19
- import { sanitizeApprovalConfigData , sanitizeUserApprovalList } from '@Shared/Helpers'
19
+ import { sanitizeApprovalConfigData , sanitizeUserApprovalList , stringComparatorBySortOrder } from '@Shared/Helpers'
20
20
import { PolicyBlockInfo , RuntimeParamsAPIResponseType , RuntimePluginVariables } from '@Shared/types'
21
21
import { get , post } from './Api'
22
22
import { GitProviderType , ROUTES } from './Constants'
@@ -42,7 +42,7 @@ import {
42
42
GlobalVariableOptionType ,
43
43
} from './Types'
44
44
import { ApiResourceType } from '../Pages'
45
- import { RefVariableType } from './CIPipeline.Types'
45
+ import { RefVariableType , VariableTypeFormat } from './CIPipeline.Types'
46
46
47
47
export const getTeamListMin = ( ) : Promise < TeamList > => {
48
48
// ignore active field
@@ -203,7 +203,7 @@ const cdMaterialListModal = ({
203
203
deploymentWindowArtifactMetadata : material . deploymentWindowArtifactMetadata ?? null ,
204
204
configuredInReleases : material . configuredInReleases ?? [ ] ,
205
205
appWorkflowId : material . appWorkflowId ?? null ,
206
- deploymentBlockedState : sanitizeDeploymentBlockedState ( material . deploymentBlockedState )
206
+ deploymentBlockedState : sanitizeDeploymentBlockedState ( material . deploymentBlockedState ) ,
207
207
}
208
208
} )
209
209
return materials
@@ -244,8 +244,37 @@ const processCDMaterialsApprovalInfo = (enableApproval: boolean, cdMaterialsResu
244
244
}
245
245
}
246
246
247
- export const parseRuntimeParams = ( response : RuntimeParamsAPIResponseType ) : RuntimePluginVariables [ ] =>
248
- ( response ?. runtimePluginVariables ?? [ ] ) . map ( ( variable ) => ( { ...variable , defaultValue : variable . value } ) )
247
+ export const parseRuntimeParams = ( response : RuntimeParamsAPIResponseType ) : RuntimePluginVariables [ ] => {
248
+ const envVariables = Object . entries ( response ?. envVariables || { } ) . map < RuntimePluginVariables > (
249
+ ( [ key , value ] ) => ( {
250
+ name : key ,
251
+ value,
252
+ defaultValue : '' ,
253
+ format : VariableTypeFormat . STRING ,
254
+ isRequired : false ,
255
+ valueType : RefVariableType . NEW ,
256
+ variableStepScope : RefVariableType . GLOBAL ,
257
+ stepName : null ,
258
+ stepType : null ,
259
+ // TODO: (Rohit/Eshank) Replace this with getUniqueId (nanoId method)
260
+ stepVariableId : Math . floor ( new Date ( ) . valueOf ( ) * Math . random ( ) ) ,
261
+ valueConstraint : null ,
262
+ description : null ,
263
+ fileReferenceId : null ,
264
+ fileMountDir : null ,
265
+ } ) ,
266
+ )
267
+
268
+ const runtimeParams = ( response ?. runtimePluginVariables ?? [ ] ) . map < RuntimePluginVariables > ( ( variable ) => ( {
269
+ ...variable ,
270
+ defaultValue : variable . value ,
271
+ } ) )
272
+
273
+ runtimeParams . push ( ...envVariables )
274
+ runtimeParams . sort ( ( a , b ) => stringComparatorBySortOrder ( a . name , b . name ) )
275
+
276
+ return runtimeParams
277
+ }
249
278
250
279
const processCDMaterialsMetaInfo = ( cdMaterialsResult ) : CDMaterialsMetaInfo => {
251
280
if ( ! cdMaterialsResult ) {
0 commit comments