diff --git a/.changeset/silent-garlics-drum.md b/.changeset/silent-garlics-drum.md new file mode 100644 index 0000000000..64666521c8 --- /dev/null +++ b/.changeset/silent-garlics-drum.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': patch +--- + +Added option to skip forked repos diff --git a/docs/integrations/gitlab/discovery.md b/docs/integrations/gitlab/discovery.md index 45991b2cf5..4ddb0413b0 100644 --- a/docs/integrations/gitlab/discovery.md +++ b/docs/integrations/gitlab/discovery.md @@ -109,3 +109,5 @@ export default async function createPlugin( ``` If you don't want create location object if file with component definition do not exists in project, you can set the `skipReposWithoutExactFileMatch` option. That can reduce count of request to gitlab with 404 status code. + +If you don't want to create location object if the project is a fork, you can set the `skipForkedRepos` option. diff --git a/plugins/catalog-backend-module-gitlab/api-report.md b/plugins/catalog-backend-module-gitlab/api-report.md index 2596b5c99a..6620f6445f 100644 --- a/plugins/catalog-backend-module-gitlab/api-report.md +++ b/plugins/catalog-backend-module-gitlab/api-report.md @@ -40,6 +40,7 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean; + skipForkedRepos?: boolean; }, ): GitLabDiscoveryProcessor; // (undocumented) diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts index 9f2cd9b17a..c9bd4d9187 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts @@ -42,10 +42,15 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { private readonly logger: Logger; private readonly cache: CacheClient; private readonly skipReposWithoutExactFileMatch: boolean; + private readonly skipForkedRepos: boolean; static fromConfig( config: Config, - options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean }, + options: { + logger: Logger; + skipReposWithoutExactFileMatch?: boolean; + skipForkedRepos?: boolean; + }, ): GitLabDiscoveryProcessor { const integrations = ScmIntegrations.fromConfig(config); const pluginCache = @@ -63,12 +68,14 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { pluginCache: PluginCacheManager; logger: Logger; skipReposWithoutExactFileMatch?: boolean; + skipForkedRepos?: boolean; }) { this.integrations = options.integrations; this.cache = options.pluginCache.getClient(); this.logger = options.logger; this.skipReposWithoutExactFileMatch = options.skipReposWithoutExactFileMatch || false; + this.skipForkedRepos = options.skipForkedRepos || false; } getProcessorName(): string { @@ -140,6 +147,13 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { } } + if ( + this.skipForkedRepos && + project.hasOwnProperty('forked_from_project') + ) { + continue; + } + res.matches.push(project); } diff --git a/plugins/catalog-backend-module-gitlab/src/lib/types.ts b/plugins/catalog-backend-module-gitlab/src/lib/types.ts index c27007861b..341e2a9d9a 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/types.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/types.ts @@ -22,6 +22,10 @@ export type GitlabGroupDescription = { projects: GitLabProject[]; }; +export type GitlabProjectForkedFrom = { + id: number; +}; + export type GitLabProject = { id: number; default_branch?: string; @@ -29,6 +33,7 @@ export type GitLabProject = { last_activity_at: string; web_url: string; path_with_namespace?: string; + forked_from_project?: GitlabProjectForkedFrom; }; export type GitLabUser = {