diff --git a/.changeset/great-squids-deliver.md b/.changeset/great-squids-deliver.md new file mode 100644 index 0000000000..a6ad0ef87f --- /dev/null +++ b/.changeset/great-squids-deliver.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +Allow file extension `.yml` to be ingested in GitLab processor diff --git a/packages/integration/src/gitlab/core.test.ts b/packages/integration/src/gitlab/core.test.ts index f07d65e02a..4f39fb2fe7 100644 --- a/packages/integration/src/gitlab/core.test.ts +++ b/packages/integration/src/gitlab/core.test.ts @@ -47,7 +47,7 @@ describe('gitlab core', () => { baseUrl: '', }; - describe('getGitLabFileFetchUrl', () => { + describe('getGitLabFileFetchUrl with .yaml extension', () => { it.each([ // Project URLs { @@ -91,4 +91,49 @@ describe('gitlab core', () => { await expect(getGitLabFileFetchUrl(url, config)).resolves.toBe(result); }); }); + + describe('getGitLabFileFetchUrl with .yml extension', () => { + it.each([ + // Project URLs + { + config: configWithNoToken, + url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file.yml', + result: + 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%2Fto%2Ffile.yml/raw?ref=branch', + }, + { + config: configWithNoToken, + // Works with non URI encoded link + url: 'https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path/to/file with spaces.yml', + result: + 'https://gitlab.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', + result: + 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%20with%20spaces%2Fto%2Ffile.yml/raw?ref=branch', + }, + { + config: configWithToken, + url: 'https://gitlab.example.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yml', + result: + 'https://gitlab.example.com/api/v4/projects/12345/repository/files/my%2Fpath%20with%20spaces%2Fto%2Ffile.yml/raw?ref=branch', + }, + { + config: configWithNoToken, + url: 'https://gitlab.com/groupA/teams/teamA/repoA/-/blob/branch/my/path%20with%20spaces/to/file.yml', // Repo not in subgroup + result: + 'https://gitlab.com/api/v4/projects/12345/repository/files/my%2Fpath%20with%20spaces%2Fto%2Ffile.yml/raw?ref=branch', + }, + // Raw URLs + { + config: configWithNoToken, + url: 'https://gitlab.example.com/a/b/blob/master/c.yml', + result: 'https://gitlab.example.com/a/b/raw/master/c.yml', + }, + ])('should handle happy path %#', async ({ config, url, result }) => { + await expect(getGitLabFileFetchUrl(url, config)).resolves.toBe(result); + }); + }); }); diff --git a/packages/integration/src/gitlab/core.ts b/packages/integration/src/gitlab/core.ts index 83ab29c62e..b30d44e2db 100644 --- a/packages/integration/src/gitlab/core.ts +++ b/packages/integration/src/gitlab/core.ts @@ -76,7 +76,7 @@ export function buildRawUrl(target: string): URL { userOrOrg === '' || repoName === '' || blobKeyword !== 'blob' || - !restOfPath.join('/').match(/\.yaml$/) + !restOfPath.join('/').match(/\.(yaml|yml)$/) ) { throw new Error('Wrong GitLab URL'); }