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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/packages_and_registries/harbor_registry/utils.js')
-rw-r--r--app/assets/javascripts/packages_and_registries/harbor_registry/utils.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/app/assets/javascripts/packages_and_registries/harbor_registry/utils.js b/app/assets/javascripts/packages_and_registries/harbor_registry/utils.js
new file mode 100644
index 00000000000..13df303cffe
--- /dev/null
+++ b/app/assets/javascripts/packages_and_registries/harbor_registry/utils.js
@@ -0,0 +1,84 @@
+import { isFinite } from 'lodash';
+import {
+ SORT_FIELD_MAPPING,
+ TOKEN_TYPE_TAG_NAME,
+} from '~/packages_and_registries/harbor_registry/constants';
+import { FILTERED_SEARCH_TERM } from '~/packages_and_registries/shared/constants';
+import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
+
+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 */