feat(techdocs): add changeset + refactor
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/techdocs-common': patch
|
||||
---
|
||||
|
||||
AWS SDK version bump for TechDocs.
|
||||
@@ -52,14 +52,10 @@ export class S3 {
|
||||
}
|
||||
|
||||
headBucket() {
|
||||
return new Promise(resolve => {
|
||||
resolve('');
|
||||
});
|
||||
return '';
|
||||
}
|
||||
|
||||
putObject() {
|
||||
return new Promise(resolve => {
|
||||
resolve('');
|
||||
});
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Regular → Executable
+7
-3
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import mockFs from 'mock-fs';
|
||||
import path from 'path';
|
||||
import * as winston from 'winston';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { AwsS3Publish } from './awsS3';
|
||||
@@ -45,7 +46,7 @@ const getEntityRootDir = (entity: Entity) => {
|
||||
kind,
|
||||
metadata: { namespace, name },
|
||||
} = entity;
|
||||
const entityRootDir = `${namespace}/${kind}/${name}`;
|
||||
const entityRootDir = path.join(namespace as string, kind, name);
|
||||
return entityRootDir;
|
||||
};
|
||||
|
||||
@@ -171,14 +172,17 @@ describe('AwsS3Publish', () => {
|
||||
it('should return an error if the techdocs_metadata.json file is not present', async () => {
|
||||
const entityNameMock = createMockEntityName();
|
||||
const entity = createMockEntity();
|
||||
const entityRootDir = getEntityRootDir(entity);
|
||||
const {
|
||||
metadata: { name, namespace },
|
||||
kind,
|
||||
} = entity;
|
||||
|
||||
await publisher
|
||||
.fetchTechDocsMetadata(entityNameMock)
|
||||
.catch(error =>
|
||||
expect(error).toEqual(
|
||||
new Error(
|
||||
`TechDocs metadata fetch failed, The file ${entityRootDir}/techdocs_metadata.json doest not exist.`,
|
||||
`TechDocs metadata fetch failed, The file ${namespace}/${kind}/${name}/techdocs_metadata.json doest not exist.`,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -25,16 +25,16 @@ import fs from 'fs-extra';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
const streamToString = (stream: Readable): Promise<string> => {
|
||||
try {
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const chunks: any[] = [];
|
||||
stream.on('data', chunk => chunks.push(chunk));
|
||||
stream.on('error', reject);
|
||||
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(`Unable to parse the response data, ${e.message}`);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`Unable to parse the response data, ${e.message}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export class AwsS3Publish implements PublisherBase {
|
||||
|
||||
Reference in New Issue
Block a user