Throws an error when there is no triplet
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -323,7 +323,13 @@ export class AwsS3Publish implements PublisherBase {
|
||||
await Promise.all(
|
||||
allObjects.map(f =>
|
||||
limiter(async file => {
|
||||
const newPath = lowerCaseEntityTripletInStoragePath(file);
|
||||
let newPath;
|
||||
try {
|
||||
newPath = lowerCaseEntityTripletInStoragePath(file);
|
||||
} catch (e) {
|
||||
this.logger.warn(e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// If all parts are already lowercase, ignore.
|
||||
if (file === newPath) {
|
||||
|
||||
@@ -313,7 +313,14 @@ export class AzureBlobStoragePublish implements PublisherBase {
|
||||
originalPath: string,
|
||||
removeOriginal: boolean,
|
||||
) {
|
||||
const newPath = lowerCaseEntityTripletInStoragePath(originalPath);
|
||||
let newPath;
|
||||
try {
|
||||
newPath = lowerCaseEntityTripletInStoragePath(originalPath);
|
||||
} catch (e) {
|
||||
this.logger.warn(e.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (originalPath === newPath) return;
|
||||
try {
|
||||
this.logger.debug(`Migrating ${originalPath}`);
|
||||
|
||||
@@ -90,4 +90,12 @@ describe('lowerCaseEntityTripletInStoragePath', () => {
|
||||
const actualPath = lowerCaseEntityTripletInStoragePath(originalPath);
|
||||
expect(actualPath).toBe('default/component/backstage/assets/IMAGE.png');
|
||||
});
|
||||
|
||||
it('throws error when there is no triplet', () => {
|
||||
const originalPath = '/default/component/IMAGE.png';
|
||||
const error = `Encountered file unmanaged by TechDocs ${originalPath}. Skipping.`;
|
||||
expect(() =>
|
||||
lowerCaseEntityTripletInStoragePath(originalPath),
|
||||
).toThrowError(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -97,6 +97,14 @@ export const getFileTreeRecursively = async (
|
||||
export const lowerCaseEntityTripletInStoragePath = (
|
||||
originalPath: string,
|
||||
): string => {
|
||||
const trimmedPath =
|
||||
originalPath[0] === '/' ? originalPath.substring(1) : originalPath;
|
||||
const matches = trimmedPath.match(/\//g) || [];
|
||||
if (matches.length <= 2) {
|
||||
throw new Error(
|
||||
`Encountered file unmanaged by TechDocs ${originalPath}. Skipping.`,
|
||||
);
|
||||
}
|
||||
const [namespace, kind, name, ...parts] = originalPath.split('/');
|
||||
const lowerNamespace = namespace.toLowerCase();
|
||||
const lowerKind = kind.toLowerCase();
|
||||
|
||||
@@ -38,7 +38,14 @@ export class MigrateWriteStream extends Writable {
|
||||
|
||||
_write(file: File, _encoding: BufferEncoding, next: Function) {
|
||||
let shouldCallNext = true;
|
||||
const newFile = lowerCaseEntityTripletInStoragePath(file.name);
|
||||
let newFile;
|
||||
try {
|
||||
newFile = lowerCaseEntityTripletInStoragePath(file.name);
|
||||
} catch (e) {
|
||||
this.logger.warn(e.message);
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
// If all parts are already lowercase, ignore.
|
||||
if (newFile === file.name) {
|
||||
|
||||
Reference in New Issue
Block a user