@backstage/plugin-catalog-backend-module-gitea 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-gitea
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/plugin-catalog-node@1.18.0
|
|
9
|
+
- @backstage/backend-plugin-api@1.4.2
|
|
10
|
+
|
|
11
|
+
## 0.1.3-next.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
- @backstage/plugin-catalog-node@1.18.0-next.0
|
|
17
|
+
- @backstage/backend-plugin-api@1.4.2-next.0
|
|
18
|
+
- @backstage/config@1.3.3
|
|
19
|
+
- @backstage/errors@1.2.7
|
|
20
|
+
- @backstage/integration@1.17.1
|
|
21
|
+
- @backstage/plugin-catalog-common@1.1.5
|
|
22
|
+
|
|
3
23
|
## 0.1.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/module.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\n\nimport { GiteaEntityProvider } from './providers/GiteaEntityProvider';\n/**\n * @public\n */\nexport const catalogModuleGitea = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'gitea',\n register(reg) {\n reg.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n\n async init({ catalog, config, logger, scheduler }) {\n const providers = GiteaEntityProvider.fromConfig(config, {\n logger,\n scheduler,\n });\n catalog.addEntityProvider(providers);\n },\n });\n },\n});\n"],"names":["createBackendModule","catalogProcessingExtensionPoint","coreServices","GiteaEntityProvider"],"mappings":";;;;;;AAyBO,MAAM,qBAAqBA,
|
|
1
|
+
{"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\n\nimport { GiteaEntityProvider } from './providers/GiteaEntityProvider';\n/**\n * @public\n */\nexport const catalogModuleGitea = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'gitea',\n register(reg) {\n reg.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n\n async init({ catalog, config, logger, scheduler }) {\n const providers = GiteaEntityProvider.fromConfig(config, {\n logger,\n scheduler,\n });\n catalog.addEntityProvider(providers);\n },\n });\n },\n});\n"],"names":["createBackendModule","catalogProcessingExtensionPoint","coreServices","GiteaEntityProvider"],"mappings":";;;;;;AAyBO,MAAM,qBAAqBA,oCAAA,CAAoB;AAAA,EACpD,QAAA,EAAU,SAAA;AAAA,EACV,QAAA,EAAU,OAAA;AAAA,EACV,SAAS,GAAA,EAAK;AACZ,IAAA,GAAA,CAAI,YAAA,CAAa;AAAA,MACf,IAAA,EAAM;AAAA,QACJ,OAAA,EAASC,qCAAA;AAAA,QACT,QAAQC,6BAAA,CAAa,UAAA;AAAA,QACrB,QAAQA,6BAAA,CAAa,MAAA;AAAA,QACrB,WAAWA,6BAAA,CAAa;AAAA,OAC1B;AAAA,MAEA,MAAM,IAAA,CAAK,EAAE,SAAS,MAAA,EAAQ,MAAA,EAAQ,WAAU,EAAG;AACjD,QAAA,MAAM,SAAA,GAAYC,uCAAA,CAAoB,UAAA,CAAW,MAAA,EAAQ;AAAA,UACvD,MAAA;AAAA,UACA;AAAA,SACD,CAAA;AACD,QAAA,OAAA,CAAQ,kBAAkB,SAAS,CAAA;AAAA,MACrC;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GiteaEntityProvider.cjs.js","sources":["../../src/providers/GiteaEntityProvider.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as uuid from 'uuid';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport {\n EntityProvider,\n EntityProviderConnection,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-node';\nimport { LocationSpec } from '@backstage/plugin-catalog-common';\nimport {\n GiteaIntegration,\n getGiteaRequestOptions,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { getGiteaApiUrl } from './core';\n\nimport { readGiteaConfigs } from './config';\nimport { GiteaProjectQueryResult, GiteaProviderConfig } from './types';\nimport {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskRunner,\n} from '@backstage/backend-plugin-api';\n\n/** @public */\nexport class GiteaEntityProvider implements EntityProvider {\n private readonly config: GiteaProviderConfig;\n private readonly integration: GiteaIntegration;\n private readonly logger: LoggerService;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n configRoot: Config,\n options: {\n logger: LoggerService;\n schedule?: SchedulerServiceTaskRunner;\n scheduler?: SchedulerService;\n },\n ): GiteaEntityProvider[] {\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n const providerConfigs = readGiteaConfigs(configRoot);\n const integrations = ScmIntegrations.fromConfig(configRoot).gitea;\n const providers: GiteaEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n if (!integration) {\n throw new InputError(\n `No Gitea integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for Gitea-provider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GiteaEntityProvider(\n providerConfig,\n integration,\n options.logger,\n taskRunner,\n ),\n );\n });\n\n return providers;\n }\n\n private constructor(\n config: GiteaProviderConfig,\n integration: GiteaIntegration,\n logger: LoggerService,\n taskRunner: SchedulerServiceTaskRunner,\n ) {\n this.config = config;\n this.integration = integration;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\n }\n\n getProviderName(): string {\n return `gitea-provider:${this.config.id}`;\n }\n\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n private async parseGiteaJsonResponse(\n response: Response,\n ): Promise<GiteaProjectQueryResult> {\n if (!response.ok) {\n throw new Error(\n `Failed to fetch Gitea repositories, status: ${response.status}`,\n );\n }\n try {\n return await response.json();\n } catch (error) {\n throw new Error(`Failed to parse Gitea API response: ${error}`);\n }\n }\n\n private createScheduleFn(\n taskRunner: SchedulerServiceTaskRunner,\n ): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:refresh`;\n return taskRunner.run({\n id: taskId,\n fn: async () => {\n const logger = this.logger.child({\n class: GiteaEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(\n `${this.getProviderName()} refresh failed, ${error}`,\n error as Error,\n );\n }\n },\n });\n };\n }\n\n async refresh(logger: LoggerService): Promise<void> {\n if (!this.connection) {\n throw new Error('Gitea discovery connection not initialized');\n }\n let allRepos: any[] = [];\n\n try {\n // Fetch all repos for an organization\n const OrgRepoApiUrl = `${getGiteaApiUrl(this.integration.config)}orgs/${\n this.config.organization\n }/repos`;\n let page = 1;\n let hasMoreData = true;\n\n while (hasMoreData) {\n const url = `${OrgRepoApiUrl}?page=${page}`;\n const response = await fetch(url, {\n method: 'GET',\n ...getGiteaRequestOptions(this.integration.config),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch page ${page} of repos, status: ${response.status}`,\n );\n }\n\n const projectsPage = (await this.parseGiteaJsonResponse(\n response,\n )) as GiteaProjectQueryResult;\n\n if (!Array.isArray(projectsPage) || projectsPage.length === 0) {\n hasMoreData = false;\n } else {\n allRepos = allRepos.concat(projectsPage);\n page++;\n }\n }\n } catch (e) {\n throw new Error(\n `Failed to list Gitea projects for organization ${this.config.organization}, ${e}`,\n );\n }\n\n // Filter for repos that have catalog-info.yaml at root\n const { default: pLimit } = await import('p-limit');\n const limit = pLimit(5);\n const validRepos: string[] = [];\n\n await Promise.all(\n allRepos.map(repo =>\n limit(async () => {\n if (repo.empty) {\n logger.warn(`Repo ${repo.html_url} is empty, skipping`);\n return;\n }\n const contentsApiUrl = `${getGiteaApiUrl(\n this.integration.config,\n )}repos/${this.config.organization}/${repo.name}/contents/${\n this.config.catalogPath\n }`;\n\n const res = await fetch(contentsApiUrl, {\n method: 'GET',\n ...getGiteaRequestOptions(this.integration.config),\n });\n if (res.ok) {\n validRepos.push(repo.html_url);\n } else {\n logger.warn(\n `Repo ${repo.html_url} does not contain a catalog-info.yaml file`,\n );\n return;\n }\n }),\n ),\n );\n // Create location specs for each valid repo\n const locations = await Promise.all(\n validRepos.map(repo => limit(() => this.createLocationSpec(repo))),\n );\n // Apply the locations to the catalog\n try {\n const providerName: string = this.getProviderName();\n const entities = locations.map(location => ({\n locationKey: providerName,\n entity: locationSpecToLocationEntity({ location }),\n }));\n await this.connection.applyMutation({\n type: 'full',\n entities: entities,\n });\n } catch (e) {\n logger.error(`Failed to apply mutation: ${e}`);\n }\n logger.info(\n `Found ${locations.length} locations from ${allRepos.length} repos`,\n );\n }\n\n private async createLocationSpec(repo: string): Promise<LocationSpec> {\n return {\n type: 'url',\n target: `${repo}/src/branch/${this.config.branch}/${this.config.catalogPath}`,\n };\n }\n}\n"],"names":["readGiteaConfigs","ScmIntegrations","InputError","uuid","getGiteaApiUrl","getGiteaRequestOptions","locationSpecToLocationEntity"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,mBAA8C,CAAA;AAAA,EACxC,MAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACT,UAAA;AAAA,EAER,OAAO,UACL,CAAA,UAAA,EACA,OAKuB,EAAA;AACvB,IAAA,IAAI,CAAC,OAAA,CAAQ,QAAY,IAAA,CAAC,QAAQ,SAAW,EAAA;AAC3C,MAAM,MAAA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ACA,YAAA;AAAA;AACF,SACD;AAAA;AACH,KACF;AAEA,IAAM,MAAA,SAAA,GAAY,MAAM,OAAQ,CAAA,GAAA;AAAA,MAC9B,UAAA,CAAW,IAAI,CAAQ,IAAA,KAAA,KAAA,CAAM,MAAM,IAAK,CAAA,kBAAA,CAAmB,IAAI,CAAC,CAAC;AAAA,KACnE;AAEA,IAAI,IAAA;AACF,MAAM,MAAA,YAAA,GAAuB,KAAK,eAAgB,EAAA;AAClD,MAAM,MAAA,QAAA,GAAW,SAAU,CAAA,GAAA,CAAI,CAAa,QAAA,MAAA;AAAA,QAC1C,WAAa,EAAA,YAAA;AAAA,QACb,MAAQ,EAAAC,8CAAA,CAA6B,EAAE,QAAA,EAAU;AAAA,OACjD,CAAA,CAAA;AACF,MAAM,MAAA,IAAA,CAAK,WAAW,aAAc,CAAA;AAAA,QAClC,IAAM,EAAA,MAAA;AAAA,QACN;AAAA,OACD,CAAA;AAAA,aACM,CAAG,EAAA;AACV,MAAO,MAAA,CAAA,KAAA,CAAM,CAA6B,0BAAA,EAAA,CAAC,CAAE,CAAA,CAAA;AAAA;AAE/C,IAAO,MAAA,CAAA,IAAA;AAAA,MACL,CAAS,MAAA,EAAA,SAAA,CAAU,MAAM,CAAA,gBAAA,EAAmB,SAAS,MAAM,CAAA,MAAA;AAAA,KAC7D;AAAA;AACF,EAEA,MAAc,mBAAmB,IAAqC,EAAA;AACpE,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,KAAA;AAAA,MACN,MAAA,EAAQ,CAAG,EAAA,IAAI,CAAe,YAAA,EAAA,IAAA,CAAK,OAAO,MAAM,CAAA,CAAA,EAAI,IAAK,CAAA,MAAA,CAAO,WAAW,CAAA;AAAA,KAC7E;AAAA;AAEJ;;;;"}
|
|
1
|
+
{"version":3,"file":"GiteaEntityProvider.cjs.js","sources":["../../src/providers/GiteaEntityProvider.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as uuid from 'uuid';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport {\n EntityProvider,\n EntityProviderConnection,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-node';\nimport { LocationSpec } from '@backstage/plugin-catalog-common';\nimport {\n GiteaIntegration,\n getGiteaRequestOptions,\n ScmIntegrations,\n} from '@backstage/integration';\nimport { getGiteaApiUrl } from './core';\n\nimport { readGiteaConfigs } from './config';\nimport { GiteaProjectQueryResult, GiteaProviderConfig } from './types';\nimport {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskRunner,\n} from '@backstage/backend-plugin-api';\n\n/** @public */\nexport class GiteaEntityProvider implements EntityProvider {\n private readonly config: GiteaProviderConfig;\n private readonly integration: GiteaIntegration;\n private readonly logger: LoggerService;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n configRoot: Config,\n options: {\n logger: LoggerService;\n schedule?: SchedulerServiceTaskRunner;\n scheduler?: SchedulerService;\n },\n ): GiteaEntityProvider[] {\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n const providerConfigs = readGiteaConfigs(configRoot);\n const integrations = ScmIntegrations.fromConfig(configRoot).gitea;\n const providers: GiteaEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n if (!integration) {\n throw new InputError(\n `No Gitea integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for Gitea-provider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GiteaEntityProvider(\n providerConfig,\n integration,\n options.logger,\n taskRunner,\n ),\n );\n });\n\n return providers;\n }\n\n private constructor(\n config: GiteaProviderConfig,\n integration: GiteaIntegration,\n logger: LoggerService,\n taskRunner: SchedulerServiceTaskRunner,\n ) {\n this.config = config;\n this.integration = integration;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\n }\n\n getProviderName(): string {\n return `gitea-provider:${this.config.id}`;\n }\n\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n private async parseGiteaJsonResponse(\n response: Response,\n ): Promise<GiteaProjectQueryResult> {\n if (!response.ok) {\n throw new Error(\n `Failed to fetch Gitea repositories, status: ${response.status}`,\n );\n }\n try {\n return await response.json();\n } catch (error) {\n throw new Error(`Failed to parse Gitea API response: ${error}`);\n }\n }\n\n private createScheduleFn(\n taskRunner: SchedulerServiceTaskRunner,\n ): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:refresh`;\n return taskRunner.run({\n id: taskId,\n fn: async () => {\n const logger = this.logger.child({\n class: GiteaEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(\n `${this.getProviderName()} refresh failed, ${error}`,\n error as Error,\n );\n }\n },\n });\n };\n }\n\n async refresh(logger: LoggerService): Promise<void> {\n if (!this.connection) {\n throw new Error('Gitea discovery connection not initialized');\n }\n let allRepos: any[] = [];\n\n try {\n // Fetch all repos for an organization\n const OrgRepoApiUrl = `${getGiteaApiUrl(this.integration.config)}orgs/${\n this.config.organization\n }/repos`;\n let page = 1;\n let hasMoreData = true;\n\n while (hasMoreData) {\n const url = `${OrgRepoApiUrl}?page=${page}`;\n const response = await fetch(url, {\n method: 'GET',\n ...getGiteaRequestOptions(this.integration.config),\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch page ${page} of repos, status: ${response.status}`,\n );\n }\n\n const projectsPage = (await this.parseGiteaJsonResponse(\n response,\n )) as GiteaProjectQueryResult;\n\n if (!Array.isArray(projectsPage) || projectsPage.length === 0) {\n hasMoreData = false;\n } else {\n allRepos = allRepos.concat(projectsPage);\n page++;\n }\n }\n } catch (e) {\n throw new Error(\n `Failed to list Gitea projects for organization ${this.config.organization}, ${e}`,\n );\n }\n\n // Filter for repos that have catalog-info.yaml at root\n const { default: pLimit } = await import('p-limit');\n const limit = pLimit(5);\n const validRepos: string[] = [];\n\n await Promise.all(\n allRepos.map(repo =>\n limit(async () => {\n if (repo.empty) {\n logger.warn(`Repo ${repo.html_url} is empty, skipping`);\n return;\n }\n const contentsApiUrl = `${getGiteaApiUrl(\n this.integration.config,\n )}repos/${this.config.organization}/${repo.name}/contents/${\n this.config.catalogPath\n }`;\n\n const res = await fetch(contentsApiUrl, {\n method: 'GET',\n ...getGiteaRequestOptions(this.integration.config),\n });\n if (res.ok) {\n validRepos.push(repo.html_url);\n } else {\n logger.warn(\n `Repo ${repo.html_url} does not contain a catalog-info.yaml file`,\n );\n return;\n }\n }),\n ),\n );\n // Create location specs for each valid repo\n const locations = await Promise.all(\n validRepos.map(repo => limit(() => this.createLocationSpec(repo))),\n );\n // Apply the locations to the catalog\n try {\n const providerName: string = this.getProviderName();\n const entities = locations.map(location => ({\n locationKey: providerName,\n entity: locationSpecToLocationEntity({ location }),\n }));\n await this.connection.applyMutation({\n type: 'full',\n entities: entities,\n });\n } catch (e) {\n logger.error(`Failed to apply mutation: ${e}`);\n }\n logger.info(\n `Found ${locations.length} locations from ${allRepos.length} repos`,\n );\n }\n\n private async createLocationSpec(repo: string): Promise<LocationSpec> {\n return {\n type: 'url',\n target: `${repo}/src/branch/${this.config.branch}/${this.config.catalogPath}`,\n };\n }\n}\n"],"names":["readGiteaConfigs","ScmIntegrations","InputError","uu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;AAAA,MACL,CAAA,MAAA,EAAS,SAAA,CAAU,MAAM,CAAA,gBAAA,EAAmB,SAAS,MAAM,CAAA,MAAA;AAAA,KAC7D;AAAA,EACF;AAAA,EAEA,MAAc,mBAAmB,IAAA,EAAqC;AACpE,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,KAAA;AAAA,MACN,MAAA,EAAQ,CAAA,EAAG,IAAI,CAAA,YAAA,EAAe,IAAA,CAAK,OAAO,MAAM,CAAA,CAAA,EAAI,IAAA,CAAK,MAAA,CAAO,WAAW,CAAA;AAAA,KAC7E;AAAA,EACF;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs.js","sources":["../../src/providers/config.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { readSchedulerServiceTaskScheduleDefinitionFromConfig } from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport { GiteaProviderConfig } from './types';\n\nfunction readGiteaConfig(id: string, config: Config): GiteaProviderConfig {\n const branch = config.getOptionalString('branch') ?? 'main';\n const catalogPath =\n config.getOptionalString('catalogPath') ?? 'catalog-info.yaml';\n const host = config.getString('host');\n const organization = config.getString('organization');\n\n const schedule = config.has('schedule')\n ? readSchedulerServiceTaskScheduleDefinitionFromConfig(\n config.getConfig('schedule'),\n )\n : undefined;\n\n return {\n branch,\n catalogPath,\n host,\n id,\n schedule,\n organization,\n };\n}\n\nexport function readGiteaConfigs(config: Config): GiteaProviderConfig[] {\n const configs: GiteaProviderConfig[] = [];\n\n const providerConfigs = config.getOptionalConfig('catalog.providers.gitea');\n\n if (!providerConfigs) {\n return configs;\n }\n\n for (const id of providerConfigs.keys()) {\n configs.push(readGiteaConfig(id, providerConfigs.getConfig(id)));\n }\n\n return configs;\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig"],"mappings":";;;;AAoBA,SAAS,eAAA,CAAgB,IAAY,
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../../src/providers/config.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { readSchedulerServiceTaskScheduleDefinitionFromConfig } from '@backstage/backend-plugin-api';\nimport { Config } from '@backstage/config';\nimport { GiteaProviderConfig } from './types';\n\nfunction readGiteaConfig(id: string, config: Config): GiteaProviderConfig {\n const branch = config.getOptionalString('branch') ?? 'main';\n const catalogPath =\n config.getOptionalString('catalogPath') ?? 'catalog-info.yaml';\n const host = config.getString('host');\n const organization = config.getString('organization');\n\n const schedule = config.has('schedule')\n ? readSchedulerServiceTaskScheduleDefinitionFromConfig(\n config.getConfig('schedule'),\n )\n : undefined;\n\n return {\n branch,\n catalogPath,\n host,\n id,\n schedule,\n organization,\n };\n}\n\nexport function readGiteaConfigs(config: Config): GiteaProviderConfig[] {\n const configs: GiteaProviderConfig[] = [];\n\n const providerConfigs = config.getOptionalConfig('catalog.providers.gitea');\n\n if (!providerConfigs) {\n return configs;\n }\n\n for (const id of providerConfigs.keys()) {\n configs.push(readGiteaConfig(id, providerConfigs.getConfig(id)));\n }\n\n return configs;\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig"],"mappings":";;;;AAoBA,SAAS,eAAA,CAAgB,IAAY,MAAA,EAAqC;AACxE,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,QAAQ,CAAA,IAAK,MAAA;AACrD,EAAA,MAAM,WAAA,GACJ,MAAA,CAAO,iBAAA,CAAkB,aAAa,CAAA,IAAK,mBAAA;AAC7C,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,SAAA,CAAU,MAAM,CAAA;AACpC,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,SAAA,CAAU,cAAc,CAAA;AAEpD,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,GAAA,CAAI,UAAU,CAAA,GAClCA,qEAAA;AAAA,IACE,MAAA,CAAO,UAAU,UAAU;AAAA,GAC7B,GACA,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,WAAA;AAAA,IACA,IAAA;AAAA,IACA,EAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF;AACF;AAEO,SAAS,iBAAiB,MAAA,EAAuC;AACtE,EAAA,MAAM,UAAiC,EAAC;AAExC,EAAA,MAAM,eAAA,GAAkB,MAAA,CAAO,iBAAA,CAAkB,yBAAyB,CAAA;AAE1E,EAAA,IAAI,CAAC,eAAA,EAAiB;AACpB,IAAA,OAAO,OAAA;AAAA,EACT;AAEA,EAAA,KAAA,MAAW,EAAA,IAAM,eAAA,CAAgB,IAAA,EAAK,EAAG;AACvC,IAAA,OAAA,CAAQ,KAAK,eAAA,CAAgB,EAAA,EAAI,gBAAgB,SAAA,CAAU,EAAE,CAAC,CAAC,CAAA;AAAA,EACjE;AAEA,EAAA,OAAO,OAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.cjs.js","sources":["../../src/providers/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { GiteaIntegrationConfig } from '@backstage/integration';\n/**\n * Return the url to query available repos using the Gitea API.\n *\n * @param config - A Gitea provider config.\n * @public\n */\nexport function getGiteaApiUrl(config: GiteaIntegrationConfig) {\n return `${config.baseUrl}/api/v1/`;\n}\n"],"names":[],"mappings":";;AAuBO,SAAS,eAAe,
|
|
1
|
+
{"version":3,"file":"core.cjs.js","sources":["../../src/providers/core.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { GiteaIntegrationConfig } from '@backstage/integration';\n/**\n * Return the url to query available repos using the Gitea API.\n *\n * @param config - A Gitea provider config.\n * @public\n */\nexport function getGiteaApiUrl(config: GiteaIntegrationConfig) {\n return `${config.baseUrl}/api/v1/`;\n}\n"],"names":[],"mappings":";;AAuBO,SAAS,eAAe,MAAA,EAAgC;AAC7D,EAAA,OAAO,CAAA,EAAG,OAAO,OAAO,CAAA,QAAA,CAAA;AAC1B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-gitea",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "The gitea backend module for the catalog plugin.",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"postpack": "backstage-cli package postpack"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@backstage/backend-plugin-api": "^1.4.
|
|
36
|
+
"@backstage/backend-plugin-api": "^1.4.2",
|
|
37
37
|
"@backstage/config": "^1.3.3",
|
|
38
38
|
"@backstage/errors": "^1.2.7",
|
|
39
39
|
"@backstage/integration": "^1.17.1",
|
|
40
40
|
"@backstage/plugin-catalog-common": "^1.1.5",
|
|
41
|
-
"@backstage/plugin-catalog-node": "^1.
|
|
41
|
+
"@backstage/plugin-catalog-node": "^1.18.0",
|
|
42
42
|
"p-limit": "^3.0.2",
|
|
43
43
|
"uuid": "^11.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@backstage/backend-test-utils": "^1.
|
|
47
|
-
"@backstage/cli": "^0.
|
|
46
|
+
"@backstage/backend-test-utils": "^1.8.0",
|
|
47
|
+
"@backstage/cli": "^0.34.0"
|
|
48
48
|
},
|
|
49
49
|
"files": [
|
|
50
50
|
"dist"
|