From a044efa1873c4675fab288a9d9c328c50fb10af9 Mon Sep 17 00:00:00 2001 From: Luke Albao Date: Fri, 28 Mar 2025 13:41:50 -0700 Subject: [PATCH 1/3] [docs] add branch naming caveat to github discovery integration Signed-off-by: Luke Albao --- docs/integrations/github/discovery.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/integrations/github/discovery.md b/docs/integrations/github/discovery.md index 4da7287383..e2513cdf21 100644 --- a/docs/integrations/github/discovery.md +++ b/docs/integrations/github/discovery.md @@ -152,7 +152,7 @@ If you do so, `default` will be used as provider ID. Wildcards cannot be used if the `validateLocationsExist` option is set to `true`. - **`filters`** _(optional)_: - **`branch`** _(optional)_: - String used to filter results based on the branch name. + String used to filter results based on the branch name. Branch name cannot have any slash (`/`) characters. Defaults to the default Branch of the repository. - **`repository`** _(optional)_: Regular expression used to filter results based on the repository name. From f0c22ebd089334ccfb8209020736fe217cf270f7 Mon Sep 17 00:00:00 2001 From: Luke Albao Date: Fri, 28 Mar 2025 15:58:58 -0700 Subject: [PATCH 2/3] [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'), From 5067db89108edd972f1eca06f14b54f88d9ad0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 1 Apr 2025 11:40:15 +0100 Subject: [PATCH 3/3] Update .changeset/clear-pigs-share.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/clear-pigs-share.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.changeset/clear-pigs-share.md b/.changeset/clear-pigs-share.md index 37925b0c10..a8241760c8 100644 --- a/.changeset/clear-pigs-share.md +++ b/.changeset/clear-pigs-share.md @@ -2,4 +2,8 @@ '@backstage/plugin-catalog-backend-module-github': minor --- -Explicitly rejects branch names containing a slash character +**BREAKING**: Explicitly rejects branch names containing a slash character. + +The module now rejects any configuration that contains slashes in branch names. The reason for this is that the ingestion will run into downstream problems if they were let through. If you had configuration with a slash in the branch name in `filters.branch`, your application may fail to start up. + +If you are affected by this, please move over to using branches that do not have slashes in them.