From 3756dd98feb776da7c114d3c6513186a89f4848b Mon Sep 17 00:00:00 2001 From: TANGUY Antoine Date: Sun, 26 Mar 2023 20:57:37 +0200 Subject: [PATCH 1/3] feat(catalog-backend-module-github): add visibility filter to github plugin Signed-off-by: TANGUY Antoine --- .changeset/eleven-balloons-occur.md | 5 +++ docs/integrations/github/discovery.md | 7 ++++ .../src/lib/github.test.ts | 4 +++ .../src/lib/github.ts | 2 ++ .../src/lib/util.test.ts | 12 +++++++ .../src/lib/util.ts | 10 ++++++ .../GithubDiscoveryProcessor.test.ts | 13 +++++++ .../providers/GithubEntityProvider.test.ts | 8 +++++ .../src/providers/GithubEntityProvider.ts | 11 +++++- .../GithubEntityProviderConfig.test.ts | 36 +++++++++++++++++-- .../providers/GithubEntityProviderConfig.ts | 6 ++++ 11 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 .changeset/eleven-balloons-occur.md diff --git a/.changeset/eleven-balloons-occur.md b/.changeset/eleven-balloons-occur.md new file mode 100644 index 0000000000..c857359aae --- /dev/null +++ b/.changeset/eleven-balloons-occur.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Add visibility filter on GithubEntityProvider diff --git a/docs/integrations/github/discovery.md b/docs/integrations/github/discovery.md index fb65173b28..aed22702ac 100644 --- a/docs/integrations/github/discovery.md +++ b/docs/integrations/github/discovery.md @@ -163,6 +163,13 @@ catalog: branch: 'main' # string repository: '.*' # Regex validateLocationsExist: true # optional boolean + visibilityProviderId: + organization: 'backstage' # string + catalogPath: '/catalog-info.yaml' # string + filters: + visibilities: + - public + - internal enterpriseProviderId: host: ghe.example.net organization: 'backstage' # string diff --git a/plugins/catalog-backend-module-github/src/lib/github.test.ts b/plugins/catalog-backend-module-github/src/lib/github.test.ts index 0345d4ba3e..df4565a174 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.test.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.test.ts @@ -493,6 +493,7 @@ describe('github', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'demo', @@ -508,6 +509,7 @@ describe('github', () => { id: 'acb123', text: 'some yaml', }, + visibility: 'private', }, ], pageInfo: { @@ -531,6 +533,7 @@ describe('github', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'demo', @@ -546,6 +549,7 @@ describe('github', () => { id: 'acb123', text: 'some yaml', }, + visibility: 'private', }, ], }; diff --git a/plugins/catalog-backend-module-github/src/lib/github.ts b/plugins/catalog-backend-module-github/src/lib/github.ts index 30e7bd83d4..39501e89bc 100644 --- a/plugins/catalog-backend-module-github/src/lib/github.ts +++ b/plugins/catalog-backend-module-github/src/lib/github.ts @@ -99,6 +99,7 @@ export type RepositoryResponse = { id: string; text: string; } | null; + visibility: string; }; type RepositoryTopics = { @@ -437,6 +438,7 @@ export async function getOrganizationRepositories( url isArchived isFork + visibility repositoryTopics(first: 100) { nodes { ... on RepositoryTopic { diff --git a/plugins/catalog-backend-module-github/src/lib/util.test.ts b/plugins/catalog-backend-module-github/src/lib/util.test.ts index 0de1d24bbf..656216942d 100644 --- a/plugins/catalog-backend-module-github/src/lib/util.test.ts +++ b/plugins/catalog-backend-module-github/src/lib/util.test.ts @@ -19,6 +19,7 @@ import { parseGithubOrgUrl, satisfiesTopicFilter, satisfiesForkFilter, + satisfiesVisibilityFilter, } from './util'; describe('parseGithubOrgUrl', () => { @@ -109,3 +110,14 @@ describe('satisfiesForkFilter', () => { expect(satisfiesForkFilter(true, false)).toEqual(true); }); }); + +describe('satisfiesVisibilityFilter', () => { + it('satisfies if no visibilities are given', () => { + expect(satisfiesVisibilityFilter([], 'public')).toEqual(true); + }); + + it('handles visibility presence into the visibilities filter', () => { + expect(satisfiesVisibilityFilter(['public'], 'public')).toEqual(true); + expect(satisfiesVisibilityFilter(['private'], 'public')).toEqual(false); + }); +}); diff --git a/plugins/catalog-backend-module-github/src/lib/util.ts b/plugins/catalog-backend-module-github/src/lib/util.ts index 54ee575a6c..9e13814598 100644 --- a/plugins/catalog-backend-module-github/src/lib/util.ts +++ b/plugins/catalog-backend-module-github/src/lib/util.ts @@ -99,3 +99,13 @@ export function splitTeamSlug(slug: string): [string, string] { } return [parts[0], parts[1]]; } + +export function satisfiesVisibilityFilter( + visibilities: string[], + visibility: string, +): Boolean { + if (!visibilities.length) { + return true; + } + return visibilities.indexOf(visibility) > -1; +} diff --git a/plugins/catalog-backend-module-github/src/processors/GithubDiscoveryProcessor.test.ts b/plugins/catalog-backend-module-github/src/processors/GithubDiscoveryProcessor.test.ts index f008c88dbe..7fbee87161 100644 --- a/plugins/catalog-backend-module-github/src/processors/GithubDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend-module-github/src/processors/GithubDiscoveryProcessor.test.ts @@ -155,6 +155,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'master', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'demo', @@ -166,6 +167,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, ], }); @@ -209,6 +211,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, ], }); @@ -242,6 +245,7 @@ describe('GithubDiscoveryProcessor', () => { isFork: false, defaultBranchRef: null, catalogInfoFile: null, + visibility: 'public', }, ], }); @@ -269,6 +273,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'master', }, catalogInfoFile: null, + visibility: 'public', }, ], }); @@ -305,6 +310,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'techdocs-cli', @@ -316,6 +322,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'techdocs-container', @@ -327,6 +334,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'techdocs-durp', @@ -336,6 +344,7 @@ describe('GithubDiscoveryProcessor', () => { isFork: false, defaultBranchRef: null, catalogInfoFile: null, + visibility: 'public', }, ], }); @@ -380,6 +389,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'test', @@ -391,6 +401,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'test-archived', @@ -402,6 +413,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'testxyz', @@ -413,6 +425,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, ], }); diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts index 21e6a46fbf..6540962411 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts @@ -181,6 +181,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, ], }), @@ -284,6 +285,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, ], }), @@ -364,6 +366,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, ], }), @@ -453,6 +456,7 @@ describe('GithubEntityProvider', () => { name: 'main', }, catalogInfoFile: null, + visibility: 'public', }, { name: 'another-repo', @@ -470,6 +474,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, ], }), @@ -571,6 +576,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, { name: 'test-repo-2', @@ -595,6 +601,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, { name: 'test-repo-3', @@ -616,6 +623,7 @@ describe('GithubEntityProvider', () => { id: 'abc123', text: 'some yaml', }, + visibility: 'public', }, ], }), diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts index 839f40e91a..011f4eab6e 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts @@ -40,7 +40,11 @@ import { GithubEntityProviderConfig, } from './GithubEntityProviderConfig'; import { getOrganizationRepositories } from '../lib/github'; -import { satisfiesTopicFilter, satisfiesForkFilter } from '../lib/util'; +import { + satisfiesTopicFilter, + satisfiesForkFilter, + satisfiesVisibilityFilter, +} from '../lib/util'; import { EventParams, EventSubscriber } from '@backstage/plugin-events-node'; import { PushEvent, Commit } from '@octokit/webhooks-types'; @@ -56,6 +60,7 @@ type Repository = { repositoryTopics: string[]; defaultBranchRef?: string; isCatalogInfoFilePresent: boolean; + visibility: string; }; /** @@ -221,6 +226,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { isCatalogInfoFilePresent: r.catalogInfoFile?.__typename === 'Blob' && r.catalogInfoFile.text !== '', + visibility: r.visibility, }; }); @@ -237,6 +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 matchingRepositories = repositories.filter(r => { const repoTopics: string[] = r.repositoryTopics; @@ -245,6 +252,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { (!repositoryFilter || repositoryFilter.test(r.name)) && satisfiesTopicFilter(repoTopics, topicFilters) && satisfiesForkFilter(allowForks, r.isFork) && + satisfiesVisibilityFilter(visibilities, r.visibility) && r.defaultBranchRef ); }); @@ -310,6 +318,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { // we can consider this file present because // only the catalog file will be recovered from the commits isCatalogInfoFilePresent: true, + visibility: event.repository.visibility, }; const matchingTargets = this.matchesFilters([repository]); 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 a597e9dbe0..68091db7e6 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts @@ -84,6 +84,12 @@ describe('readProviderConfigs', () => { allowForks: false, }, }, + providerWithVisibilitiesFilter: { + organization: 'test-org6', + filters: { + visibilities: ['public', 'internal'], + }, + }, providerWithHost: { organization: 'test-org1', host: 'ghe.internal.com', @@ -103,7 +109,7 @@ describe('readProviderConfigs', () => { }); const providerConfigs = readProviderConfigs(config); - expect(providerConfigs).toHaveLength(8); + expect(providerConfigs).toHaveLength(9); expect(providerConfigs[0]).toEqual({ id: 'providerOrganizationOnly', organization: 'test-org1', @@ -117,6 +123,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -134,6 +141,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -151,6 +159,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -168,6 +177,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -185,6 +195,7 @@ describe('readProviderConfigs', () => { include: ['backstage-include'], exclude: ['backstage-exclude'], }, + visibilities: undefined, }, schedule: undefined, validateLocationsExist: false, @@ -202,11 +213,30 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: undefined, }, schedule: undefined, validateLocationsExist: false, }); expect(providerConfigs[6]).toEqual({ + id: 'providerWithVisibilitiesFilter', + organization: 'test-org6', + catalogPath: '/catalog-info.yaml', + host: 'github.com', + filters: { + repository: undefined, + branch: undefined, + allowForks: true, + topic: { + include: undefined, + exclude: undefined, + }, + visibilities: ['public', 'internal'], + }, + schedule: undefined, + validateLocationsExist: false, + }); + expect(providerConfigs[7]).toEqual({ id: 'providerWithHost', organization: 'test-org1', catalogPath: '/catalog-info.yaml', @@ -219,11 +249,12 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: undefined, }, validateLocationsExist: false, schedule: undefined, }); - expect(providerConfigs[7]).toEqual({ + expect(providerConfigs[8]).toEqual({ id: 'providerWithSchedule', organization: 'test-org1', catalogPath: '/catalog-info.yaml', @@ -236,6 +267,7 @@ describe('readProviderConfigs', () => { include: undefined, exclude: undefined, }, + visibilities: 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 a79a557ebf..71e1ba4bb4 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts @@ -33,6 +33,7 @@ export type GithubEntityProviderConfig = { branch?: string; topic?: GithubTopicFilters; allowForks?: boolean; + visibilities?: string[]; }; validateLocationsExist: boolean; schedule?: TaskScheduleDefinition; @@ -85,6 +86,10 @@ function readProviderConfig( const catalogPathContainsWildcard = catalogPath.includes('*'); + const visibilitiesInclude = config?.getOptionalStringArray( + 'filters.visibilities', + ); + if (validateLocationsExist && catalogPathContainsWildcard) { throw Error( `Error while processing GitHub provider config. The catalog path ${catalogPath} contains a wildcard, which is incompatible with validation of locations existing before emitting them. Ensure that validateLocationsExist is set to false.`, @@ -110,6 +115,7 @@ function readProviderConfig( include: topicFilterInclude, exclude: topicFilterExclude, }, + visibilities: visibilitiesInclude, }, schedule, validateLocationsExist, From 8960902a4ea002d0a44c376f071048b0ef90053f Mon Sep 17 00:00:00 2001 From: TANGUY Antoine Date: Wed, 5 Apr 2023 11:10:17 +0200 Subject: [PATCH 2/3] 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, From ebd0cdaf8f1053dacf3594787f6985582351475f Mon Sep 17 00:00:00 2001 From: TANGUY Antoine Date: Wed, 5 Apr 2023 13:28:19 +0200 Subject: [PATCH 3/3] chore: refactor declaration file Signed-off-by: TANGUY Antoine --- docs/integrations/github/discovery.md | 2 +- plugins/catalog-backend-module-github/config.d.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/integrations/github/discovery.md b/docs/integrations/github/discovery.md index e5acc60646..7d637838b4 100644 --- a/docs/integrations/github/discovery.md +++ b/docs/integrations/github/discovery.md @@ -202,7 +202,7 @@ This provider supports multiple organizations via unique provider IDs. 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 + An array of strings used to filter results based on their visibility. Available options are `private`, `internal`, `public`. 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/plugins/catalog-backend-module-github/config.d.ts b/plugins/catalog-backend-module-github/config.d.ts index 37852223c1..5a699e745f 100644 --- a/plugins/catalog-backend-module-github/config.d.ts +++ b/plugins/catalog-backend-module-github/config.d.ts @@ -84,11 +84,11 @@ export interface Config { */ repository?: string; /** - * (Optional) GitHub topic-based filters. + * (Optional) Allow Forks to be evaluated. */ allowForks?: boolean; /** - * (Optional) Allow Forks to be evaluated. + * (Optional) GitHub topic-based filters. */ topic?: { /** @@ -108,6 +108,10 @@ export interface Config { */ exclude?: string[]; }; + /** + * (Optional) GitHub repository visibility filter. + */ + visibility?: Array<'private' | 'internal' | 'public'>; }; /** * (Optional) TaskScheduleDefinition for the refresh. @@ -169,6 +173,10 @@ export interface Config { */ exclude?: string[]; }; + /** + * (Optional) GitHub repository visibility filter. + */ + visibility?: Array<'private' | 'internal' | 'public'>; }; /** * (Optional) TaskScheduleDefinition for the refresh.