From e823d78d90fc87a94a7496b80c6623a5a43a89a2 Mon Sep 17 00:00:00 2001 From: ahmed Date: Thu, 7 Jul 2022 01:32:17 +0200 Subject: [PATCH] fix a bug for self hosted without relative path Signed-off-by: ahmed --- packages/integration/src/gitlab/config.ts | 2 +- packages/integration/src/gitlab/core.test.ts | 43 +++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/packages/integration/src/gitlab/config.ts b/packages/integration/src/gitlab/config.ts index 0e96a5e5e9..301fe46f90 100644 --- a/packages/integration/src/gitlab/config.ts +++ b/packages/integration/src/gitlab/config.ts @@ -138,5 +138,5 @@ export function getGitLabIntegrationRelativePath( if (config.host !== GITLAB_HOST) { relativePath = new URL(config.baseUrl).pathname; } - return relativePath; + return trimEnd(relativePath, '/'); } diff --git a/packages/integration/src/gitlab/core.test.ts b/packages/integration/src/gitlab/core.test.ts index d0ba87c653..d043aba55a 100644 --- a/packages/integration/src/gitlab/core.test.ts +++ b/packages/integration/src/gitlab/core.test.ts @@ -47,13 +47,20 @@ describe('gitlab core', () => { baseUrl: '', }; - const configWithSelfHosted: GitLabIntegrationConfig = { + const configSelfHosteWithRelativePath: GitLabIntegrationConfig = { host: 'gitlab.mycompany.com', token: '0123456789', apiBaseUrl: '', baseUrl: 'https://gitlab.mycompany.com/gitlab', }; + const configSelfHostedWithoutRelativePath: GitLabIntegrationConfig = { + host: 'gitlab.mycompany.com', + token: '0123456789', + apiBaseUrl: '', + baseUrl: 'https://gitlab.mycompany.com', + }; + describe('getGitLabFileFetchUrl with .yaml extension', () => { it.each([ // Project URLs @@ -64,11 +71,17 @@ describe('gitlab core', () => { 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yaml/raw?ref=branch', }, { - config: configWithSelfHosted, + config: configSelfHosteWithRelativePath, url: 'https://gitlab.mycompany.com/gitlab/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file.yaml', result: 'https://gitlab.mycompany.com/gitlab/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yaml/raw?ref=branch', }, + { + config: configSelfHostedWithoutRelativePath, + url: 'https://gitlab.mycompany.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file.yaml', + result: + 'https://gitlab.mycompany.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yaml/raw?ref=branch', + }, { config: configWithNoToken, // Works with non URI encoded link @@ -77,12 +90,17 @@ describe('gitlab core', () => { 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yaml/raw?ref=branch', }, { - config: configWithSelfHosted, + config: configSelfHosteWithRelativePath, url: 'https://gitlab.mycompany.com/gitlab/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file with spaces.yaml', result: 'https://gitlab.mycompany.com/gitlab/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yaml/raw?ref=branch', }, - + { + config: configSelfHostedWithoutRelativePath, + url: 'https://gitlab.mycompany.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file with spaces.yaml', + result: + 'https://gitlab.mycompany.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yaml/raw?ref=branch', + }, { config: configWithNoToken, url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yaml', @@ -142,11 +160,17 @@ describe('gitlab core', () => { 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yml/raw?ref=branch', }, { - config: configWithSelfHosted, + config: configSelfHosteWithRelativePath, url: 'https://gitlab.mycompany.com/gitlab/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file.yml', result: 'https://gitlab.mycompany.com/gitlab/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yml/raw?ref=branch', }, + { + config: configSelfHostedWithoutRelativePath, + url: 'https://gitlab.mycompany.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file.yml', + result: + 'https://gitlab.mycompany.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yml/raw?ref=branch', + }, { config: configWithNoToken, // Works with non URI encoded link @@ -155,12 +179,19 @@ describe('gitlab core', () => { 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yml/raw?ref=branch', }, { - config: configWithSelfHosted, + config: configSelfHosteWithRelativePath, // Works with non URI encoded link url: 'https://gitlab.mycompany.com/gitlab/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file with spaces.yml', result: 'https://gitlab.mycompany.com/gitlab/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yml/raw?ref=branch', }, + { + config: configSelfHostedWithoutRelativePath, + // Works with non URI encoded link + url: 'https://gitlab.mycompany.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file with spaces.yml', + result: + 'https://gitlab.mycompany.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile%20with%20spaces.yml/raw?ref=branch', + }, { config: configWithNoToken, url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yml',