techdocs: switch to using constants from techdocs-common for annotations
Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import { ScmIntegrations } from '@backstage/integration';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { Readable } from 'stream';
|
||||
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
|
||||
import {
|
||||
getDocFilesFromRepository,
|
||||
getLocationForEntity,
|
||||
@@ -64,7 +65,7 @@ const metadataBase = {
|
||||
|
||||
const goodAnnotation = {
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref':
|
||||
[TECHDOCS_ANNOTATION]:
|
||||
'url:https://github.com/backstage/backstage/blob/master/subfolder/',
|
||||
},
|
||||
};
|
||||
@@ -81,7 +82,7 @@ const mockEntityWithAnnotation: Entity = {
|
||||
|
||||
const badAnnotation = {
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref': 'bad-annotation',
|
||||
[TECHDOCS_ANNOTATION]: 'bad-annotation',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -102,7 +103,7 @@ afterEach(() => jest.resetAllMocks());
|
||||
describe('parseReferenceAnnotation', () => {
|
||||
it('should parse annotation', () => {
|
||||
const parsedLocationAnnotation = parseReferenceAnnotation(
|
||||
'backstage.io/techdocs-ref',
|
||||
TECHDOCS_ANNOTATION,
|
||||
mockEntityWithAnnotation,
|
||||
);
|
||||
expect(parsedLocationAnnotation.type).toBe('url');
|
||||
@@ -113,14 +114,14 @@ describe('parseReferenceAnnotation', () => {
|
||||
|
||||
it('should throw error without annotation', () => {
|
||||
expect(() => {
|
||||
parseReferenceAnnotation('backstage.io/techdocs-ref', entityBase);
|
||||
parseReferenceAnnotation(TECHDOCS_ANNOTATION, entityBase);
|
||||
}).toThrow(/No location annotation/);
|
||||
});
|
||||
|
||||
it('should throw error with bad annotation', () => {
|
||||
expect(() => {
|
||||
parseReferenceAnnotation(
|
||||
'backstage.io/techdocs-ref',
|
||||
TECHDOCS_ANNOTATION,
|
||||
mockEntityWithBadAnnotation,
|
||||
);
|
||||
}).toThrow(/Unable to parse/);
|
||||
@@ -146,14 +147,14 @@ describe('transformDirLocation', () => {
|
||||
metadata: {
|
||||
name: 'test',
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref': techdocsRef,
|
||||
[TECHDOCS_ANNOTATION]: techdocsRef,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result = transformDirLocation(
|
||||
entity,
|
||||
parseReferenceAnnotation('backstage.io/techdocs-ref', entity),
|
||||
parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity),
|
||||
scmIntegrations,
|
||||
);
|
||||
|
||||
@@ -179,14 +180,14 @@ describe('transformDirLocation', () => {
|
||||
metadata: {
|
||||
name: 'test',
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref': techdocsRef,
|
||||
[TECHDOCS_ANNOTATION]: techdocsRef,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result = transformDirLocation(
|
||||
entity,
|
||||
parseReferenceAnnotation('backstage.io/techdocs-ref', entity),
|
||||
parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity),
|
||||
scmIntegrations,
|
||||
);
|
||||
|
||||
@@ -206,7 +207,7 @@ describe('transformDirLocation', () => {
|
||||
metadata: {
|
||||
name: 'test',
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref': 'dir:..',
|
||||
[TECHDOCS_ANNOTATION]: 'dir:..',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -214,7 +215,7 @@ describe('transformDirLocation', () => {
|
||||
expect(() =>
|
||||
transformDirLocation(
|
||||
entity,
|
||||
parseReferenceAnnotation('backstage.io/techdocs-ref', entity),
|
||||
parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity),
|
||||
scmIntegrations,
|
||||
),
|
||||
).toThrow(
|
||||
@@ -234,7 +235,7 @@ describe('transformDirLocation', () => {
|
||||
metadata: {
|
||||
name: 'test',
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref': 'dir:.',
|
||||
[TECHDOCS_ANNOTATION]: 'dir:.',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -242,7 +243,7 @@ describe('transformDirLocation', () => {
|
||||
expect(() =>
|
||||
transformDirLocation(
|
||||
entity,
|
||||
parseReferenceAnnotation('backstage.io/techdocs-ref', entity),
|
||||
parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity),
|
||||
scmIntegrations,
|
||||
),
|
||||
).toThrow(/Unable to resolve location type other/);
|
||||
@@ -262,7 +263,7 @@ describe('getLocationForEntity', () => {
|
||||
metadata: {
|
||||
name: 'test',
|
||||
annotations: {
|
||||
'backstage.io/techdocs-ref': 'dir:.',
|
||||
[TECHDOCS_ANNOTATION]: 'dir:.',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
} from '@backstage/catalog-model';
|
||||
import { InputError } from '@backstage/errors';
|
||||
import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
|
||||
import path from 'path';
|
||||
import { Logger } from 'winston';
|
||||
import { PreparerResponse, RemoteProtocol } from './stages/prepare/types';
|
||||
@@ -122,10 +123,7 @@ export const getLocationForEntity = (
|
||||
entity: Entity,
|
||||
scmIntegration: ScmIntegrationRegistry,
|
||||
): ParsedLocationAnnotation => {
|
||||
const annotation = parseReferenceAnnotation(
|
||||
'backstage.io/techdocs-ref',
|
||||
entity,
|
||||
);
|
||||
const annotation = parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity);
|
||||
|
||||
switch (annotation.type) {
|
||||
case 'url':
|
||||
@@ -149,10 +147,7 @@ export const getDocFilesFromRepository = async (
|
||||
entity: Entity,
|
||||
opts?: { etag?: string; logger?: Logger },
|
||||
): Promise<PreparerResponse> => {
|
||||
const { target } = parseReferenceAnnotation(
|
||||
'backstage.io/techdocs-ref',
|
||||
entity,
|
||||
);
|
||||
const { target } = parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity);
|
||||
|
||||
opts?.logger?.debug(`Reading files from ${target}`);
|
||||
// readTree will throw NotModifiedError if etag has not changed.
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { UrlReader, loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { DirectoryPreparer } from './dir';
|
||||
import { mockServices } from '@backstage/backend-test-utils';
|
||||
@@ -61,7 +62,7 @@ describe('directory preparer', () => {
|
||||
const mockEntity = createMockEntity({
|
||||
'backstage.io/managed-by-location':
|
||||
'file:/directory/documented-component.yaml',
|
||||
'backstage.io/techdocs-ref': 'dir:./our-documentation',
|
||||
[TECHDOCS_ANNOTATION]: 'dir:./our-documentation',
|
||||
});
|
||||
|
||||
const { preparedDir } = await directoryPreparer.prepare(mockEntity);
|
||||
@@ -77,7 +78,7 @@ describe('directory preparer', () => {
|
||||
const mockEntity = createMockEntity({
|
||||
'backstage.io/managed-by-location':
|
||||
'file:/directory/documented-component.yaml',
|
||||
'backstage.io/techdocs-ref': 'dir:/our-documentation/techdocs',
|
||||
[TECHDOCS_ANNOTATION]: 'dir:/our-documentation/techdocs',
|
||||
});
|
||||
|
||||
await expect(directoryPreparer.prepare(mockEntity)).rejects.toThrow(
|
||||
@@ -94,7 +95,7 @@ describe('directory preparer', () => {
|
||||
const mockEntity = createMockEntity({
|
||||
'backstage.io/managed-by-location':
|
||||
'does-not-exist:https://github.com/backstage/backstage/blob/master/catalog-info.yaml',
|
||||
'backstage.io/techdocs-ref': 'dir:./docs',
|
||||
[TECHDOCS_ANNOTATION]: 'dir:./docs',
|
||||
});
|
||||
|
||||
await expect(directoryPreparer.prepare(mockEntity)).rejects.toThrow(
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
ScmIntegrationRegistry,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
|
||||
import { Logger } from 'winston';
|
||||
import { parseReferenceAnnotation, transformDirLocation } from '../../helpers';
|
||||
import {
|
||||
@@ -70,10 +71,7 @@ export class DirectoryPreparer implements PreparerBase {
|
||||
entity: Entity,
|
||||
options?: PreparerOptions,
|
||||
): Promise<PreparerResponse> {
|
||||
const annotation = parseReferenceAnnotation(
|
||||
'backstage.io/techdocs-ref',
|
||||
entity,
|
||||
);
|
||||
const annotation = parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity);
|
||||
const { type, target } = transformDirLocation(
|
||||
entity,
|
||||
annotation,
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
|
||||
import { parseReferenceAnnotation } from '../../helpers';
|
||||
import { DirectoryPreparer } from './dir';
|
||||
import { UrlPreparer } from './url';
|
||||
@@ -78,10 +79,7 @@ export class Preparers implements PreparerBuilder {
|
||||
* @returns
|
||||
*/
|
||||
get(entity: Entity): PreparerBase {
|
||||
const { type } = parseReferenceAnnotation(
|
||||
'backstage.io/techdocs-ref',
|
||||
entity,
|
||||
);
|
||||
const { type } = parseReferenceAnnotation(TECHDOCS_ANNOTATION, entity);
|
||||
const preparer = this.preparerMap.get(type);
|
||||
|
||||
if (!preparer) {
|
||||
|
||||
Reference in New Issue
Block a user