mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-03 05:27:36 +00:00
feat(cli): add completion helper and handle review issue releases/closures
This commit is contained in:
1 parent
a64a6c2379
commit
d6b483f84e
3 files changed
+116
-79
No files matched your search
+14
-8
@@ -25,12 +25,13 @@
|
||||
import type { Problem } from "../api/src/reviews.ts";
|
||||
import type { GitHub } from "./github.ts";
|
||||
|
||||
/** Completion of a required set: a topic's core problems, or every problem of a review. */
|
||||
export interface Core {
|
||||
/** Core sub-issues, closed and open alike, lowest number first. */
|
||||
/** The required problems, closed and open alike, in the order given. */
|
||||
all: number[];
|
||||
/** The core sub-issues still open — non-empty means the topic stays open. */
|
||||
/** The required problems still open — non-empty means the issue stays open. */
|
||||
pending: number[];
|
||||
/** When the last core sub-issue closed; null until the topic is finished. */
|
||||
/** When the last required problem closed; null until the set is finished (never, if empty). */
|
||||
finishedAt: string | null;
|
||||
}
|
||||
|
||||
@@ -71,13 +72,18 @@ export function labelValue(problem: Problem, prefix: string): string | undefined
|
||||
return problem.labels.find((l) => l.startsWith(prefix))?.slice(prefix.length);
|
||||
}
|
||||
|
||||
/** A topic's rule: its `set:core` problems are the required set. */
|
||||
export function coreSet(problems: Problem[]): Core {
|
||||
const core = problems.filter((p) => labelValue(p, "set:") === "core");
|
||||
const pending = core.filter((p) => !p.closedAt).map((p) => p.number);
|
||||
return completion(problems.filter((p) => labelValue(p, "set:") === "core"));
|
||||
}
|
||||
|
||||
/** The shared rule: finished when non-empty and every required problem is closed. */
|
||||
export function completion(required: Problem[]): Core {
|
||||
const pending = required.filter((p) => !p.closedAt).map((p) => p.number);
|
||||
// ISO instants from the API share one format, so string order is time order.
|
||||
const finishedAt =
|
||||
core.length && !pending.length
|
||||
? core.map((p) => p.closedAt!).reduce((a, b) => (a > b ? a : b))
|
||||
required.length && !pending.length
|
||||
? required.map((p) => p.closedAt!).reduce((a, b) => (a > b ? a : b))
|
||||
: null;
|
||||
return { all: core.map((p) => p.number), pending, finishedAt };
|
||||
return { all: required.map((p) => p.number), pending, finishedAt };
|
||||
}
|
||||
Reference in new issue
Block a user