fix a bug for self hosted without relative path
Signed-off-by: ahmed <ahmed@planet.com>
This commit is contained in:
@@ -138,5 +138,5 @@ export function getGitLabIntegrationRelativePath(
|
||||
if (config.host !== GITLAB_HOST) {
|
||||
relativePath = new URL(config.baseUrl).pathname;
|
||||
}
|
||||
return relativePath;
|
||||
return trimEnd(relativePath, '/');
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user