[ACS-11759] MNT-25541 automated (#5186)

* [ACS-11759] MNT-25541 automated

* [ACS-11759] copilot review fixes 1
This commit is contained in:
Adam Świderski
2026-05-15 14:35:46 +02:00
committed by GitHub
parent 29a2a36efc
commit 0ba55fd2cd
5 changed files with 52 additions and 27 deletions
@@ -162,8 +162,12 @@ export class ApiClientFactory {
try {
return await peopleApi.createPerson(person);
} catch (error) {
if (String(error).includes('409')) {
logger.warn(`[API Client Factory] createUser: user "${user.username}" already exists, skipping creation`);
return null;
}
logger.error(`[API Client Factory] createUser failed: ${error}`);
return null;
throw error;
}
}
@@ -42,11 +42,18 @@ export class FileActionsApi {
async uploadFile(fileLocation: string, fileName: string, parentFolderId: string): Promise<NodeEntry> {
const file = fs.createReadStream(fileLocation);
return this.apiService.upload.uploadFile(file, '', parentFolderId, null, {
name: fileName,
nodeType: 'cm:content',
renditions: 'doclib'
});
try {
const result = await this.apiService.upload.uploadFile(file, '', parentFolderId, undefined, {
name: fileName,
nodeType: 'cm:content',
renditions: 'doclib'
});
logger.info(`File uploaded successfully: ${fileName}`);
return result;
} catch (error) {
logger.error(`Failed to upload file: ${fileName}: ${error}`);
return Promise.reject(error);
}
}
async uploadFileWithRename(
@@ -70,8 +77,11 @@ export class FileActionsApi {
};
try {
return this.apiService.upload.uploadFile(file, '', parentId, nodeProps, opts);
const result = await this.apiService.upload.uploadFile(file, '', parentId, nodeProps, opts);
logger.info(`File uploaded successfully: ${newName}`);
return result;
} catch (error) {
logger.error(`Failed to upload file: ${newName}: ${error}`);
return Promise.reject(error);
}
}
@@ -95,7 +105,7 @@ export class FileActionsApi {
async getNodeProperty(nodeId: string, property: string): Promise<string> {
try {
const node = await this.getNodeById(nodeId);
return node.entry.properties?.[property] || '';
return node?.entry?.properties?.[property] || '';
} catch {
return '';
}
@@ -133,7 +143,7 @@ export class FileActionsApi {
private async queryNodesNames(searchTerm: string): Promise<ResultSetPaging> {
const data = {
query: {
query: `cm:name:\"${searchTerm}*\"`,
query: `cm:name:"${searchTerm}*"`,
language: 'afts'
},
filterQueries: [{ query: `+TYPE:'cm:folder' OR +TYPE:'cm:content'` }]
@@ -147,11 +157,17 @@ export class FileActionsApi {
}
async waitForNodes(searchTerm: string, data: { expect: number }): Promise<void> {
logger.info(`waitForNodes: Waiting for ${data.expect} node(s) matching "${searchTerm}"`);
const predicate = (totalItems: number) => totalItems === data.expect;
let pollCount = 0;
const apiCall = async () => {
try {
return (await this.queryNodesNames(searchTerm)).list.pagination.totalItems;
const totalItems = (await this.queryNodesNames(searchTerm)).list?.pagination?.totalItems || 0;
if (pollCount++ % 4 === 0) {
logger.info(`waitForNodes: "${searchTerm}" — found ${totalItems}, expecting ${data.expect}`);
}
return totalItems;
} catch (error) {
return 0;
}
@@ -208,7 +224,7 @@ export class FileActionsApi {
const apiCall = async (): Promise<number> => {
try {
return (await this.queryNodesSearchHighlight(searchTerm)).list.pagination.totalItems;
return (await this.queryNodesSearchHighlight(searchTerm)).list?.pagination?.totalItems || 0;
} catch (error) {
logger.warn(`queryNodesSearchHighlight failed for "${searchTerm}": ${error}`);
return 0;
@@ -225,11 +241,13 @@ export class FileActionsApi {
async updateNodeContent(nodeId: string, content: string, majorVersion: boolean = true, comment?: string, newName?: string): Promise<NodeEntry> {
try {
const opts: { [key: string]: string | boolean } = {
majorVersion: majorVersion,
comment: comment,
name: newName
};
const opts: { [key: string]: string | boolean } = { majorVersion };
if (comment !== undefined) {
opts['comment'] = comment;
}
if (newName !== undefined) {
opts['name'] = newName;
}
return await this.apiService.nodes.updateNodeContent(nodeId, content, opts);
} catch (error) {
logger.error(`${this.constructor.name} ${this.updateNodeContent.name}: ${error}`);
@@ -111,5 +111,10 @@ export const TEST_FILES = {
AZW3_FILE: {
path: resolve(__dirname, 'file-azw3.azw3'),
name: 'file-azw3'
},
PDF_JP2_FILE: {
path: resolve(__dirname, 'file-pdf-with-jp2.pdf'),
name: 'file-pdf-jp2',
data: 'Lorem ipsum dolor sit amet'
}
};