Skip to content

Commit

Permalink
Merge pull request #20 from Comfy-Org/mass-pr
Browse files Browse the repository at this point in the history
Mass pr
  • Loading branch information
snomiao authored Jan 25, 2025
2 parents 239ebaf + 287580e commit ee9a86f
Show file tree
Hide file tree
Showing 27 changed files with 424 additions and 165 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Run Comfy-PR Tests.

on:
push:
- main
branches:
- main
jobs:
run_comfy_pr:
runs-on: ubuntu-latest
Expand All @@ -27,4 +28,4 @@ jobs:
- run: docker compose up mongodb -d
# Run Comfy-PR Tests
- run: bun i
- run: bun test
- run: bun test
47 changes: 47 additions & 0 deletions .github/workflows/updateGithubActionTask.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: updateGithubActionTask
on:
schedule:
- cron: "0 */2 * * *" # Runs every 2 hours
workflow_dispatch:
push:
branches:
- main
- mass-pr
paths:
- ".github/workflows/*"
- "src/*.ts"
jobs:
run_comfy_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# this dont need python
# # setup comfy-cli
# - uses: actions/setup-python@v5
# with:
# python-version: "3.x"
# - run: python -m pip install --upgrade pip
# - run: python -m venv .venv
# - run: source .venv/bin/activate
# - run: pip install comfy-cli
# Setup SSH Key for git push
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
# Setup Bun
# - run: pip install setuptools
- uses: oven-sh/setup-bun@v1
# Run Comfy-PR Worker
- run: bun i
- run: bun src/GithubActionUpdateTask/updateGithubActionTask.ts
env:
COMFY_PR_REPO: ${{ secrets.COMFY_PR_REPO }}
FORK_OWNER: "ComfyNodePRs"
FORK_PREFIX: "PR-"
GH_TOKEN_COMFY_PR: ${{ secrets.GH_TOKEN_COMFY_PR }}
MONGODB_URI: ${{ secrets.MONGODB_URI }}
SLACK_BOT_CHANNEL: ${{ secrets.SLACK_BOT_CHANNEL }}
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
AUTH_GOOGLE_ID: ${{ secrets.AUTH_GOOGLE_ID }}
AUTH_GOOGLE_SECRET: ${{ secrets.AUTH_GOOGLE_SECRET }}
AUTH_GCLOUD_URL: https://comfy-pr.vercel.app
17 changes: 1 addition & 16 deletions app/(dashboard)/TotalsBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
"use server";
import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
import { Totals } from "@/src/Totals";
import { updateComfyTotals } from "@/src/updateComfyTotals";
import { yaml } from "@/src/utils/yaml";
import { flatten } from "flat";
import Markdown from "react-markdown";
import { sf } from "sflow";
import { TotalsChart } from "./TotalsChart";

function getTotalsData() {
return sf(
$pipeline(Totals)
.match({ "totals.data": { $exists: true } })
.set({ "totals.data.date": "$totals.mtime" })
.replaceRoot({ newRoot: "$totals.data" })
.aggregate(),
)
.map((e) => flatten(e) as { date: string } & Record<string, number>)
.toArray();
}
import { getTotalsData } from "./getTotalsData";

export async function TotalsBlock() {
"use server";
Expand Down
19 changes: 19 additions & 0 deletions app/(dashboard)/getTotalsData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use server";
import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
import { Totals } from "@/src/Totals";
import { flatten } from "flat";
import sf from "sflow";

export async function getTotalsData() {
return sf(
$pipeline(Totals)
.match({ "totals.data": { $exists: true } })
.match({ "totals.mtime": { $gt: new Date(+new Date() - 86400e3 * 30) } }) // 1 month
.set({ "totals.data.date": "$totals.mtime" })
.replaceRoot({ newRoot: "$totals.data" })
.aggregate(),
)
.map((e) => flatten(e) as { date: string } & Record<string, number>)
.limit(3000)
.toArray();
}
14 changes: 7 additions & 7 deletions app/api/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { type OpenApiMeta } from "trpc-openapi";
import z from "zod";
export const t = initTRPC.meta<OpenApiMeta>().create(); /* 👈 */
export const router = t.router({
// sayHello: t.procedure
// .meta({ openapi: { method: "GET", path: "/say-hello", description: "say hello" } })
// .input(z.object({ name: z.string() }))
// .output(z.object({ greeting: z.string() }))
// .query(({ input }) => {
// return { greeting: `Hello ${input.name} 1!` };
// }),
sayHello: t.procedure
.meta({ openapi: { method: "GET", path: "/say-hello", description: "say hello" } })
.input(z.object({ name: z.string() }))
.output(z.object({ greeting: z.string() }))
.query(({ input }) => {
return { greeting: `Hello ${input.name} 1!` };
}),
version: t.procedure
.meta({ openapi: { method: "GET", path: "/version", description: "Get version of ComfyPR" } })
.input(z.object({}))
Expand Down
4 changes: 4 additions & 0 deletions app/tasks-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
.tasks-panel a:hover {
@apply underline;
}

.btn[aria-busy=true] {
@apply loading;
}
28 changes: 0 additions & 28 deletions app/tasks/GithubActionUpdateTask/ApprovePRButton.tsx

This file was deleted.

38 changes: 38 additions & 0 deletions app/tasks/github-action-update/ApprovePRButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use client";
import "is-hotkey-esm";
import { isHotkey } from "is-hotkey-esm";
import { useRouter } from "next/navigation";
import { useActionState, useEffect } from "react";
import { approveGithubActionUpdateTaskAction } from "./actions";
export function ApprovePRButton(e: { repo: string; branchVersionHash?: string }) {
const [state, formAction, pending] = useActionState(approveGithubActionUpdateTaskAction, { ok: false });
const router = useRouter();
useEffect(() => {
if (state.ok) router.refresh();
}, [state.ok, router]);
return (
<form action={formAction} className="contents">
<input type="hidden" name="repo" value={e.repo} />
<input type="hidden" name="branchVersionHash" value={e.branchVersionHash} />

<button
disabled={pending || !!state.ok}
aria-busy={pending}
className="btn btn-approve"
title="will perform on next run"
onKeyDown={(e) => {
const mv = (offset: number) => {
const btns = [...document.querySelectorAll("button.btn-approve")] as HTMLButtonElement[];
btns[btns.indexOf(e.currentTarget) + offset]?.focus();
e.stopPropagation();
e.preventDefault();
};
if (isHotkey("ArrowUp")(e)) mv(-1);
if (isHotkey("ArrowDown")(e)) mv(1);
}}
>
{!state.ok ? <>Approve PR</> : <>APPROVED</>}
</button>
</form>
);
}
85 changes: 85 additions & 0 deletions app/tasks/github-action-update/ProgressBarChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"use client";

import { EChart } from "@kbox-labs/react-echarts";

// import ReactECharts from "echarts-for-react"; // or var ReactECharts = require('echarts-for-react');
/**
*
* @author: snomiao <[email protected]>
*/
export default function ProgressBarChart({ data }: { data: readonly [string, number, string][] }) {
return (
<>
<EChart
style={{
height: "100px",
width: "100%",
}}
// xAxis={[
// {
// type: "time",
// axisLabel: {
// formatter: function (value) {
// return new Date(value).toISOString().slice(0, 10);
// },
// },
// },
// ]}
// yAxis={{
// type: "value",
// }}
// series={uniq(totalsData.flatMap((e) => Object.keys(omit("date", e)))).map((key) => ({
// type: "line",
// data: totalsData.map((e) => [e.date, e[key] ?? null]),
// }))}
{...{
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow", // 'shadow' as default; can also be 'line' or 'shadow'
},
},
legend: {},
grid: {
left: "0",
right: "0",
bottom: "0",
containLabel: false,
},
xAxis: {
type: "value",
},
yAxis: {
type: "category",
data: ["Progress"],
},
series: data.map(([name, value, color]) => ({
name,
type: "bar",
stack: "total",
label: {
show: true,
},
color,
emphasis: {
focus: "series",
},
data: [value],
})),
}}
/>
{/* <ReactECharts
// option={this.getOption()}
notMerge={true}
lazyUpdate={true}
theme={"theme_name"}
// onChartReady={this.onChartReadyCallback}
// onEvents={EventsDict}
// opts={}
// data={
// }
/> */}
</>
);
}
37 changes: 37 additions & 0 deletions app/tasks/github-action-update/ResetTaskButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";
import "is-hotkey-esm";
import { isHotkey } from "is-hotkey-esm";
import { useRouter } from "next/navigation";
import { useActionState, useEffect } from "react";
import { resetGithubActionUpdateTaskAction } from "./actions";
export function ResetTaskButton(e: { repo: string }) {
const [state, formAction, pending] = useActionState(resetGithubActionUpdateTaskAction, { ok: false });
const router = useRouter();
useEffect(() => {
if (state.ok) router.refresh();
}, [state.ok, router]);
return (
<form action={formAction} className="contents">
<input type="hidden" name="repo" value={e.repo} />

<button
disabled={pending || !!state.ok}
aria-busy={pending || undefined}
className="btn btn-reset"
title="will perform on next run"
onKeyDown={(e) => {
const mv = (offset: number) => {
const btns = [...document.querySelectorAll("button.btn-reset")] as HTMLButtonElement[];
btns[btns.indexOf(e.currentTarget) + offset]?.focus();
e.stopPropagation();
e.preventDefault();
};
if (isHotkey("ArrowUp")(e)) mv(-1);
if (isHotkey("ArrowDown")(e)) mv(1);
}}
>
{!state.ok ? <>RESET</> : <>RESET OK</>}
</button>
</form>
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"use server";
import { getAuthUser } from "@/app/api/auth/[...nextauth]/getAuthUser";
import { GithubActionUpdateTask } from "@/src/2025-01-20-GithubActionUpdateTask/GithubActionUpdateTask";
import { GithubActionUpdateTask } from "@/src/GithubActionUpdateTask/GithubActionUpdateTask";
import { z } from "zod";

export async function resetGithubActionUpdateTaskAction(prevState: { ok: boolean }, formData: FormData) {
"use server";
await getAuthUser();
const e = z.object({ repo: z.string() }).parse(Object.fromEntries(formData.entries()));
await resetErrorForGithubActionUpdateTask(e.repo);
return { ok: true };
}
export async function approveGithubActionUpdateTaskAction(prevState: { ok: boolean }, formData: FormData) {
"use server";
await getAuthUser();
Expand All @@ -16,17 +23,17 @@ export async function approveGithubActionUpdateTaskAction(prevState: { ok: boole
return { ok: true };
}
export async function approveGithubActionUpdateTask(repo: string, approvedHash: string) {
"use server";
await getAuthUser();
// "use server";
// await getAuthUser();
await GithubActionUpdateTask.findOneAndUpdate(
{ repo },
{ $set: { approvedBranchVersionHash: approvedHash, updatedAt: new Date() } },
{ returnDocument: "after" },
);
}
export async function resetErrorForGithubActionUpdateTask(repo: string) {
"use server";
await getAuthUser();
// "use server";
// await getAuthUser();
await GithubActionUpdateTask.findOneAndDelete({ repo });
await GithubActionUpdateTask.findOneAndUpdate(
{ repo },
Expand All @@ -35,8 +42,8 @@ export async function resetErrorForGithubActionUpdateTask(repo: string) {
);
}
export async function listGithubActionUpdateTask() {
"use server";
await getAuthUser();
// "use server";
// await getAuthUser();
return (await GithubActionUpdateTask.find({}).toArray()).map(({ _id, ...e }) => ({
...e,
updatedAt: +(e.updatedAt ?? 0),
Expand Down
Loading

1 comment on commit ee9a86f

@vercel
Copy link

@vercel vercel bot commented on ee9a86f Jan 25, 2025

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

comfy-pr – ./

comfy-pr-drip-ai.vercel.app
comfy-pr-git-main-drip-ai.vercel.app
comfy-pr.vercel.app

Please sign in to comment.