fix: apply PR feedback
Signed-off-by: TANGUY Antoine <tanguyantoine@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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`**:
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('compileConfigSchemas', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should discover visibilities', () => {
|
||||
it('should discover visibility', () => {
|
||||
const validate = compileConfigSchemas([
|
||||
{
|
||||
path: 'a1',
|
||||
|
||||
@@ -107,5 +107,5 @@ export function satisfiesVisibilityFilter(
|
||||
if (!visibilities.length) {
|
||||
return true;
|
||||
}
|
||||
return visibilities.indexOf(visibility) > -1;
|
||||
return visibilities.includes(visibility);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+12
-12
@@ -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'),
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user