From 66261b4ab44180c046c175e48d676fb38c992327 Mon Sep 17 00:00:00 2001 From: alessandro Date: Thu, 23 Mar 2023 16:13:34 +0100 Subject: [PATCH 1/4] feat(catalog-backend-module-gitlab): Added option to skip forked repos Signed-off-by: alessandro --- .changeset/silent-garlics-drum.md | 5 +++++ docs/integrations/gitlab/discovery.md | 2 ++ .../src/GitLabDiscoveryProcessor.ts | 9 ++++++++- plugins/catalog-backend-module-gitlab/src/lib/types.ts | 5 +++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/silent-garlics-drum.md diff --git a/.changeset/silent-garlics-drum.md b/.changeset/silent-garlics-drum.md new file mode 100644 index 0000000000..6515efbd4b --- /dev/null +++ b/.changeset/silent-garlics-drum.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': minor +--- + +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/src/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts index 9f2cd9b17a..1d6ce44176 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts @@ -42,10 +42,11 @@ 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 +64,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 +143,10 @@ 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..cc382c9a43 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 = { From a06c52c511e96fe3bb293eb6f66467588838dce9 Mon Sep 17 00:00:00 2001 From: alessandro Date: Thu, 23 Mar 2023 16:38:06 +0100 Subject: [PATCH 2/4] feat(catalog-backend-module-gitlab): lint Signed-off-by: alessandro --- .../src/GitLabDiscoveryProcessor.ts | 11 +++++++++-- .../catalog-backend-module-gitlab/src/lib/types.ts | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts index 1d6ce44176..c9bd4d9187 100644 --- a/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-gitlab/src/GitLabDiscoveryProcessor.ts @@ -46,7 +46,11 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { static fromConfig( config: Config, - options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean; skipForkedRepos?: boolean }, + options: { + logger: Logger; + skipReposWithoutExactFileMatch?: boolean; + skipForkedRepos?: boolean; + }, ): GitLabDiscoveryProcessor { const integrations = ScmIntegrations.fromConfig(config); const pluginCache = @@ -143,7 +147,10 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor { } } - if (this.skipForkedRepos && project.hasOwnProperty('forked_from_project')) { + if ( + this.skipForkedRepos && + project.hasOwnProperty('forked_from_project') + ) { continue; } diff --git a/plugins/catalog-backend-module-gitlab/src/lib/types.ts b/plugins/catalog-backend-module-gitlab/src/lib/types.ts index cc382c9a43..341e2a9d9a 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/types.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/types.ts @@ -23,8 +23,8 @@ export type GitlabGroupDescription = { }; export type GitlabProjectForkedFrom = { - id: number -} + id: number; +}; export type GitLabProject = { id: number; From b31fe8154e2596a7ef9d4c93c287a1289b027dc0 Mon Sep 17 00:00:00 2001 From: alessandro Date: Thu, 23 Mar 2023 17:16:09 +0100 Subject: [PATCH 3/4] feat(catalog-backend-module-gitlab): fixed api-report.md Signed-off-by: alessandro --- plugins/catalog-backend-module-gitlab/api-report.md | 1 + 1 file changed, 1 insertion(+) 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) From de6fc4349eab4cc715762e0b4c201ef31f1e8aa1 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 31 May 2023 17:19:21 +0200 Subject: [PATCH 4/4] Update .changeset/silent-garlics-drum.md Signed-off-by: Patrik Oldsberg --- .changeset/silent-garlics-drum.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/silent-garlics-drum.md b/.changeset/silent-garlics-drum.md index 6515efbd4b..64666521c8 100644 --- a/.changeset/silent-garlics-drum.md +++ b/.changeset/silent-garlics-drum.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-catalog-backend-module-gitlab': minor +'@backstage/plugin-catalog-backend-module-gitlab': patch --- Added option to skip forked repos