feat(FN-4288): complete Step 2 — add stall log entry locator
Fusion-Task-Id: FN-4288 Fusion-Task-Lineage: 09c6efc0-ea0b-443a-ab45-a89188fcf888
This commit is contained in:
31
packages/dashboard/app/utils/findInReviewStallLogEntry.ts
Normal file
31
packages/dashboard/app/utils/findInReviewStallLogEntry.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { InReviewStallCode, Task, TaskLogEntry } from "@fusion/core";
|
||||
|
||||
export const IN_REVIEW_STALL_LOG_PREFIX = "In-review stall surfaced [";
|
||||
export const IN_REVIEW_STALL_LOG_REGEX = /^In-review stall surfaced \[([^\]]+)\]/;
|
||||
|
||||
export interface InReviewStallLogMatch {
|
||||
entry: TaskLogEntry;
|
||||
reversedIndex: number;
|
||||
code: InReviewStallCode;
|
||||
}
|
||||
|
||||
export function findInReviewStallLogEntry(
|
||||
task: Pick<Task, "log">,
|
||||
code: InReviewStallCode,
|
||||
): InReviewStallLogMatch | undefined {
|
||||
if (!task.log?.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const reversed = [...task.log].reverse();
|
||||
for (const [reversedIndex, entry] of reversed.entries()) {
|
||||
const match = entry.action.match(IN_REVIEW_STALL_LOG_REGEX);
|
||||
if (!match || match[1] !== code) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return { entry, reversedIndex, code };
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user