Merge pull request #3968 from mateiidavid/create-techdocs-metadata-type

This commit is contained in:
Himanshu Mishra
2021-01-20 21:23:23 +01:00
committed by GitHub
13 changed files with 115 additions and 29 deletions
+16 -8
View File
@@ -58,14 +58,22 @@ export async function createRouter({
const { '0': path } = req.params;
const entityName = getEntityNameFromUrlPath(path);
publisher
.fetchTechDocsMetadata(entityName)
.then(techdocsMetadataJson => {
res.send(techdocsMetadataJson);
})
.catch(reason => {
res.status(500).send(`Unable to get Metadata. Reason: ${reason}`);
});
try {
const techdocsMetadata = await publisher.fetchTechDocsMetadata(
entityName,
);
res.send(techdocsMetadata);
} catch (err) {
logger.error(
`Unable to get metadata for ${entityName.namespace}/${entityName.name} with error ${err}`,
);
res
.status(500)
.send(
`Unable to get metadata for $${entityName.namespace}/${entityName.name}, reason: ${err}`,
);
}
});
router.get('/metadata/entity/:namespace/:kind/:name', async (req, res) => {
+2 -1
View File
@@ -16,6 +16,7 @@
import { createApiRef } from '@backstage/core';
import { EntityName } from '@backstage/catalog-model';
import { TechDocsMetadata } from './types';
export const techdocsStorageApiRef = createApiRef<TechDocsStorageApi>({
id: 'plugin.techdocs.storageservice',
@@ -33,7 +34,7 @@ export interface TechDocsStorage {
}
export interface TechDocs {
getTechDocsMetadata(entityId: EntityName): Promise<string>;
getTechDocsMetadata(entityId: EntityName): Promise<TechDocsMetadata>;
getEntityMetadata(entityId: EntityName): Promise<string>;
}
@@ -19,12 +19,13 @@ import { AsyncState } from 'react-use/lib/useAsync';
import CodeIcon from '@material-ui/icons/Code';
import { EntityName } from '@backstage/catalog-model';
import { Header, HeaderLabel, Link } from '@backstage/core';
import { TechDocsMetadata } from '../../types';
type TechDocsPageHeaderProps = {
entityId: EntityName;
metadataRequest: {
entity: AsyncState<any>;
techdocs: AsyncState<any>;
techdocs: AsyncState<TechDocsMetadata>;
};
};
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright 2021 Spotify AB
*
* 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.
*/
export type TechDocsMetadata = {
site_name: string;
site_description: string;
};