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

Disable Self Assigns #13

Closed
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions src/handlers/shared/check-unassigns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Context } from "../../types";

export async function wasPreviouslyUnassigned(
context: Context,
senderLogin: Context["payload"]["sender"],
issueNumber: Context["payload"]["issue"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming convention for these args is off slightly so it's being used in error in the return statement below I think

): Promise<boolean> {
try {
const issueEvents = await context.octokit.issues.listEventsForTimeline({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: issueNumber.id,
});

return issueEvents.data.some((event) => event.event === "unassigned" && event.event === senderLogin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sceptical that event.event can be both unassigned and senderLogin, QA would be ideal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that this fails on the test CI. I suppose I should be more cautious of reviews from mobile as it is not easy to see these details sometimes.

} catch (error) {
console.error("Error while checking previous assignment:", error);
return false;
}
}
7 changes: 7 additions & 0 deletions src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Context, ISSUE_TYPE, Label } from "../../types";
import { isParentIssue, getAvailableOpenedPullRequests, getAssignedIssues, addAssignees, addCommentToIssue } from "../../utils/issue";
import { calculateDurations } from "../../utils/shared";
import { checkTaskStale } from "./check-task-stale";
import { wasPreviouslyUnassigned } from "./check-unassigns";
import { generateAssignmentComment } from "./generate-assignment-comment";
import structuredMetadata from "./structured-metadata";
import { assignTableComment } from "./table";
Expand Down Expand Up @@ -66,12 +67,18 @@ export async function start(context: Context, issue: Context["payload"]["issue"]

const labels = issue.labels;
const priceLabel = labels.find((label: Label) => label.name.startsWith("Price: "));
const isUnassigned = await wasPreviouslyUnassigned(context, sender, issue);

if (!priceLabel) {
await addCommentToIssue(context, "```diff\n! No price label is set to calculate the duration.\n```");
throw new Error("No price label is set to calculate the duration");
}

if (isUnassigned) {
await addCommentToIssue(context, "```diff\n! You were previously unassigned from this task. You cannot reassign yourself\n```");
throw new Error(`This user was unassigned from this task previously. Cannot auto assign`);
}

const duration: number = calculateDurations(labels).shift() ?? 0;

const { id, login } = sender;
Expand Down
Loading