integration: addressed comments

This commit is contained in:
Fredrik Adelöw
2020-12-07 21:43:17 +01:00
parent 38e24db009
commit b2db892869
12 changed files with 27 additions and 29 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
---
'@backstage/integration': minor
'@backstage/integration': patch
---
Add the basics of cross-integration concerns
@@ -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;
}
@@ -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');
});
});
@@ -34,7 +34,7 @@ export class AzureIntegration implements ScmIntegration {
return 'azure';
}
get name(): string {
get title(): string {
return this.config.host;
}
}
@@ -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');
});
});
@@ -37,7 +37,7 @@ export class BitbucketIntegration implements ScmIntegration {
return 'bitbucket';
}
get name(): string {
get title(): string {
return this.config.host;
}
}
@@ -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');
});
});
@@ -37,7 +37,7 @@ export class GitHubIntegration implements ScmIntegration {
return 'github';
}
get name(): string {
get title(): string {
return this.config.host;
}
}
@@ -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');
});
});
@@ -37,7 +37,7 @@ export class GitLabIntegration implements ScmIntegration {
return 'gitlab';
}
get name(): string {
get title(): string {
return this.config.host;
}
}
+2 -1
View File
@@ -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';
+12 -11
View File
@@ -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;
};