Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « harbor_registry « packages_and_registries « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ae5957343bf47e863820cdba825d6b096f18fba (plain)
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
import { isFinite } from 'lodash';
import {
  SORT_FIELD_MAPPING,
  TOKEN_TYPE_TAG_NAME,
} from '~/packages_and_registries/harbor_registry/constants';
import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
import { FILTERED_SEARCH_TERM } from '~/vue_shared/components/filtered_search_bar/constants';

export const extractSortingDetail = (parsedSorting = '') => {
  const [orderBy, sortOrder] = parsedSorting.split('_');
  if (orderBy && sortOrder) {
    return {
      orderBy: SORT_FIELD_MAPPING[orderBy],
      sort: sortOrder.toLowerCase(),
    };
  }

  return {
    orderBy: '',
    sort: '',
  };
};

export const parseFilter = (filters = [], defaultPrefix = '') => {
  /* eslint-disable @gitlab/require-i18n-strings */
  const prefixMap = {
    [FILTERED_SEARCH_TERM]: `${defaultPrefix}=`,
    [TOKEN_TYPE_TAG_NAME]: 'tags=',
  };
  /* eslint-enable @gitlab/require-i18n-strings */
  const filterList = [];
  filters.forEach((i) => {
    if (i.value?.data) {
      const filterVal = i.value?.data;
      const prefix = prefixMap[i.type];
      const filterString = `${prefix}${filterVal}`;

      filterList.push(filterString);
    }
  });

  return filterList.join(',');
};

export const getNameFromParams = (fullName) => {
  const names = fullName.split('/');
  return {
    projectName: names[0] || '',
    imageName: names[1] || '',
  };
};

export const formatPagination = (headers) => {
  const pagination = parseIntPagination(normalizeHeaders(headers)) || {};

  if (pagination.nextPage || pagination.previousPage) {
    pagination.hasNextPage = isFinite(pagination.nextPage);
    pagination.hasPreviousPage = isFinite(pagination.previousPage);
  }

  return pagination;
};

/* eslint-disable @gitlab/require-i18n-strings */
export const dockerBuildCommand = ({ repositoryUrl, harborProjectName, projectName = '' }) => {
  return `docker build -t ${repositoryUrl}/${harborProjectName}/${projectName} .`;
};

export const dockerPushCommand = ({ repositoryUrl, harborProjectName, projectName = '' }) => {
  return `docker push ${repositoryUrl}/${harborProjectName}/${projectName}`;
};

export const dockerLoginCommand = (repositoryUrl) => {
  return `docker login ${repositoryUrl}`;
};

export const artifactPullCommand = ({ repositoryUrl, harborProjectName, imageName, digest }) => {
  return `docker pull ${repositoryUrl}/${harborProjectName}/${imageName}@${digest}`;
};

export const tagPullCommand = ({ repositoryUrl, harborProjectName, imageName, tag }) => {
  return `docker pull ${repositoryUrl}/${harborProjectName}/${imageName}:${tag}`;
};
/* eslint-enable @gitlab/require-i18n-strings */