Skip to content

Commit

Permalink
fix(main): second round
Browse files Browse the repository at this point in the history
second round
  • Loading branch information
snomiao committed Jun 19, 2024
1 parent df100f1 commit 83c791e
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 82 deletions.
8 changes: 2 additions & 6 deletions app/(dashboard)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ export const dynamic = "force-dynamic";
export default async function DashboardPage() {
return (
<main className="flex flex-wrap">
<Suspense>
<TotalsPage />
</Suspense>
<Suspense>
<LatestDetails />
</Suspense>
<TotalsPage />
<LatestDetails />
</main>
);
}
Expand Down
35 changes: 18 additions & 17 deletions app/(dashboard)/rules/[name]/RuleWhirler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,29 @@ export default function RuleWhirler({
const defaultLanguage = "yaml";
return (
<div className="card card-body overflow-hidden">
<div className="flex ">
<CodeEditor
{...{
onChange: async (code) => {
if (code === undefined) return;
const results = await onChange(code);
setResults(results);
},
defaultValue,
defaultLanguage,
}}
height="80vh"
/>

<div className="card-body bg-cyan-600">
<div className="flex">
<div className="grow">
<CodeEditor
{...{
onChange: async (code) => {
if (code === undefined) return;
const results = await onChange(code);
setResults(results);
},
defaultValue,
defaultLanguage,
}}
height="80vh"
/>
</div>
<div className="card-body bg-cyan-600 w-[40%]">
<Markdown>
{`${tsmatch(results)
.with($OK, ({ data }) => {
yaml.stringify(data);
return yaml.stringify(data);
})
.with($ERROR, ({ error }) => {
yaml.stringify(error);
return yaml.stringify(error);
})
.otherwise(() => {
// maybe pending
Expand Down
4 changes: 2 additions & 2 deletions app/(dashboard)/rules/[name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const RuleWhirler = dynamic(() => import("./RuleWhirler"), { ssr: false });
export default async function FollowRulesPage({ params: { name = "default" } }) {
const defaultValue = (await FollowRuleSets.findOne({ name }))?.yaml ?? notFound();
return (
<main>
<main className="grow card-body gap-4">
<h1>Follow Rules Edit</h1>
<div className="card-body">
<div className="card">
<RuleWhirler
onChange={async (yaml) => {
"use server";
Expand Down
2 changes: 1 addition & 1 deletion app/(dashboard)/rules/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* @author: snomiao <[email protected]>
*/
export default async function RulesList() {
return <>Choose one ruleset to continue...</>;
return <div className="text-1xl self-center">Choose one ruleset to continue...</div>;
}
49 changes: 11 additions & 38 deletions packages/mongodb-pipeline-ts/$pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,20 @@ import {
type Filter,
type IndexSpecification,
} from "mongodb";
import type { FieldArrayPath } from "react-hook-form";
import type { AutoPath } from "ts-toolbelt/out/Function/AutoPath";
import type { Path } from "ts-toolbelt/out/Object/Path";
import type { Split } from "ts-toolbelt/out/String/Split";
type ValueOfPath<T extends any, P extends string> = Path<T, Split<P, ".">>;
// import type { ArrayPath, PathValue } from "react-hook-form";
// import type { ArrayPath, FieldPath, PathValue } from "react-hook-form";
// import type { FieldPath, $Value } from "react-hook-form";
// react-hook-form path match is extremely slow, while generating 3k+ paths for a object

// type FieldPath<S extends Document> = string;
// type $Value<S extends Document, Path extends string> = any;
// type FieldArrayPath<S extends Document> = string;
// type FieldArrayPathValue<S extends Document, Path extends string> = any;
// type Head<T extends any[]> = T extends [infer H, ...any] ? H : never;
// type PathHead<T extends string> = T extends `${infer H}.${infer R}` ? H : T extends `${infer H}` ? H : never;
// type PathTail<T extends string> = T extends `${infer H}.${infer R}` ? R : never;
// type $Value<S extends Document, P extends string = string> = Path<S, Split<P, ".">>;
// type $Path<S extends Document, P extends string = string> = `$${string}`;
// type $Value<S extends Document, P extends string = string> = Path<S, Split<P, ".">>;
type PathFrom$Path<P extends string> = P extends `$${infer R}` ? R : never;
type $Path<S extends Document, P extends string = string> = `$${AutoPath<S, P>}`;
// type $Path<S extends Document, P extends string = string> = `$${P}`;
type DeepRecord<Path extends string, Value> = Path extends `${infer Head}.${infer Tail}`
? { [K in Head]: DeepRecord<Tail, Value> }
: { [K in Path]: Value };

// type $PathOf<S extends Document, V extends any = any> = `$${string}`;
// type $PathOf<S extends Document, V extends any = any> = `$${AllPathOf<S, V>}`;

// type AllPathOf<S extends Document, V extends any = any> = ValueOfPath<S, infer P extends AllPath<S>> extends V ? P : never;
import type { FieldArrayPath, FieldArrayPathValue, FieldPath, FieldPathValue } from "react-hook-form";
import type { AllPath } from "./AllPath";
type $Path<S extends Document, P extends string = string> = `$${AllPath<S>}`;
type PathOf$Path<P extends string> = P extends `$${infer Path}` ? Path : never;
// type DeepRecord<Path extends string, Value> = Path extends `${infer Head}.${infer Tail}`
// ? { [K in Head]: DeepRecord<Tail, Value> }
// : { [K in Path]: Value };
type $Value<S extends Document, P extends string = string> = any;

type Expression<S extends Document> = any;
type $Set<S extends Document> = {
[P in keyof S]?: Expression<S>;
} & Record<string, Expression<S>>;
type $SetResult<S extends Document, Set extends $Set<S>> = S & {
[P in keyof Set]?: Set[P] extends `$${infer Path extends string}`
? Path extends string
? $Value<S, Path>
: any
: Set[P];
[P in keyof Set]?: Set[P] extends `$${infer P extends FieldPath<S>}` ? FieldPathValue<S, P> : Set[P];
};
type $Unset<S extends Document> = {
[P in keyof S]?: 1 | 0;
Expand Down Expand Up @@ -217,7 +188,9 @@ type Stages<S extends Document> = {
* $unset is an alias for $project stage that removes fields. */
unset<I extends string | string[]>(i: I): StageBuilder<Omit<S, I extends any[] ? I[number] : I>>;
/** Deconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array. */
unwind: <P extends FieldArrayPath<S> = FieldArrayPath<S>, I extends `$${P}` = `$${P}`>(i: I) => StageBuilder<S>;
unwind: <P extends FieldArrayPath<S>>(
i: `$${P}`,
) => StageBuilder<S & { [k in P]: FieldArrayPathValue<S, k>[number] }>;
/** Performs an ANN search on a vector in the specified field of an Atlas collection.
* New in version 7.0.2. */
vectorSearch<I extends Document>(i: I): StageBuilder<S>;
Expand Down
10 changes: 7 additions & 3 deletions src/CNRepos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,26 @@ export type CustomNodeRepo = {

/** @deprecated use cr_ids or on_registry */
cr?: Pick<WithId<CRNode>, "_id" | "id" | "name">;

cr_ids?: ObjectId[];
on_registry?: Task<boolean>; // check if cr_ids is not empty

/** @deprecated use cm_ids */
cm?: Pick<WithId<CMNode>, "_id" | "id" | "title">;
cm_ids?: ObjectId[];

// cache
pulls?: Task<GithubPullParsed[]>;
/** @deprecated use CRPulls */

crPulls?: Task<CRPull[]>;

/** @deprecated TODO: NOT IMPLEMENTD */
crPull_ids: ObjectId[];

candidate?: Task<boolean>;
// createFork?: Task<GithubRepo>;
// createBranches?: Task<{ type: CRType; assigned: Worker } & PushedBranch>[];

/** @deprecated use CRPulls.pull */
createdPulls?: Task<GithubPullParsed[]>;
};
Expand Down
1 change: 1 addition & 0 deletions src/analyzePullsStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function analyzePullsStatusPipeline() {
.set({ "crPulls.data.pull.on_registry": "$on_registry" })
.set({ "crPulls.data.pull.type": "$crPulls.data.type" })
.set({ "crPulls.data.pull.comments": "$crPulls.data.comments.data" })
.set({ "crPulls.data.pull": "$crPulls.data.pull" })
.replaceRoot({ newRoot: "$crPulls.data.pull" })
.as<
CRPull & {
Expand Down
2 changes: 1 addition & 1 deletion src/analyzeTotals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function analyzeTotals() {
"on Registry": { $sum: { $cond: [{ $eq: [{ $type: "$cr" }, "missing"] }, 0, 1] } },
Archived: { $sum: { $cond: ["$info.data.archived", 1, 0] } },
All: { $sum: 1 },
Candidates: { $sum: { $cond: ["$candidate.data", 1, 0] } },
// Candidates: { $sum: { $cond: ["$candidate.data", 1, 0] } },
"Got ERROR on creating PR": { $sum: { $cond: [{ $eq: ["$createdPulls.state", "error"] }, 1, 0] } },
})
.project({ _id: 0 })
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ if (import.meta.main) {
initializeFollowRules(),
updateCNRepos(),
]);
// second round
await Promise.all([
// try send msgs that didn't send in last run
updateSlackMessages(),
checkComfyActivated(), // needed if make pr
initializeFollowRules(),
updateCNRepos(),
]);
console.log("All done");
process.exit(0);
}
30 changes: 16 additions & 14 deletions src/updateCNReposPRCandidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ if (import.meta.main) {
peekYaml(
await $pipeline(CNRepos)
.match(
peekYaml(
$filaten({
crPulls: { mtime: $stale("7d") },
// info: { mtime: $fresh("7d"), data: { private: false, archived: false } },
// createdPulls: { mtime: $stale("7d"), data: { $exists: false } },
}),
),
$filaten({
crPulls: { mtime: $stale("7d") },
// info: { mtime: $fresh("7d"), data: { private: false, archived: false } },
// createdPulls: { mtime: $stale("7d"), data: { $exists: false } },
}),
)
.aggregate()
.map((e) => ({
Expand All @@ -55,13 +53,17 @@ if (import.meta.main) {

export async function updateCNReposPRCandidate() {
return await pMap(
CNRepos.find(
$filaten({
crPulls: { mtime: $fresh("1d"), ...$OK },
info: { mtime: $fresh("7d"), ...$OK, data: { private: false, archived: false } },
candidate: { mtime: $stale("7d") },
}),
),
$pipeline(CNRepos)
.match(
$filaten({
crPulls: { mtime: $fresh("1d"), ...$OK },
// info: { mtime: $fresh("7d"), ...$OK, data: { private: false, archived: false } },
info: { mtime: $fresh("7d"), ...$OK },
// createdPulls: { state: { $ne: "ok" }, mtime: $stale("5m") },
candidate: { mtime: $stale("1d") },
}),
)
.aggregate(),
async (repo) => {
const crPulls = match(repo.crPulls)
.with($OK, (e) => e.data)
Expand Down

0 comments on commit 83c791e

Please sign in to comment.