From f0c22ebd089334ccfb8209020736fe217cf270f7 Mon Sep 17 00:00:00 2001 From: Luke Albao Date: Fri, 28 Mar 2025 15:58:58 -0700 Subject: [PATCH] [plugins/catalog-backend-module-github] Throw on invalid branch name Signed-off-by: Luke Albao --- .changeset/clear-pigs-share.md | 5 +++++ .../GithubEntityProviderConfig.test.ts | 20 +++++++++++++++++++ .../providers/GithubEntityProviderConfig.ts | 6 ++++++ 3 files changed, 31 insertions(+) create mode 100644 .changeset/clear-pigs-share.md diff --git a/.changeset/clear-pigs-share.md b/.changeset/clear-pigs-share.md new file mode 100644 index 0000000000..37925b0c10 --- /dev/null +++ b/.changeset/clear-pigs-share.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': minor +--- + +Explicitly rejects branch names containing a slash character diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts index d00cbc888c..bddb4d27cd 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts @@ -311,4 +311,24 @@ describe('readProviderConfigs', () => { expect(() => readProviderConfigs(config)).toThrow(); }); + + it('throws an error when filters.branch contains a slash', () => { + const config = new ConfigReader({ + catalog: { + providers: { + github: { + invalidBranchUser: { + organization: 'test-org', + catalogPath: '/*/catalog-info.yaml', + filters: { + branch: 'test/a', + }, + }, + }, + }, + }, + }); + + expect(() => readProviderConfigs(config)).toThrow(); + }); }); diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts index 2e2592b70a..781239978f 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts @@ -104,6 +104,12 @@ function readProviderConfig( ); } + if (branchPattern?.includes('/')) { + throw new Error( + 'Error while processing GitHub provider config. Slash characters (/) are not allowed in filters.branch', + ); + } + const schedule = config.has('schedule') ? readSchedulerServiceTaskScheduleDefinitionFromConfig( config.getConfig('schedule'),