Skip to content

Commit

Permalink
fix: continue searching for assignees to disqualify
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Dec 15, 2023
1 parent 1b38997 commit ef47ed8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
41 changes: 18 additions & 23 deletions src/handlers/wildcard/unassign/assign-event-found.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,26 @@ import { Logs } from "../../../adapters/supabase/helpers/tables/logs";
import { Context } from "../../../types/context";
import { GitHubAssignEvent, GitHubUser } from "../../../types/payload";
import { disqualifyIdleAssignees } from "./disqualify-idle-assignees";
import { followUpWithTheRest } from "./follow-up-with-the-rest";
import { remindNonEliminatedAssignees } from "./remind-non-eliminated-assignees";

interface Params {
latestAssignEvent: GitHubAssignEvent;
logger: Logs;
assignees: GitHubUser[];
taskDisqualifyDuration: number;
disqualifiedAssignees: null | string[];
context: Context;
activeAssigneesInDisqualifyDuration: string[];
login: string;
name: string;
number: number;
activeAssigneesInFollowUpDuration: string[];
}
export async function assignEventFound({
latestAssignEvent,
logger,
assignees,
taskDisqualifyDuration,
disqualifiedAssignees,
context,
activeAssigneesInDisqualifyDuration,
login,
name,
number,
taskDisqualifyDuration,
activeAssigneesInDisqualifyDuration,
activeAssigneesInFollowUpDuration,
}: Params) {
}: AssignEventFoundParams) {
const latestAssignEventTime = new Date(latestAssignEvent.created_at).getTime();

logger.debug("Latest assign event time", { latestAssignEventTime });

const now = Date.now();

const assigneesWithinGracePeriod = assignees.filter(() => now - latestAssignEventTime < taskDisqualifyDuration);

const assigneesOutsideGracePeriod = assignees.filter((assignee) => !assigneesWithinGracePeriod.includes(assignee));

disqualifiedAssignees = await disqualifyIdleAssignees(context, {
assignees: assigneesOutsideGracePeriod.map((assignee) => assignee.login),
activeAssigneesInDisqualifyDuration,
Expand All @@ -49,7 +31,7 @@ export async function assignEventFound({
});

// DONE: follow up with those who are in `assignees` and not inside of `disqualifiedAssignees` or `activeAssigneesInFollowUpDuration`
await followUpWithTheRest(context, {
await remindNonEliminatedAssignees(context, {
assignees: assigneesOutsideGracePeriod.map((assignee) => assignee.login),
disqualifiedAssignees,
activeAssigneesInFollowUpDuration,
Expand All @@ -60,3 +42,16 @@ export async function assignEventFound({
});
return disqualifiedAssignees;
}
interface AssignEventFoundParams {
latestAssignEvent: GitHubAssignEvent;
logger: Logs;
assignees: GitHubUser[];
context: Context;
login: string;
name: string;
number: number;
disqualifiedAssignees: null | string[];
taskDisqualifyDuration: number;
activeAssigneesInDisqualifyDuration: string[];
activeAssigneesInFollowUpDuration: string[];
}
5 changes: 2 additions & 3 deletions src/handlers/wildcard/unassign/check-task-to-unassign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export async function checkTaskToUnassign(context: Context, assignedIssue: GitHu
});
}
const assignees = assignedIssue.assignees.filter((item): item is GitHubUser => item !== null);

const assigneeLoginsOnly = assignees.map((assignee) => assignee.login);

const login = payload.repository.owner.login;
Expand Down Expand Up @@ -66,10 +65,10 @@ export async function checkTaskToUnassign(context: Context, assignedIssue: GitHu

logger.debug("Latest assign event", { latestAssignEvent });

let disqualifiedAssignees: null | GitHubUser[] = null;
let disqualifiedAssignees: null | string[] = null;

if (!latestAssignEvent) {
throw logger.debug("No latest assign event found.", { assignEventsOfAssignee });
return logger.debug("No latest assign event found.", { assignEventsOfAssignee });
} else {
disqualifiedAssignees = await assignEventFound({
latestAssignEvent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context } from "../../../types/context";
import { checkIfFollowUpAlreadyPosted } from "./check-if-follow-up-already-posted";

export async function followUpWithTheRest(
export async function remindNonEliminatedAssignees(
context: Context,
{
assignees,
Expand Down

0 comments on commit ef47ed8

Please sign in to comment.