fix a bug for self hosted without relative path

Signed-off-by: ahmed <ahmed@planet.com>
This commit is contained in:
ahmed
2022-07-07 01:32:17 +02:00
parent f0f2e4f6b0
commit e823d78d90
2 changed files with 38 additions and 7 deletions
+1 -1
View File
@@ -138,5 +138,5 @@ export function getGitLabIntegrationRelativePath(
if (config.host !== GITLAB_HOST) {
relativePath = new URL(config.baseUrl).pathname;
}
return relativePath;
return trimEnd(relativePath, '/');
}
+37 -6
View File
@@ -47,13 +47,20 @@ describe('gitlab core', () => {
baseUrl: '<ignored>',
};
const configWithSelfHosted: GitLabIntegrationConfig = {
const configSelfHosteWithRelativePath: GitLabIntegrationConfig = {
host: 'gitlab.mycompany.com',
token: '0123456789',
apiBaseUrl: '<ignored>',
baseUrl: 'https://gitlab.mycompany.com/gitlab',
};
const configSelfHostedWithoutRelativePath: GitLabIntegrationConfig = {
host: 'gitlab.mycompany.com',
token: '0123456789',
apiBaseUrl: '<ignored>',
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',