@comeonautomation/reportportal-client
Advanced tools
Comparing version
@@ -280,46 +280,94 @@ /* eslint-disable quotes,no-console,class-methods-use-this */ | ||
*/ | ||
forceStopAndDeleteSkippedInterruptedTests() { | ||
if (this.isLaunchMergeRequired) { | ||
const statusUrl = ['launch', 'status'].join('/'); | ||
const stopUrl = ['launch', 'stop'].join('/'); | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
async forceStopAndDeleteSkippedInterruptedTests() { | ||
if (!this.isLaunchMergeRequired) { | ||
this.logDebug(`Option isLaunchMergeRequired is false.`); | ||
return; | ||
} | ||
const statusUrl = 'launch/status'; | ||
const stopUrl = 'launch/stop'; | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
try { | ||
// Retrieve statuses for all launches | ||
const response = await this.restClient.retrieve(`${statusUrl}?ids=${launchIds.join()}`); | ||
const inProgressLaunches = Object.entries(response) | ||
.filter(([_, status]) => status === 'IN_PROGRESS') | ||
.map(([launchId]) => launchId); | ||
if (inProgressLaunches.length === 0) { | ||
this.logDebug(`No launches are in progress to stop.`); | ||
} else { | ||
// Prepare data for stopping launches | ||
const data = inProgressLaunches.reduce((acc, launchId) => { | ||
acc[launchId] = { | ||
endTime: this.helpers.now(), | ||
status: 'STOPPED' | ||
}; | ||
return acc; | ||
}, {}); | ||
// Stop the in-progress launches | ||
await this.restClient.update(stopUrl, { entities: data }, { headers: this.headers }); | ||
this.logDebug(`In-progress launches successfully stopped: ${inProgressLaunches.join(', ')}`); | ||
} | ||
// Proceed with deletion of skipped, interrupted, and empty tests/launches | ||
await this.deleteSkippedInterruptedTest(); | ||
await this.deleteEmptyExecutionTest(); | ||
await this.deleteEmptyExecutionLaunch(); | ||
} catch (error) { | ||
this.logDebug(`Failed to force stop and clean up tests/launches: ${error.message}`); | ||
} | ||
} | ||
this.restClient | ||
.retrieve(`${statusUrl}?ids=${launchIds.join()}`) | ||
.then(response => { | ||
const arr = []; | ||
for (let item in response) { | ||
response[item] === 'IN_PROGRESS' && arr.push(item); | ||
async deleteSkippedInterruptedTest() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const hasSkipTestItems = []; | ||
for (let item in launchIds) { | ||
try { | ||
// Retrieve items for the current launchId | ||
const response = await this.restClient.retrieve(`/item?filter.eq.launchId=${launchIds[item]}&page.size=100`); | ||
if (response.status !== 200) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to HTTP ${response.status}.`); | ||
continue; | ||
} | ||
this.logDebug(`Total elements in ${launchIds[item]}: ` + response.page.totalElements); | ||
for (let i = 0; i < response.page.totalElements; i++) { | ||
this.logDebug(`Test ID: ${response.content[i].id} ${response.content[i].name} Skipped: ${response.content[i].statistics.executions.skipped}`); | ||
const item_id_url = `/item/uuid/${response.content[i].id}`; | ||
if ( | ||
(response.content[i].statistics.executions.skipped === 1 && !response.content[i].hasChildren) || | ||
(response.content[i].statistics.executions.total === response.content[i].statistics.executions.skipped) || | ||
(response.content[i].status === 'INTERRUPTED' && !response.content[i].hasChildren) | ||
) { | ||
try { | ||
const itemDetails = await this.restClient.retrieve(item_id_url); | ||
hasSkipTestItems.push(itemDetails.id); | ||
await this.restClient.delete(`/item?ids=${itemDetails.id}`); | ||
this.logDebug('Deleted Skipped & Interrupted tests successfully'); | ||
} catch (innerError) { | ||
this.logDebug(`Failed to retrieve or delete item ${response.content[i].id}. Error: ${innerError.message}`); | ||
} | ||
} | ||
const data = {}; | ||
arr.map( | ||
item => | ||
(data[item] = { | ||
endTime: this.helpers.now(), | ||
status: 'STOPPED' | ||
}) | ||
); | ||
this.restClient | ||
.update( | ||
stopUrl, | ||
{ entities: data }, | ||
{ headers: this.headers } | ||
) | ||
.then(async response => { | ||
this.logDebug(`Launches successfully stopped!`); | ||
await this.deleteSkippedInterruptedTest() | ||
.then(async () => { | ||
await this.deleteEmptyExecutionTest(); | ||
}) | ||
.then(async () => { | ||
await this.deleteEmptyExecutionLaunch(); | ||
}); | ||
}); | ||
}); | ||
} else { | ||
this.logDebug(`Option isLaunchMergeRequired is false'`); | ||
} | ||
} catch (error) { | ||
// Log error and continue to next item | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to error: ${error.message}`); | ||
continue; | ||
} | ||
} | ||
this.logDebug('Completed processing all launch IDs.'); | ||
} | ||
isLaunchWithFailedTests(launchTempId) { | ||
@@ -351,84 +399,105 @@ const launchObj = this.map[launchTempId]; | ||
async deleteSkippedInterruptedTest() { | ||
async deleteEmptyExecutionTest() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const hasSkipTestItems = []; | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve('/item?filter.eq.launchId=' + launchIds[item] + '&page.size=100') | ||
.then(async response => { | ||
this.logDebug(`Total elements in ${launchIds[item]}: ` + response.page.totalElements); | ||
for (var i = 0; i < response.page.totalElements; i++) { | ||
this.logDebug('Test ID: ' + response.content[i].id + ' ' + response.content[i].name + ' Skipped:' + response.content[i].statistics.executions.skipped); | ||
const item_id_url = '/item/uuid/' + response.content[i].id; | ||
if ( | ||
(response.content[i].statistics.executions | ||
.skipped === 1 | ||
&& response.content[i].hasChildren === false) | ||
|| (response.content[i].statistics.executions.total | ||
=== response.content[i].statistics.executions | ||
.skipped) | ||
|| (response.content[i].status === 'INTERRUPTED' | ||
&& response.content[i].hasChildren === false) | ||
) { | ||
this.restClient | ||
.retrieve(item_id_url) | ||
.then(response => { | ||
hasSkipTestItems.push(response.id); | ||
this.restClient | ||
.delete('/item?ids=' + response.id) | ||
.then(response => { | ||
this.logDebug('Deleted Skipped & Interrupted tests successfully'); | ||
}); | ||
}); | ||
try { | ||
// Retrieve items for the current launchId | ||
const response = await this.restClient.retrieve(`/item?filter.eq.launchId=${launchIds[item]}&page.size=100`); | ||
if (response.status !== 200) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to HTTP ${response.status}.`); | ||
continue; | ||
} | ||
for (let i = 0; i < response.page.totalElements; i++) { | ||
const item_id_url = `/item/uuid/${response.content[i].id}`; | ||
try { | ||
const itemDetails = await this.restClient.retrieve(item_id_url); | ||
if (Object.values(itemDetails.statistics.executions).length === 0) { | ||
await this.restClient.delete(`/item?ids=${itemDetails.id}`); | ||
this.logDebug(`Deleted test with empty executions: ${itemDetails.id}`); | ||
} | ||
} catch (innerError) { | ||
this.logDebug(`Failed to retrieve or delete item ${response.content[i].id}. Error: ${innerError.message}`); | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to error: ${error.message}`); | ||
continue; | ||
} | ||
} | ||
this.logDebug('Completed processing all launch IDs for empty execution tests.'); | ||
} | ||
async deleteEmptyExecutionTest() { | ||
async deleteEmptyExecutionLaunch() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve( | ||
'/item?filter.eq.launchId=' + launchIds[item] + '&page.size=100', | ||
) | ||
.then(response => { | ||
for (let i = 0; i < response.page.totalElements; i++) { | ||
const item_id_url = '/item/uuid/' + response.content[i].id; | ||
this.restClient | ||
.retrieve(item_id_url) | ||
.then(response => { | ||
if (Object.values(response.statistics.executions).length === 0) { | ||
this.restClient | ||
.delete('/item?ids=' + response.id) | ||
.then(() => { | ||
this.logDebug('Deleted test have empty executions'); | ||
}); | ||
} | ||
}); | ||
try { | ||
// Retrieve items for the current launchId | ||
const response = await this.restClient.retrieve(`/item?filter.eq.launchId=${launchIds[item]}&page.size=100`); | ||
if (response.status !== 200) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to HTTP ${response.status}.`); | ||
continue; | ||
} | ||
if (response.page.totalElements === 0) { | ||
try { | ||
await this.restClient.delete(`/launch/${launchIds[item]}`); | ||
this.logDebug(`Deleted launch with empty executions: ${launchIds[item]}`); | ||
} catch (deleteError) { | ||
this.logDebug(`Failed to delete launch ${launchIds[item]}. Error: ${deleteError.message}`); | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to error: ${error.message}`); | ||
continue; | ||
} | ||
} | ||
this.logDebug('Completed processing all launch IDs for empty execution launches.'); | ||
} | ||
async deleteEmptyExecutionLaunch() { | ||
async deleteEmptyExecutionTest() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve('/item?filter.eq.launchId=' + launchIds[item] + '&page.size=100',) | ||
.then(async (response) => { | ||
if (response.page.totalElements === 0) { | ||
await this.restClient | ||
.delete('/launch/' + launchIds[item]) | ||
.then(() => { | ||
this.logDebug('Deleted launch have empty executions'); | ||
}); | ||
try { | ||
// Retrieve items for the current launchId | ||
const response = await this.restClient.retrieve(`/item?filter.eq.launchId=${launchIds[item]}&page.size=100`); | ||
if (response.status !== 200) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to HTTP ${response.status}.`); | ||
continue; | ||
} | ||
for (let i = 0; i < response.page.totalElements; i++) { | ||
const item_id_url = `/item/uuid/${response.content[i].id}`; | ||
try { | ||
const itemDetails = await this.restClient.retrieve(item_id_url); | ||
if (Object.values(itemDetails.statistics.executions).length === 0) { | ||
await this.restClient.delete(`/item?ids=${itemDetails.id}`); | ||
this.logDebug(`Deleted test with empty executions: ${itemDetails.id}`); | ||
} | ||
} catch (innerError) { | ||
this.logDebug(`Failed to retrieve or delete item ${response.content[i].id}. Error: ${innerError.message}`); | ||
} | ||
}); | ||
} | ||
} catch (error) { | ||
this.logDebug(`Skipping launchId ${launchIds[item]} due to error: ${error.message}`); | ||
continue; | ||
} | ||
} | ||
this.logDebug('Completed processing all launch IDs for empty execution tests.'); | ||
} | ||
@@ -460,27 +529,41 @@ /* | ||
async mergeLaunches(mergeDescription) { | ||
if (this.isLaunchMergeRequired) { | ||
const url = ['launch', 'merge'].join('/'); | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const activeLaunches = []; | ||
for (let items in launchIds) { | ||
await this.restClient | ||
.retrieve('/launch/status?ids=' + launchIds[items]) | ||
.then(response => { | ||
if (response.hasOwnProperty(launchIds[items])) { | ||
activeLaunches.push(launchIds[items]); | ||
} | ||
}); | ||
if (!this.isLaunchMergeRequired) { | ||
this.logDebug(`Option isLaunchMergeRequired is false`); | ||
return; | ||
} | ||
const url = 'launch/merge'; | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const activeLaunches = []; | ||
try { | ||
for (const launchId of launchIds) { | ||
try { | ||
const response = await this.restClient.retrieve(`/launch/status?ids=${launchId}`); | ||
if (response.hasOwnProperty(launchId)) { | ||
activeLaunches.push(launchId); | ||
this.logDebug(`Launch ${launchId} is active and added for merging.`); | ||
} else { | ||
this.logDebug(`Launch ${launchId} is not active or invalid.`); | ||
} | ||
} catch (error) { | ||
this.logDebug(`Failed to retrieve status for launch ${launchId}: ${error.message}`); | ||
continue; | ||
} | ||
} | ||
if (activeLaunches.length === 0) { | ||
this.logDebug(`No active launches found for merging.`); | ||
return; | ||
} | ||
const data = this.getMergeLaunchesData(activeLaunches, mergeDescription); | ||
this.restClient | ||
.create(url, data, { headers: this.headers }) | ||
.then(() => { | ||
this.logDebug(`Launches successfully merged!`); | ||
}); | ||
} else { | ||
this.logDebug(`Option isLaunchMergeRequired is false'`); | ||
await this.restClient.create(url, data, { headers: this.headers }); | ||
this.logDebug(`Launches successfully merged!`); | ||
} catch (error) { | ||
this.logDebug(`Failed to merge launches: ${error.message}`); | ||
} | ||
} | ||
@@ -487,0 +570,0 @@ |
{ | ||
"name": "@comeonautomation/reportportal-client", | ||
"version": "2.3.8", | ||
"version": "2.3.9", | ||
"description": "ReportPortal client for node.js", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
156847
2.36%1974
2.6%