Skip to content

Commit

Permalink
chore: refactor null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 16, 2024
1 parent 9196ec8 commit 4c6156c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/helpers/get-assignee-activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
});
}
10 changes: 8 additions & 2 deletions src/helpers/task-deadline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit 4c6156c

Please sign in to comment.