feat: updated handling for findTaskById to take complexityReport as input

This commit is contained in:
Shrey Paharia
2025-04-19 13:09:14 +05:30
parent 8911bf4d49
commit e045a5268c
3 changed files with 47 additions and 19 deletions

View File

@@ -270,12 +270,14 @@ function getStatusWithColor(status, forTable = false) {
* @param {Array} dependencies - Array of dependency IDs
* @param {Array} allTasks - Array of all tasks
* @param {boolean} forConsole - Whether the output is for console display
* @param {Object|null} complexityReport - Optional pre-loaded complexity report
* @returns {string} Formatted dependencies string
*/
function formatDependenciesWithStatus(
dependencies,
allTasks,
forConsole = false
forConsole = false,
complexityReport = null // Add complexityReport parameter
) {
if (
!dependencies ||
@@ -338,8 +340,8 @@ function formatDependenciesWithStatus(
const numericDepId =
typeof depId === 'string' ? parseInt(depId, 10) : depId;
// Look up the task using the numeric ID
const depTask = findTaskById(allTasks, numericDepId);
// Look up the task using the numeric ID, passing the complexity report
const depTask = findTaskById(allTasks, numericDepId, complexityReport);
if (!depTask) {
return forConsole
@@ -680,6 +682,9 @@ async function displayNextTask(tasksPath) {
process.exit(1);
}
// Read complexity report once
const complexityReport = readComplexityReport();
// Find the next task
const nextTask = findNextTask(data.tasks);
@@ -747,7 +752,12 @@ async function displayNextTask(tasksPath) {
],
[
chalk.cyan.bold('Dependencies:'),
formatDependenciesWithStatus(nextTask.dependencies, data.tasks, true)
formatDependenciesWithStatus(
nextTask.dependencies,
data.tasks,
true,
complexityReport
) // Pass complexityReport
],
[chalk.cyan.bold('Description:'), nextTask.description]
);
@@ -929,8 +939,11 @@ async function displayTaskById(tasksPath, taskId) {
process.exit(1);
}
// Find the task by ID
const task = findTaskById(data.tasks, taskId);
// Read complexity report once
const complexityReport = readComplexityReport();
// Find the task by ID, passing the complexity report
const task = findTaskById(data.tasks, taskId, complexityReport);
if (!task) {
console.log(
@@ -1157,7 +1170,12 @@ async function displayTaskById(tasksPath, taskId) {
[chalk.cyan.bold('Priority:'), priorityColor(task.priority || 'medium')],
[
chalk.cyan.bold('Dependencies:'),
formatDependenciesWithStatus(task.dependencies, data.tasks, true)
formatDependenciesWithStatus(
task.dependencies,
data.tasks,
true,
complexityReport
) // Pass complexityReport
],
[chalk.cyan.bold('Description:'), task.description]
);