diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f5c6f49617..16d55c29dd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -51,7 +51,7 @@ yarn.lock @backstage/maintainers @backst /plugins/catalog-backend-module-aws @backstage/maintainers @backstage/reviewers @backstage/catalog-maintainers @pjungermann /plugins/catalog-backend-module-bitbucket-cloud @backstage/maintainers @backstage/reviewers @backstage/catalog-maintainers @pjungermann /plugins/catalog-backend-module-backstage-openapi @backstage/maintainers @backstage/reviewers @backstage/openapi-tooling-maintainers -/plugins/catalog-backend-module-gitea @backstage/maintainers @backstage/reviewers @vinnie-jog-on +/plugins/catalog-backend-module-gitea @backstage/maintainers @backstage/reviewers @backstage/catalog-maintainers /plugins/catalog-backend-module-msgraph @backstage/maintainers @backstage/reviewers @backstage/catalog-maintainers @pjungermann /plugins/catalog-backend-module-puppetdb @backstage/maintainers @backstage/reviewers @backstage/catalog-maintainers /plugins/catalog-graph @backstage/maintainers @backstage/reviewers @backstage/catalog-maintainers @backstage/sda-se-reviewers diff --git a/docs/integrations/gitea/discovery.md b/docs/integrations/gitea/discovery.md index c01ea52edf..6cae169b58 100644 --- a/docs/integrations/gitea/discovery.md +++ b/docs/integrations/gitea/discovery.md @@ -2,14 +2,9 @@ id: discovery title: Gitea Discovery sidebar_label: Discovery -# prettier-ignore description: Automatically discovering catalog entities from Gitea repositories --- -:::info -This documentation is written for [the new backend system](../../backend-system/index.md) which is the default since Backstage [version 1.24](../../releases/v1.24.0.md). -::: - The Gitea integration has a special entity provider for discovering catalog entities from Gitea repositories. The provider uses the "List Projects" API in Gitea to get a list of repositories and will automatically ingest all `catalog-info.yaml` files diff --git a/plugins/catalog-backend-module-gitea/config.d.ts b/plugins/catalog-backend-module-gitea/config.d.ts new file mode 100644 index 0000000000..bbb1a0ee4f --- /dev/null +++ b/plugins/catalog-backend-module-gitea/config.d.ts @@ -0,0 +1,58 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { SchedulerServiceTaskScheduleDefinition } from '@backstage/backend-plugin-api'; + +export interface Config { + catalog?: { + /** + * List of provider-specific options and attributes + */ + providers?: { + /** + * GiteaEntityProvider configuration + * + * Maps provider id with configuration. + */ + gitea?: { + [name: string]: { + /** + * (Required) The host of the Gitea integration to use. + */ + host: string; + /** + * (Required) Name of your organization account/workspace. + */ + organization: string; + /** + * (Optional) Branch. + * The branch where the provider will try to find entities. Uses the default to "main". + */ + branch?: string; + /** + * (Optional) Path where the catalog YAML manifest file is expected in the repository. + * Defaults to "catalog-info.yaml". + */ + catalogPath?: string; + /** + * (Optional) TaskScheduleDefinition for the discovery. + */ + schedule?: SchedulerServiceTaskScheduleDefinition; + }; + }; + }; + }; +} diff --git a/plugins/catalog-backend-module-gitea/package.json b/plugins/catalog-backend-module-gitea/package.json index fbba66a039..b35f0b6b77 100644 --- a/plugins/catalog-backend-module-gitea/package.json +++ b/plugins/catalog-backend-module-gitea/package.json @@ -1,8 +1,7 @@ { "name": "@backstage/plugin-catalog-backend-module-gitea", - "version": "0.1.0", + "version": "0.0.0", "license": "Apache-2.0", - "private": true, "description": "The gitea backend module for the catalog plugin.", "main": "src/index.ts", "types": "src/index.ts", @@ -41,7 +40,6 @@ "uuid": "^11.0.0" }, "devDependencies": { - "@backstage/backend-common": "^0.25.0", "@backstage/backend-test-utils": "workspace:^", "@backstage/cli": "workspace:^" }, diff --git a/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.test.ts b/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.test.ts index c17b3bc20e..d6a31899f1 100644 --- a/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.test.ts +++ b/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.test.ts @@ -13,8 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { getVoidLogger } from '@backstage/backend-common'; -import { LoggerService } from '@backstage/backend-plugin-api'; +import { mockServices } from '@backstage/backend-test-utils'; import { ConfigReader } from '@backstage/config'; import { EntityProviderConnection } from '@backstage/plugin-catalog-node'; import { GiteaEntityProvider } from './GiteaEntityProvider'; @@ -28,7 +27,8 @@ jest.mock('./core'); jest.mock('uuid'); describe('GiteaEntityProvider', () => { - const logger = getVoidLogger() as unknown as LoggerService; + const logger = mockServices.logger.mock(); + const mockScheduler = { createScheduledTaskRunner: jest.fn(), triggerTask: jest.fn(), @@ -285,66 +285,6 @@ describe('GiteaEntityProvider', () => { fn: expect.any(Function), }); }); - - it('should run the scheduled refresh function', async () => { - await provider.connect(mockConnection); - - // Extract and call the scheduled function - const runArgument = mockTaskRunner.run.mock.calls[0][0]; - const refreshFn = runArgument.fn; - - // Mock the refresh behavior - (global.fetch as jest.Mock).mockImplementation(async (url: string) => { - if (url.includes('/orgs/test-org/repos')) { - if (url.includes('page=1')) { - return { - ok: true, - json: async () => [ - { - name: 'repo1', - html_url: 'https://gitea.example.com/test-org/repo1', - empty: false, - }, - { - name: 'repo2', - html_url: 'https://gitea.example.com/test-org/repo2', - empty: false, - }, - ], - }; - } - return { - ok: true, - json: async () => [], - }; - } else if (url.includes('/contents/catalog-info.yaml')) { - if (url.includes('repo1')) { - return { ok: true }; - } - } - return { ok: false }; - }); - - const abortController = new AbortController(); - await refreshFn(abortController.signal); - - expect(mockConnection.applyMutation).toHaveBeenCalledWith({ - type: 'full', - entities: [ - { - locationKey: 'gitea-provider:test-provider', - entity: expect.objectContaining({ - metadata: expect.objectContaining({ - annotations: expect.objectContaining({ - 'backstage.io/managed-by-location': - 'url:https://gitea.example.com/test-org/repo1/src/branch/main/catalog-info.yaml', - }), - }), - }), - }, - ], - }); - }); }); describe('refresh', () => { diff --git a/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.ts b/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.ts index 7097edf2ca..2f9475af26 100644 --- a/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.ts +++ b/plugins/catalog-backend-module-gitea/src/providers/GiteaEntityProvider.ts @@ -164,7 +164,7 @@ export class GiteaEntityProvider implements EntityProvider { let allRepos: any[] = []; try { - // Step 1: Fetch all repos for an organization + // Fetch all repos for an organization const OrgRepoApiUrl = `${getGiteaApiUrl(this.integration.config)}orgs/${ this.config.organization }/repos`; @@ -201,7 +201,7 @@ export class GiteaEntityProvider implements EntityProvider { ); } - // Step 2: Filter for repos that have catalog-info.yaml at root + // Filter for repos that have catalog-info.yaml at root const { default: pLimit } = await import('p-limit'); const limit = pLimit(5); const validRepos: string[] = []; @@ -234,11 +234,11 @@ export class GiteaEntityProvider implements EntityProvider { }), ), ); - // Step 3: create location specs for each valid repo + // Create location specs for each valid repo const locations = await Promise.all( validRepos.map(repo => limit(() => this.createLocationSpec(repo))), ); - // Step 4: Apply the locations to the catalog + // Apply the locations to the catalog try { const providerName: string = this.getProviderName(); const entities = locations.map(location => ({ diff --git a/yarn.lock b/yarn.lock index 6fa02a3a52..8ed49c2325 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5946,7 +5946,6 @@ __metadata: version: 0.0.0-use.local resolution: "@backstage/plugin-catalog-backend-module-gitea@workspace:plugins/catalog-backend-module-gitea" dependencies: - "@backstage/backend-common": "npm:^0.25.0" "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" "@backstage/cli": "workspace:^"