Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for actor type bot in unassigned events #83

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/handlers/shared/check-assignments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ async function getUserStopComments(context: Context, username: string): Promise<
}

export async function hasUserBeenUnassigned(context: Context, username: string): Promise<boolean> {
const {
env: { BOT_USER_ID },
} = context;
const events = await getAssignmentEvents(context);
const userAssignments = events.filter((event) => event.assignee === username);

Expand All @@ -36,9 +33,9 @@ export async function hasUserBeenUnassigned(context: Context, username: string):
const unassignedEvents = userAssignments.filter((event) => event.event === "unassigned");
// all bot unassignments (/stop, disqualification, etc)
// TODO: task-xp-guard: will also prevent future assignments so we need to add a comment tracker we can use here
const botUnassigned = unassignedEvents.filter((event) => event.actorId === BOT_USER_ID);
const botUnassigned = unassignedEvents.filter((event) => event.actorType === "Bot");
// UI assignment
const adminUnassigned = unassignedEvents.filter((event) => event.actor !== username && event.actorId !== BOT_USER_ID);
const adminUnassigned = unassignedEvents.filter((event) => event.actor !== username && event.actorType !== "Bot");
// UI assignment
const userUnassigned = unassignedEvents.filter((event) => event.actor === username);
const userStopComments = await getUserStopComments(context, username);
Expand Down Expand Up @@ -69,19 +66,21 @@ async function getAssignmentEvents(context: Context) {
const events = data
.filter((event) => event.event === "assigned" || event.event === "unassigned")
.map((event) => {
let actor, assignee, createdAt, actorId;
let actor, assignee, createdAt, actorId, actorType;

if ((event.event === "unassigned" || event.event === "assigned") && "actor" in event && event.actor && "assignee" in event && event.assignee) {
actor = event.actor.login;
assignee = event.assignee.login;
createdAt = event.created_at;
actorId = event.actor.id;
actorType = event.actor.type;
}

return {
event: event.event,
actor,
actorId,
actorType,
assignee,
createdAt,
};
Expand Down