diff --git a/.changeset/nine-forks-sleep.md b/.changeset/nine-forks-sleep.md index 7edbca2169..ce8051d35c 100644 --- a/.changeset/nine-forks-sleep.md +++ b/.changeset/nine-forks-sleep.md @@ -1,5 +1,5 @@ --- -'@backstage/integration': minor +'@backstage/integration': patch --- Add the basics of cross-integration concerns diff --git a/packages/integration/src/ScmIntegrationsImpl.ts b/packages/integration/src/ScmIntegrations.ts similarity index 82% rename from packages/integration/src/ScmIntegrationsImpl.ts rename to packages/integration/src/ScmIntegrations.ts index ef6a6835b9..515a32502d 100644 --- a/packages/integration/src/ScmIntegrationsImpl.ts +++ b/packages/integration/src/ScmIntegrations.ts @@ -22,12 +22,12 @@ import { GitLabIntegration } from './gitlab/GitLabIntegration'; import { ScmIntegration, ScmIntegrationPredicateTuple, - ScmIntegrations, + ScmIntegrationRegistry, } from './types'; -export class ScmIntegrationsImpl implements ScmIntegrations { - static fromConfig(config: Config): ScmIntegrationsImpl { - return new ScmIntegrationsImpl([ +export class ScmIntegrations implements ScmIntegrationRegistry { + static fromConfig(config: Config): ScmIntegrations { + return new ScmIntegrations([ ...AzureIntegration.factory({ config }), ...BitbucketIntegration.factory({ config }), ...GitHubIntegration.factory({ config }), @@ -41,10 +41,6 @@ export class ScmIntegrationsImpl implements ScmIntegrations { return this.integrations.map(i => i.integration); } - byName(name: string): ScmIntegration | undefined { - return this.integrations.map(i => i.integration).find(i => i.name === name); - } - byUrl(url: string): ScmIntegration | undefined { return this.integrations.find(i => i.predicate(new URL(url)))?.integration; } diff --git a/packages/integration/src/azure/AzureIntegration.test.ts b/packages/integration/src/azure/AzureIntegration.test.ts index d0d3cf65ad..aec37ce905 100644 --- a/packages/integration/src/azure/AzureIntegration.test.ts +++ b/packages/integration/src/azure/AzureIntegration.test.ts @@ -43,6 +43,6 @@ describe('AzureIntegration', () => { it('returns the basics', () => { const integration = new AzureIntegration({ host: 'h.com' } as any); expect(integration.type).toBe('azure'); - expect(integration.name).toBe('h.com'); + expect(integration.title).toBe('h.com'); }); }); diff --git a/packages/integration/src/azure/AzureIntegration.ts b/packages/integration/src/azure/AzureIntegration.ts index 2e1e4d9795..84dc3800d2 100644 --- a/packages/integration/src/azure/AzureIntegration.ts +++ b/packages/integration/src/azure/AzureIntegration.ts @@ -34,7 +34,7 @@ export class AzureIntegration implements ScmIntegration { return 'azure'; } - get name(): string { + get title(): string { return this.config.host; } } diff --git a/packages/integration/src/bitbucket/BitbucketIntegration.test.ts b/packages/integration/src/bitbucket/BitbucketIntegration.test.ts index 9678b35014..174b6ab232 100644 --- a/packages/integration/src/bitbucket/BitbucketIntegration.test.ts +++ b/packages/integration/src/bitbucket/BitbucketIntegration.test.ts @@ -46,6 +46,6 @@ describe('BitbucketIntegration', () => { it('returns the basics', () => { const integration = new BitbucketIntegration({ host: 'h.com' } as any); expect(integration.type).toBe('bitbucket'); - expect(integration.name).toBe('h.com'); + expect(integration.title).toBe('h.com'); }); }); diff --git a/packages/integration/src/bitbucket/BitbucketIntegration.ts b/packages/integration/src/bitbucket/BitbucketIntegration.ts index e06b539611..b271e2f408 100644 --- a/packages/integration/src/bitbucket/BitbucketIntegration.ts +++ b/packages/integration/src/bitbucket/BitbucketIntegration.ts @@ -37,7 +37,7 @@ export class BitbucketIntegration implements ScmIntegration { return 'bitbucket'; } - get name(): string { + get title(): string { return this.config.host; } } diff --git a/packages/integration/src/github/GitHubIntegration.test.ts b/packages/integration/src/github/GitHubIntegration.test.ts index 5a8800200f..3383c9ebe7 100644 --- a/packages/integration/src/github/GitHubIntegration.test.ts +++ b/packages/integration/src/github/GitHubIntegration.test.ts @@ -45,6 +45,6 @@ describe('GitHubIntegration', () => { it('returns the basics', () => { const integration = new GitHubIntegration({ host: 'h.com' } as any); expect(integration.type).toBe('github'); - expect(integration.name).toBe('h.com'); + expect(integration.title).toBe('h.com'); }); }); diff --git a/packages/integration/src/github/GitHubIntegration.ts b/packages/integration/src/github/GitHubIntegration.ts index f70684975d..92c5951873 100644 --- a/packages/integration/src/github/GitHubIntegration.ts +++ b/packages/integration/src/github/GitHubIntegration.ts @@ -37,7 +37,7 @@ export class GitHubIntegration implements ScmIntegration { return 'github'; } - get name(): string { + get title(): string { return this.config.host; } } diff --git a/packages/integration/src/gitlab/GitLabIntegration.test.ts b/packages/integration/src/gitlab/GitLabIntegration.test.ts index 5c46610c53..4a23f55816 100644 --- a/packages/integration/src/gitlab/GitLabIntegration.test.ts +++ b/packages/integration/src/gitlab/GitLabIntegration.test.ts @@ -43,6 +43,6 @@ describe('GitLabIntegration', () => { it('returns the basics', () => { const integration = new GitLabIntegration({ host: 'h.com' } as any); expect(integration.type).toBe('gitlab'); - expect(integration.name).toBe('h.com'); + expect(integration.title).toBe('h.com'); }); }); diff --git a/packages/integration/src/gitlab/GitLabIntegration.ts b/packages/integration/src/gitlab/GitLabIntegration.ts index 6e94e084cc..4d035cb24e 100644 --- a/packages/integration/src/gitlab/GitLabIntegration.ts +++ b/packages/integration/src/gitlab/GitLabIntegration.ts @@ -37,7 +37,7 @@ export class GitLabIntegration implements ScmIntegration { return 'gitlab'; } - get name(): string { + get title(): string { return this.config.host; } } diff --git a/packages/integration/src/index.ts b/packages/integration/src/index.ts index 9d42914fdb..fdcd7da676 100644 --- a/packages/integration/src/index.ts +++ b/packages/integration/src/index.ts @@ -18,4 +18,5 @@ export * from './azure'; export * from './bitbucket'; export * from './github'; export * from './gitlab'; -export type { ScmIntegration, ScmIntegrations } from './types'; +export { ScmIntegrations } from './ScmIntegrations'; +export type { ScmIntegration, ScmIntegrationRegistry } from './types'; diff --git a/packages/integration/src/types.ts b/packages/integration/src/types.ts index 6f9290a948..ae9c360980 100644 --- a/packages/integration/src/types.ts +++ b/packages/integration/src/types.ts @@ -20,30 +20,31 @@ import { Config } from '@backstage/config'; * Encapsulates a single SCM integration. */ export type ScmIntegration = { + /** + * The type of integration, e.g. "github". + */ type: string; - name: string; + + /** + * A human readable title for the integration, that can be shown to users to + * differentiate between different integrations. + */ + title: string; }; /** * Holds all registered SCM integrations. */ -export type ScmIntegrations = { +export type ScmIntegrationRegistry = { /** * Lists all registered integrations. */ list(): ScmIntegration[]; /** - * Fetches a named integration + * Fetches an integration by URL. * - * @param name The name of a registered integration - */ - byName(name: string): ScmIntegration | undefined; - - /** - * Fetches an integration by URL - * - * @param name A URL that matches a registered integration + * @param url A URL that matches a registered integration */ byUrl(url: string): ScmIntegration | undefined; };