From 8960902a4ea002d0a44c376f071048b0ef90053f Mon Sep 17 00:00:00 2001 From: TANGUY Antoine Date: Wed, 5 Apr 2023 11:10:17 +0200 Subject: [PATCH] fix: apply PR feedback Signed-off-by: TANGUY Antoine --- .changeset/eleven-balloons-occur.md | 4 +++- docs/integrations/github/discovery.md | 4 +++- .../src/lib/schema/compile.test.ts | 2 +- .../src/lib/util.ts | 2 +- .../src/providers/GithubEntityProvider.ts | 2 +- .../GithubEntityProviderConfig.test.ts | 24 +++++++++---------- .../providers/GithubEntityProviderConfig.ts | 9 ++++--- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.changeset/eleven-balloons-occur.md b/.changeset/eleven-balloons-occur.md index c857359aae..c55746f012 100644 --- a/.changeset/eleven-balloons-occur.md +++ b/.changeset/eleven-balloons-occur.md @@ -2,4 +2,6 @@ '@backstage/plugin-catalog-backend-module-github': patch --- -Add visibility filter on GithubEntityProvider +`GitHubEntityProvider`: Add option to configure visibility filter via `app-config.yaml`. + +Please find how to configure visibility filter config at https://backstage.io/docs/integrations/github/discovery diff --git a/docs/integrations/github/discovery.md b/docs/integrations/github/discovery.md index aed22702ac..e5acc60646 100644 --- a/docs/integrations/github/discovery.md +++ b/docs/integrations/github/discovery.md @@ -167,7 +167,7 @@ catalog: organization: 'backstage' # string catalogPath: '/catalog-info.yaml' # string filters: - visibilities: + visibility: - public - internal enterpriseProviderId: @@ -201,6 +201,8 @@ This provider supports multiple organizations via unique provider IDs. - **`exclude`** _(optional)_: An array of strings used to filter out results based on their associated GitHub topics. If configured, all repositories _except_ those with one (or more) topics(s) present in the exclusion filter will be ingested. + - **`visibility`** _(optional)_: + An array of strings used to filter results based on their visibility. Available options are `private`, `internal`, `private`. If configured (non empty), only repositories with visibility present in the filter will be ingested - **`host`** _(optional)_: The hostname of your GitHub Enterprise instance. It must match a host defined in [integrations.github](locations.md). - **`organization`**: diff --git a/packages/config-loader/src/lib/schema/compile.test.ts b/packages/config-loader/src/lib/schema/compile.test.ts index 999dabd307..02fa0be095 100644 --- a/packages/config-loader/src/lib/schema/compile.test.ts +++ b/packages/config-loader/src/lib/schema/compile.test.ts @@ -58,7 +58,7 @@ describe('compileConfigSchemas', () => { }); }); - it('should discover visibilities', () => { + it('should discover visibility', () => { const validate = compileConfigSchemas([ { path: 'a1', diff --git a/plugins/catalog-backend-module-github/src/lib/util.ts b/plugins/catalog-backend-module-github/src/lib/util.ts index 9e13814598..bb91e9dd2a 100644 --- a/plugins/catalog-backend-module-github/src/lib/util.ts +++ b/plugins/catalog-backend-module-github/src/lib/util.ts @@ -107,5 +107,5 @@ export function satisfiesVisibilityFilter( if (!visibilities.length) { return true; } - return visibilities.indexOf(visibility) > -1; + return visibilities.includes(visibility); } diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts index 011f4eab6e..bd26f2906a 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts @@ -243,7 +243,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { const repositoryFilter = this.config.filters?.repository; const topicFilters = this.config.filters?.topic; const allowForks = this.config.filters?.allowForks ?? true; - const visibilities = this.config.filters?.visibilities ?? []; + const visibilities = this.config.filters?.visibility ?? []; const matchingRepositories = repositories.filter(r => { const repoTopics: string[] = r.repositoryTopics; 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 68091db7e6..c83bfe5db1 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts @@ -84,10 +84,10 @@ describe('readProviderConfigs', () => { allowForks: false, }, }, - providerWithVisibilitiesFilter: { + providerWithVisibilityFilter: { organization: 'test-org6', filters: { - visibilities: ['public', 'internal'], + visibility: ['public', 'internal'], }, }, providerWithHost: { @@ -123,7 +123,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -141,7 +141,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -159,7 +159,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -177,7 +177,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -195,7 +195,7 @@ describe('readProviderConfigs', () => { include: ['backstage-include'], exclude: ['backstage-exclude'], }, - visibilities: undefined, + visibility: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -213,13 +213,13 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, schedule: undefined, validateLocationsExist: false, }); expect(providerConfigs[6]).toEqual({ - id: 'providerWithVisibilitiesFilter', + id: 'providerWithVisibilityFilter', organization: 'test-org6', catalogPath: '/catalog-info.yaml', host: 'github.com', @@ -231,7 +231,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: ['public', 'internal'], + visibility: ['public', 'internal'], }, schedule: undefined, validateLocationsExist: false, @@ -249,7 +249,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, validateLocationsExist: false, schedule: undefined, @@ -267,7 +267,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, - visibilities: undefined, + visibility: undefined, }, schedule: { frequency: Duration.fromISO('PT30M'), diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts index 71e1ba4bb4..296a508adf 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts @@ -33,7 +33,7 @@ export type GithubEntityProviderConfig = { branch?: string; topic?: GithubTopicFilters; allowForks?: boolean; - visibilities?: string[]; + visibility?: string[]; }; validateLocationsExist: boolean; schedule?: TaskScheduleDefinition; @@ -86,9 +86,8 @@ function readProviderConfig( const catalogPathContainsWildcard = catalogPath.includes('*'); - const visibilitiesInclude = config?.getOptionalStringArray( - 'filters.visibilities', - ); + const visibilityFilterInclude = + config?.getOptionalStringArray('filters.visibility'); if (validateLocationsExist && catalogPathContainsWildcard) { throw Error( @@ -115,7 +114,7 @@ function readProviderConfig( include: topicFilterInclude, exclude: topicFilterExclude, }, - visibilities: visibilitiesInclude, + visibility: visibilityFilterInclude, }, schedule, validateLocationsExist,