refactor: improve task notification logic for unblocked tasks
- Simplified the logic for determining pending blockers in the notifyUnblockedOwners function. - Replaced filter method with a for loop for better clarity and performance. - Updated notification message to accurately reflect the status of pending blockers.
This commit is contained in:
parent
67f38d8029
commit
82a70d8a16
1 changed files with 12 additions and 20 deletions
|
|
@ -244,34 +244,26 @@ function notifyUnblockedOwners(context, completedTask) {
|
||||||
if (!normalizeActorName(blockedTask.owner)) continue;
|
if (!normalizeActorName(blockedTask.owner)) continue;
|
||||||
|
|
||||||
const allBlockerIds = Array.isArray(blockedTask.blockedBy) ? blockedTask.blockedBy : [];
|
const allBlockerIds = Array.isArray(blockedTask.blockedBy) ? blockedTask.blockedBy : [];
|
||||||
const pendingBlockers = allBlockerIds.filter((id) => {
|
const pendingBlockerTasks = [];
|
||||||
if (id === completedTask.id) return false;
|
for (const id of allBlockerIds) {
|
||||||
|
if (id === completedTask.id) continue;
|
||||||
try {
|
try {
|
||||||
const t = taskStore.readTask(context.paths, id, { includeDeleted: true });
|
const t = taskStore.readTask(context.paths, id, { includeDeleted: true });
|
||||||
return t.status !== 'completed' && t.status !== 'deleted';
|
if (t.status !== 'completed' && t.status !== 'deleted') {
|
||||||
} catch { return false; }
|
pendingBlockerTasks.push(t);
|
||||||
});
|
}
|
||||||
|
} catch { /* missing task = not blocking */ }
|
||||||
const allResolved = pendingBlockers.length === 0;
|
|
||||||
const blockedLabel = `#${blockedTask.displayId || blockedTask.id}`;
|
|
||||||
|
|
||||||
let pendingList = '';
|
|
||||||
if (!allResolved) {
|
|
||||||
const refs = pendingBlockers.map((id) => {
|
|
||||||
try {
|
|
||||||
const t = taskStore.readTask(context.paths, id, { includeDeleted: true });
|
|
||||||
return `#${t.displayId || t.id}`;
|
|
||||||
} catch { return `#${id.slice(0, 8)}`; }
|
|
||||||
});
|
|
||||||
pendingList = refs.join(', ');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allResolved = pendingBlockerTasks.length === 0;
|
||||||
|
const blockedLabel = `#${blockedTask.displayId || blockedTask.id}`;
|
||||||
|
|
||||||
const lines = [
|
const lines = [
|
||||||
`**Dependency resolved** — task ${completedLabel} _${completedTask.subject}_ completed.`,
|
`**Dependency resolved** — task ${completedLabel} _${completedTask.subject}_ completed.`,
|
||||||
``,
|
``,
|
||||||
allResolved
|
allResolved
|
||||||
? `All blockers for ${blockedLabel} are resolved — this task is ready to start.`
|
? `All blockers for ${blockedLabel} are resolved — this task is ready to start.`
|
||||||
: `${allBlockerIds.length - pendingBlockers.length} of ${allBlockerIds.length} blockers resolved. Still waiting on: ${pendingList}.`,
|
: `${allBlockerIds.length - pendingBlockerTasks.length} of ${allBlockerIds.length} blockers resolved. Still waiting on: ${pendingBlockerTasks.map((t) => `#${t.displayId || t.id}`).join(', ')}.`,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (allResolved) {
|
if (allResolved) {
|
||||||
|
|
@ -299,7 +291,7 @@ function notifyUnblockedOwners(context, completedTask) {
|
||||||
function completeTask(context, taskId, actor) {
|
function completeTask(context, taskId, actor) {
|
||||||
const task = setTaskStatus(context, taskId, 'completed', actor);
|
const task = setTaskStatus(context, taskId, 'completed', actor);
|
||||||
try {
|
try {
|
||||||
notifyUnblockedOwners(context, task, actor);
|
notifyUnblockedOwners(context, task);
|
||||||
} catch {
|
} catch {
|
||||||
// Best-effort: task completion succeeded, notification failure is non-fatal
|
// Best-effort: task completion succeeded, notification failure is non-fatal
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue