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: change to draft only on changes requested #65

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"prepare": "husky install",
"test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage",
"supabase:generate:local": "supabase gen types typescript --local > src/types/database.ts",
"supabase:generate:remote": "cross-env-shell \"supabase gen types typescript --project-id $SUPABASE_PROJECT_ID --schema public > src/types/database.ts\"",
"server": "bun --watch src/worker.ts"
"supabase:generate:remote": "cross-env-shell \"supabase gen types typescript --project-id $SUPABASE_PROJECT_ID --schema public > src/types/database.ts\""
},
"keywords": [
"typescript",
Expand Down
33 changes: 26 additions & 7 deletions src/handlers/time-format.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
export function formatMillisecondsToDaysAndHours(milliseconds: number): string {
export function formatMillisecondsToHumanReadable(milliseconds: number): string {
if (milliseconds <= 0) {
return "0 days and 0 hours";
return "0 days, 0 hours, and 0 minutes";
}
const days = Math.floor(milliseconds / (1000 * 60 * 60 * 24));
const hours = Math.floor((milliseconds % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
if (days === 0) {
return `${hours} ${hours === 1 ? "hour" : "hours"}`;
} else if (hours === 0) {
return `${days} ${days === 1 ? "day" : "days"}`;
const minutes = Math.floor((milliseconds % (1000 * 60 * 60)) / (1000 * 60));
const components: string[] = [];

if (days > 0) {
components.push(`${days} ${days === 1 ? "day" : "days"}`);
}

if (hours > 0) {
components.push(`${hours} ${hours === 1 ? "hour" : "hours"}`);
}

if (minutes > 0) {
components.push(`${minutes} ${minutes === 1 ? "minute" : "minutes"}`);
}

if (components.length === 0) {
return "< 1 minute";
}

if (components.length === 1) {
return components[0];
} else if (components.length === 2) {
return `${components[0]} and ${components[1]}`;
} else {
return `${days} ${days === 1 ? "day" : "days"} and ${hours} ${hours === 1 ? "hour" : "hours"}`;
return `${components[0]}, ${components[1]}, and ${components[2]}`;
}
}
6 changes: 3 additions & 3 deletions src/handlers/watch-user-activity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { RestEndpointMethodTypes } from "@octokit/rest";
import { postComment } from "@ubiquity-os/plugin-sdk";
import { formatMillisecondsToHumanReadable } from "./time-format";
import { getWatchedRepos } from "../helpers/get-watched-repos";
import { parsePriorityLabel } from "../helpers/task-metadata";
import { updateTaskReminder } from "../helpers/task-update";
import { ListForOrg } from "../types/github-types";
import { ContextPlugin } from "../types/plugin-input";
import { formatMillisecondsToDaysAndHours } from "./time-format";

type IssueType = RestEndpointMethodTypes["issues"]["listForRepo"]["response"]["data"]["0"];

Expand All @@ -29,9 +29,9 @@ export async function watchUserActivity(context: ContextPlugin) {
if (context.config.pullRequestRequired) {
message.push(`- Be sure to link a pull-request before the first reminder to avoid disqualification.`);
}
message.push(`- Reminders will be sent every \`${formatMillisecondsToDaysAndHours(context.config.warning / priorityValue)}\` if there is no activity.`);
message.push(`- Reminders will be sent every \`${formatMillisecondsToHumanReadable(context.config.warning / priorityValue)}\` if there is no activity.`);
message.push(
`- Assignees will be disqualified after \`${formatMillisecondsToDaysAndHours(context.config.disqualification / priorityValue)}\` of inactivity.`
`- Assignees will be disqualified after \`${formatMillisecondsToHumanReadable(context.config.disqualification / priorityValue)}\` of inactivity.`
Copy link
Member

Choose a reason for hiding this comment

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

What happens on priority 0?

Copy link
Member Author

@gentlementlegen gentlementlegen Dec 14, 2024

Choose a reason for hiding this comment

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

It will be considered as 1 for deadlines, is that ok?
Example with 0 prio: Meniole#7 (comment)

Copy link
Member

@0x4007 0x4007 Dec 15, 2024

Choose a reason for hiding this comment

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

That or infinity. Let's try 1 for now then. I'm just considering the ability to set float levels like priority 0.5 and the system acting predictably. So 0 should predictably be infinity but it's also sort of rarely used so we'll see.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even when the priority is 0 we still want the disqualifier to run right? If so I don't think infinity makes sense, it should use the same timers as a priority 1.

);
const log = logger.error(message.map((o) => `> ${o}`).join("\n"));
log.logMessage.diff = log.logMessage.raw;
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/collect-linked-pulls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PullRequest, validate } from "@octokit/graphql-schema";
import { ContextPlugin } from "../types/plugin-input";

type ClosedByPullRequestsReferences = {
node: Pick<PullRequest, "url" | "title" | "number" | "state" | "body" | "id"> & { author: { login: string; id: number } };
node: Pick<PullRequest, "url" | "title" | "number" | "state" | "body" | "id" | "reviewDecision"> & { author: { login: string; id: number } };
};

type IssueWithClosedByPrs = {
Expand Down Expand Up @@ -34,6 +34,7 @@ const query = /* GraphQL */ `
id: databaseId
}
}
reviewDecision
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is based on the last review?

Copy link
Member Author

Choose a reason for hiding this comment

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

According to the docs it contains the last global state of the review: https://docs.github.com/en/graphql/reference/enums#pullrequestreviewdecision

}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/helpers/remind-and-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function remindAssigneesForIssue(context: ContextPlugin, issue: Lis
const { logger, config } = context;
const issueItem = parseIssueUrl(issue.html_url);

const hasLinkedPr = !!(await collectLinkedPullRequests(context, issueItem)).length;
const hasLinkedPr = !!(await collectLinkedPullRequests(context, issueItem)).filter((o) => o.state === "OPEN").length;
if (config.warning <= 0) {
logger.info("The reminder threshold is <= 0, won't send any reminder.");
} else if (config.pullRequestRequired && !hasLinkedPr) {
Expand Down Expand Up @@ -71,11 +71,13 @@ async function remindAssignees(context: ContextPlugin, issue: ListIssueForRepo)
issue_number: prNumber,
body: [logMessage.logMessage.raw, metadata].join("\n"),
});
await octokit.graphql(MUTATION_PULL_REQUEST_TO_DRAFT, {
input: {
pullRequestId: pullRequest.id,
},
});
if (pullRequest.reviewDecision === "CHANGES_REQUESTED") {
await octokit.graphql(MUTATION_PULL_REQUEST_TO_DRAFT, {
input: {
pullRequestId: pullRequest.id,
},
});
}
} catch (e) {
logger.error(`Could not post to ${pullRequest.url} will post to the issue instead.`, { e });
shouldPostToMainIssue = true;
Expand Down
Loading