diff --git a/src/helpers/get-assignee-activity.ts b/src/helpers/get-assignee-activity.ts index 78679cc..2468cde 100644 --- a/src/helpers/get-assignee-activity.ts +++ b/src/helpers/get-assignee-activity.ts @@ -38,7 +38,7 @@ function filterEvents(issueEvents: GitHubTimelineEvents[], assigneeIds: number[] for (const event of issueEvents) { let actorId = null; let actorLogin = null; - let createdAt = "UNKNOWN"; + let createdAt = null; let eventName = event.event; if ("actor" in event && event.actor) { @@ -71,6 +71,9 @@ function filterEvents(issueEvents: GitHubTimelineEvents[], assigneeIds: number[] } return assigneeEvents.sort((a, b) => { + if (!a.created_at || !b.created_at) { + return 0; + } return DateTime.fromISO(b.created_at).toMillis() - DateTime.fromISO(a.created_at).toMillis(); }); } diff --git a/src/helpers/task-deadline.ts b/src/helpers/task-deadline.ts index 7b62079..555fb07 100644 --- a/src/helpers/task-deadline.ts +++ b/src/helpers/task-deadline.ts @@ -35,18 +35,24 @@ export async function getDeadlineWithThreshold( } const activity = (await getAssigneesActivityForIssue(context, issue, assigneeIds)).filter((o) => { + if (!o.created_at) { + return false; + } return DateTime.fromISO(o.created_at) > lastCheck; }); const filteredActivity = activity.filter((o) => { - return eventWhitelist.includes(o.event || ""); + if (!o.event) { + return false; + } + return eventWhitelist.includes(o.event); }); let deadlineWithThreshold = deadline.plus({ milliseconds: disqualification }); let reminderWithThreshold = deadline.plus({ milliseconds: warning }); if (filteredActivity?.length) { - const lastActivity = DateTime.fromISO(filteredActivity[0].created_at); + const lastActivity = filteredActivity[0].created_at ? DateTime.fromISO(filteredActivity[0].created_at) : deadline; deadlineWithThreshold = lastActivity.plus({ milliseconds: disqualification }); reminderWithThreshold = lastActivity.plus({ milliseconds: warning }); }