All files / app/assets/javascripts/packages_and_registries/package_registry/components/details pypi_installation.vue

100% Statements 4/4
100% Branches 0/0
100% Functions 3/3
100% Lines 4/4

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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123                        3x                                     8x       8x     8x                                                                                                                                                                        
<script>
import { GlFormGroup, GlLink, GlSprintf } from '@gitlab/ui';
 
import { s__ } from '~/locale';
import InstallationTitle from '~/packages_and_registries/package_registry/components/details/installation_title.vue';
import {
  PERSONAL_ACCESS_TOKEN_HELP_URL,
  TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND,
  TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND,
  TRACKING_LABEL_CODE_INSTRUCTION,
  PYPI_HELP_PATH,
} from '~/packages_and_registries/package_registry/constants';
import CodeInstruction from '~/vue_shared/components/registry/code_instruction.vue';
 
export default {
  name: 'PyPiInstallation',
  components: {
    InstallationTitle,
    CodeInstruction,
    GlFormGroup,
    GlLink,
    GlSprintf,
  },
  props: {
    packageEntity: {
      type: Object,
      required: true,
    },
  },
  computed: {
    isPrivatePackage() {
      return !this.packageEntity.publicPackage;
    },
    pypiPipCommand() {
      // eslint-disable-next-line @gitlab/require-i18n-strings
      return `pip install ${this.packageEntity.name} --index-url ${this.packageEntity.pypiUrl}`;
    },
    pypiSetupCommand() {
      return `[gitlab]
repository = ${this.packageEntity.pypiSetupUrl}
username = __token__
password = <your personal access token>`;
    },
  },
  tracking: {
    TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND,
    TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND,
    TRACKING_LABEL_CODE_INSTRUCTION,
  },
  i18n: {
    tokenText: s__(`PackageRegistry|You will need a %{linkStart}personal access token%{linkEnd}.`),
    setupText: s__(
      `PackageRegistry|If you haven't already done so, you will need to add the below to your %{codeStart}.pypirc%{codeEnd} file.`,
    ),
    helpText: s__(
      'PackageRegistry|For more information on the PyPi registry, %{linkStart}see the documentation%{linkEnd}.',
    ),
  },
  links: {
    PERSONAL_ACCESS_TOKEN_HELP_URL,
    PYPI_HELP_PATH,
  },
  installOptions: [{ value: 'pypi', label: s__('PackageRegistry|Show PyPi commands') }],
};
</script>
 
<template>
  <div>
    <installation-title package-type="pypi" :options="$options.installOptions" />
 
    <gl-form-group id="installation-pip-command-group">
      <code-instruction
        id="installation-pip-command"
        :label="s__('PackageRegistry|Pip Command')"
        :instruction="pypiPipCommand"
        :copy-text="s__('PackageRegistry|Copy Pip command')"
        data-testid="pip-command"
        :tracking-action="$options.tracking.TRACKING_ACTION_COPY_PIP_INSTALL_COMMAND"
        :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
      />
      <template v-if="isPrivatePackage" #description>
        <gl-sprintf :message="$options.i18n.tokenText">
          <template #link="{ content }">
            <gl-link
              :href="$options.links.PERSONAL_ACCESS_TOKEN_HELP_URL"
              data-testid="access-token-link"
              >{{ content }}</gl-link
            >
          </template>
        </gl-sprintf>
      </template>
    </gl-form-group>
 
    <h3 class="gl-font-lg">{{ __('Registry setup') }}</h3>
    <p>
      <gl-sprintf :message="$options.i18n.setupText">
        <template #code="{ content }">
          <code>{{ content }}</code>
        </template>
      </gl-sprintf>
    </p>
 
    <code-instruction
      :instruction="pypiSetupCommand"
      :copy-text="s__('PackageRegistry|Copy .pypirc content')"
      data-testid="pypi-setup-content"
      multiline
      :tracking-action="$options.tracking.TRACKING_ACTION_COPY_PYPI_SETUP_COMMAND"
      :tracking-label="$options.tracking.TRACKING_LABEL_CODE_INSTRUCTION"
    />
    <gl-sprintf :message="$options.i18n.helpText">
      <template #link="{ content }">
        <gl-link
          :href="$options.links.PYPI_HELP_PATH"
          target="_blank"
          data-testid="pypi-docs-link"
          >{{ content }}</gl-link
        >
      </template>
    </gl-sprintf>
  </div>
</template>