Commit 6de7a81f authored by Brandon Labuschagne's avatar Brandon Labuschagne

Merge branch '288752-registry-details-relative-url-fix' into 'master'

Fix container_registry url for relative urls

See merge request gitlab-org/gitlab!48661
parents 3ea3f960 41fc8225
import { joinPaths } from '~/lib/utils/url_utility';
export const pathGenerator = (imageDetails, ending = '?format=json') => { export const pathGenerator = (imageDetails, ending = '?format=json') => {
// this method is a temporary workaround, to be removed with graphql implementation // this method is a temporary workaround, to be removed with graphql implementation
// https://gitlab.com/gitlab-org/gitlab/-/issues/276432 // https://gitlab.com/gitlab-org/gitlab/-/issues/276432
...@@ -12,5 +14,12 @@ export const pathGenerator = (imageDetails, ending = '?format=json') => { ...@@ -12,5 +14,12 @@ export const pathGenerator = (imageDetails, ending = '?format=json') => {
return acc; return acc;
}, []) }, [])
.join('/'); .join('/');
return `/${basePath}/registry/repository/${imageDetails.id}/tags${ending}`;
return joinPaths(
window.gon.relative_url_root,
`/${basePath}`,
'/registry/repository/',
`${imageDetails.id}`,
`tags${ending}`,
);
}; };
---
title: Fix container_registry url for relative urls
merge_request: 48661
author:
type: fixed
...@@ -8,6 +8,10 @@ describe('Utils', () => { ...@@ -8,6 +8,10 @@ describe('Utils', () => {
id: 1, id: 1,
}; };
beforeEach(() => {
window.gon.relative_url_root = null;
});
it('returns the fetch url when no ending is passed', () => { it('returns the fetch url when no ending is passed', () => {
expect(pathGenerator(imageDetails)).toBe('/foo/bar/registry/repository/1/tags?format=json'); expect(pathGenerator(imageDetails)).toBe('/foo/bar/registry/repository/1/tags?format=json');
}); });
...@@ -16,7 +20,7 @@ describe('Utils', () => { ...@@ -16,7 +20,7 @@ describe('Utils', () => {
expect(pathGenerator(imageDetails, '/foo')).toBe('/foo/bar/registry/repository/1/tags/foo'); expect(pathGenerator(imageDetails, '/foo')).toBe('/foo/bar/registry/repository/1/tags/foo');
}); });
it.each` describe.each`
path | name | result path | name | result
${'foo/foo'} | ${''} | ${'/foo/foo/registry/repository/1/tags?format=json'} ${'foo/foo'} | ${''} | ${'/foo/foo/registry/repository/1/tags?format=json'}
${'foo/foo/foo'} | ${'foo'} | ${'/foo/foo/registry/repository/1/tags?format=json'} ${'foo/foo/foo'} | ${'foo'} | ${'/foo/foo/registry/repository/1/tags?format=json'}
...@@ -26,8 +30,15 @@ describe('Utils', () => { ...@@ -26,8 +30,15 @@ describe('Utils', () => {
${'foo/foo/baz/foo/bar'} | ${'foo/bar'} | ${'/foo/foo/baz/registry/repository/1/tags?format=json'} ${'foo/foo/baz/foo/bar'} | ${'foo/bar'} | ${'/foo/foo/baz/registry/repository/1/tags?format=json'}
${'baz/foo/foo'} | ${'foo'} | ${'/baz/foo/registry/repository/1/tags?format=json'} ${'baz/foo/foo'} | ${'foo'} | ${'/baz/foo/registry/repository/1/tags?format=json'}
${'baz/foo/bar'} | ${'foo'} | ${'/baz/foo/bar/registry/repository/1/tags?format=json'} ${'baz/foo/bar'} | ${'foo'} | ${'/baz/foo/bar/registry/repository/1/tags?format=json'}
`('returns the correct path when path is $path and name is $name', ({ name, path, result }) => { `('when path is $path and name is $name', ({ name, path, result }) => {
expect(pathGenerator({ id: 1, name, path })).toBe(result); it('returns the correct value', () => {
expect(pathGenerator({ id: 1, name, path })).toBe(result);
});
it('produces a correct relative url', () => {
window.gon.relative_url_root = '/gitlab';
expect(pathGenerator({ id: 1, name, path })).toBe(`/gitlab${result}`);
});
}); });
it('returns the url unchanged when imageDetails have no name', () => { it('returns the url unchanged when imageDetails have no name', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment