All files / modules/75-ci/components/PipelineSteps EditorSuggestionUtils.ts

100% Statements 19/19
85.53% Branches 130/152
100% Functions 5/5
100% Lines 15/15

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58              105x 105x 105x   105x 6x               105x 6x               105x 1x         1x 1x 1x   1x                   1x         1x      
/*
 * 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 { CompletionItemKind } from 'vscode-languageserver-types'
import { getConnectorListV2Promise, ConnectorResponse } from 'services/cd-ng'
import { Scope } from '@common/interfaces/SecretsInterface'
 
export const getConnectorValue = (connector?: ConnectorResponse): string =>
  `${
    connector?.connector?.orgIdentifier && connector?.connector?.projectIdentifier
      ? connector?.connector?.identifier
      : connector?.connector?.orgIdentifier
      ? `${Scope.ORG}.${connector?.connector?.identifier}`
      : `${Scope.ACCOUNT}.${connector?.connector?.identifier}`
  }`
 
export const getConnectorName = (connector?: ConnectorResponse): string =>
  `${
    connector?.connector?.orgIdentifier && connector?.connector?.projectIdentifier
      ? `${connector?.connector?.type}: ${connector?.connector?.name}`
      : connector?.connector?.orgIdentifier
      ? `${connector?.connector?.type}[Org]: ${connector?.connector?.name}`
      : `${connector?.connector?.type}[Account]: ${connector?.connector?.name}`
  }`
 
export const getConnectorSuggestions = (params: Record<string, unknown>, types?: string[]) => {
  const { accountId, projectIdentifier, orgIdentifier } = params as {
    accountId: string
    orgIdentifier: string
    projectIdentifier: string
  }
  const body: any = { filterType: 'Connector' }
  Eif (types?.length) {
    body.types = [...types]
  }
  return getConnectorListV2Promise({
    queryParams: {
      accountIdentifier: accountId,
      orgIdentifier,
      projectIdentifier,
      includeAllConnectorsAvailableAtScope: true
    },
    body
  }).then(response => {
    const data =
      response?.data?.content?.map(connector => ({
        label: getConnectorName(connector),
        insertText: getConnectorValue(connector),
        kind: CompletionItemKind.Field
      })) || []
    return data
  })
}