Skip to content

Commit 5826d09

Browse files
committed
feat(techdocs): add changeset + refactor
1 parent b18efa0 commit 5826d09

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

.changeset/short-badgers-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@backstage/techdocs-common': patch
3+
---
4+
5+
AWS SDK version bump for TechDocs.

packages/techdocs-common/__mocks__/@aws-sdk/client-s3.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,10 @@ export class S3 {
5252
}
5353

5454
headBucket() {
55-
return new Promise(resolve => {
56-
resolve('');
57-
});
55+
return '';
5856
}
5957

6058
putObject() {
61-
return new Promise(resolve => {
62-
resolve('');
63-
});
59+
return '';
6460
}
6561
}

packages/techdocs-common/src/stages/publish/awsS3.test.ts

100644100755
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import mockFs from 'mock-fs';
17+
import path from 'path';
1718
import * as winston from 'winston';
1819
import { ConfigReader } from '@backstage/config';
1920
import { AwsS3Publish } from './awsS3';
@@ -45,7 +46,7 @@ const getEntityRootDir = (entity: Entity) => {
4546
kind,
4647
metadata: { namespace, name },
4748
} = entity;
48-
const entityRootDir = `${namespace}/${kind}/${name}`;
49+
const entityRootDir = path.join(namespace as string, kind, name);
4950
return entityRootDir;
5051
};
5152

@@ -171,14 +172,17 @@ describe('AwsS3Publish', () => {
171172
it('should return an error if the techdocs_metadata.json file is not present', async () => {
172173
const entityNameMock = createMockEntityName();
173174
const entity = createMockEntity();
174-
const entityRootDir = getEntityRootDir(entity);
175+
const {
176+
metadata: { name, namespace },
177+
kind,
178+
} = entity;
175179

176180
await publisher
177181
.fetchTechDocsMetadata(entityNameMock)
178182
.catch(error =>
179183
expect(error).toEqual(
180184
new Error(
181-
`TechDocs metadata fetch failed, The file ${entityRootDir}/techdocs_metadata.json doest not exist.`,
185+
`TechDocs metadata fetch failed, The file ${namespace}/${kind}/${name}/techdocs_metadata.json doest not exist.`,
182186
),
183187
),
184188
);

packages/techdocs-common/src/stages/publish/awsS3.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ import fs from 'fs-extra';
2525
import { Readable } from 'stream';
2626

2727
const streamToString = (stream: Readable): Promise<string> => {
28-
try {
29-
return new Promise((resolve, reject) => {
28+
return new Promise((resolve, reject) => {
29+
try {
3030
const chunks: any[] = [];
3131
stream.on('data', chunk => chunks.push(chunk));
3232
stream.on('error', reject);
3333
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
34-
});
35-
} catch (e) {
36-
throw new Error(`Unable to parse the response data, ${e.message}`);
37-
}
34+
} catch (e) {
35+
throw new Error(`Unable to parse the response data, ${e.message}`);
36+
}
37+
});
3838
};
3939

4040
export class AwsS3Publish implements PublisherBase {

0 commit comments

Comments
 (0)