Skip to content

Commit

Permalink
Merge pull request #65 from gentlementlegen/fix/draft-only-review-req…
Browse files Browse the repository at this point in the history
…uest

fix: change to draft only on changes requested
  • Loading branch information
gentlementlegen authored Dec 18, 2024
2 parents cc2bb57 + a67d38c commit b539b51
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
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 "< 1 minute";
}
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.`
);
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
}
}
}
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

0 comments on commit b539b51

Please sign in to comment.