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

GithubAction Update #19

Merged
merged 11 commits into from
Jan 21, 2025
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Run Comfy-PR Tests.

on:
push:
- main
jobs:
run_comfy_pr:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion app/(dashboard)/followup/actions/send-gmail/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// /followup/actions/email

import { getAuthUser } from "@/app/(dashboard)/rules/getAuthUser";
import { getAuthUser } from "@/app/api/auth/[...nextauth]/getAuthUser";
import { TaskDataOrNull, TaskError, TaskErrorOrNull, TaskOK } from "@/packages/mongodb-pipeline-ts/Task";
import { GCloudOAuth2Credentials, getGCloudOAuth2Client } from "@/src/gcloud/GCloudOAuth2Credentials";
import { sendGmail } from "@/src/sendGmail";
Expand Down
16 changes: 2 additions & 14 deletions app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Link from "next/link";
import { Header } from "../Components/Header";

/**
*
Expand All @@ -7,19 +7,7 @@ import Link from "next/link";
export default function ComponentLayout({ children }: { children: React.ReactNode }) {
return (
<div className="w-full min-h-screen flex bg-cyan-800 card-body text-white gap-8">
<header className="flex w-full gap-4 flex-wrap">
<Link href="/">
<h1 className="text-5xl">Comfy-PR</h1>
</Link>
<nav className="flex gap-2 flex-wrap">
<Link href="/details" className="text-2xl">
Details
</Link>
<Link href="/rules" className="text-2xl">
Rules
</Link>
</nav>
</header>
<Header />
<div className="shadow-xl bg-cyan-900 text-white w-full card">{children}</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion app/(dashboard)/repos/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function ReposPage() {
);
}

async function DataPage({ page = 0, size = 100 }) {
async function DataPage({ page = 0, size = 10000 }) {
const data = await CNRepos.find({})
.sort({ _id: 1 })
.project({
Expand Down
2 changes: 1 addition & 1 deletion app/(dashboard)/rules/[name]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function FollowRulesPage({ params }: { params: Promise<{ na
name={name}
updateFollowRuleSet={updateFollowRuleSet}
defaultYaml={defaultYaml}
defaultMatchResults={await updateFollowRuleSet({ yaml: defaultYaml, name })}
// defaultMatchResults={await updateFollowRuleSet({ yaml: defaultYaml, name })}
enabled={enabled}
/>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/(dashboard)/rules/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { forbidden } from "next/navigation";
import type { ReactNode } from "react";
import { getAuthUser } from "./getAuthUser";
import { getAuthUser } from "../../api/auth/[...nextauth]/getAuthUser";

export default async function RulesLayout({ children }: { children: ReactNode }) {
const user = await getAuthUser();
// check authorization (permission)
const { admin } = user;
const isAdmin = admin || user.email.endsWith("@drip.art");
if (!isAdmin) return <div>Unauthorized</div>;
const isAdmin = user.admin || user.email.endsWith("@drip.art");
if (!isAdmin) return forbidden();

return (
<div className="flex flex-wrap">
Expand Down
15 changes: 7 additions & 8 deletions app/(dashboard)/totals-chart/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import UseSWRComponent from "use-swr-component";
import { TotalsChartBlock } from "../TotalsBlock";
/**
* @author: snomiao <[email protected]>
*/
export default function TotalsPage() {
return (
<UseSWRComponent props={{}} Component={TotalsChartBlock} refreshInterval={1e3}>
{<TotalsChartBlock />}
</UseSWRComponent>
);
export default function TotalsChartPage() {
return <>Maintaining</>
// return (
// <UseSWRComponent props={{}} Component={TotalsChartBlock} refreshInterval={1e3}>
// {<TotalsChartBlock />}
// </UseSWRComponent>
// );
}
22 changes: 22 additions & 0 deletions app/Components/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Link from "next/link";

export function Header() {
return <header className="flex w-full gap-4 flex-wrap">
<Link href="/">
<h1 className="text-5xl">Comfy-PR</h1>
</Link>
<nav className="flex gap-2 flex-wrap">
<Link href="/details" className="text-2xl">
Details
</Link>
<Link href="/rules" className="text-2xl">
Rules
</Link>
<Link href="/tasks" className="text-2xl">
Tasks
</Link>
</nav>
</header>;
}


File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export async function getAuthUser() {
const authUser = session?.user ?? (await signIn());
const email = authUser.email || (await signIn()); // must have email
const user = { ...{ ...authUser, email }, ...(await Users.findOne({ email })) };
user.admin ||= user.email.endsWith("@drip.art");
return user;
}
2 changes: 1 addition & 1 deletion app/api/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import pkg from "@/package.json";
import { getWorkerInstance } from "@/src/WorkerInstances";
import { analyzePullsStatus } from "@/src/analyzePullsStatus";
import { zPullsStatus } from "@/src/zod/zPullsStatus";
import DIE from "@snomiao/die";
import { initTRPC } from "@trpc/server";
import DIE from "phpdie";
import { type OpenApiMeta } from "trpc-openapi";
import z from "zod";
export const t = initTRPC.meta<OpenApiMeta>().create(); /* 👈 */
Expand Down
104 changes: 104 additions & 0 deletions app/markdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* Additional vertical padding used by kbd tag. */
.py-05 {
padding-top: 0.125rem;
padding-bottom: 0.125rem;
}
.markdown-frame {
@apply bg-white p-1 m-1 rounded-md text-black;
}
.markdown {
@apply text-gray-900 leading-normal break-words;
}

.markdown > * + * {
@apply mt-0 mb-4;
}

.markdown li + li {
@apply mt-1;
}

.markdown li > p + p {
@apply mt-6;
}

.markdown strong {
@apply font-semibold;
}

.markdown a {
@apply text-blue-600 font-semibold;
}

.markdown strong a {
@apply font-bold;
}

.markdown h1 {
@apply leading-tight border-b text-4xl font-semibold mb-4 mt-6 pb-2 text-black;
}

.markdown h2 {
@apply leading-tight border-b text-2xl font-semibold mb-4 mt-6 pb-2 text-black;
}

.markdown h3 {
@apply leading-snug text-lg font-semibold mb-4 mt-6 text-black;
}

.markdown h4 {
@apply leading-none text-base font-semibold mb-4 mt-6 text-black;
}

.markdown h5 {
@apply leading-tight text-sm font-semibold mb-4 mt-6 text-black;
}

.markdown h6 {
@apply leading-tight text-sm font-semibold text-gray-600 mb-4 mt-6;
}

.markdown blockquote {
@apply text-base border-l-4 border-gray-300 pl-4 pr-4 text-gray-600;
}

.markdown code {
@apply font-mono text-sm inline bg-gray-200 rounded px-1 py-05;
}

.markdown pre {
@apply bg-gray-100 rounded p-4;
}

.markdown pre code {
@apply block bg-transparent p-0 overflow-visible rounded-none;
}

.markdown ul {
@apply text-base pl-8 list-disc;
}

.markdown ol {
@apply text-base pl-8 list-decimal;
}

.markdown kbd {
@apply text-xs inline-block rounded border px-1 py-05 align-middle font-normal font-mono shadow;
}

.markdown table {
@apply text-base border-gray-600;
}

.markdown th {
@apply border py-1 px-3;
}

.markdown td {
@apply border py-1 px-3;
}

/* Override pygments style background color. */
.markdown .highlight pre {
@apply bg-gray-100 !important;
}
18 changes: 18 additions & 0 deletions app/tasks-panel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.tasks-panel {
@apply bg-gray-100 rounded-lg;
}
.tasks-panel details {
@apply ml-4;
}
.tasks-panel details > summary > * {
@apply inline ml-4;
}
.tasks-panel h1 {
@apply font-bold text-3xl m-4;
}
.tasks-panel h2 {
@apply font-bold text-xl;
}
.tasks-panel a:hover {
@apply underline;
}
28 changes: 28 additions & 0 deletions app/tasks/GithubActionUpdateTask/ApprovePRButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use client";
import Router from "next/router";
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 });
useEffect(() => {
if (state.ok) Router.reload();
}, [state.ok]);
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} tabIndex={1} className="btn" title="will perform on next run">
{!state.ok ? (
"Approve PR"
) : (
<>
APPROVED
<br /> <span className="text-sm">(Reload page to update the list)</span>
</>
)}
</button>
</form>
);
}
44 changes: 44 additions & 0 deletions app/tasks/GithubActionUpdateTask/actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use server";
import { getAuthUser } from "@/app/api/auth/[...nextauth]/getAuthUser";
import { GithubActionUpdateTask } from "@/src/2025-01-20-GithubActionUpdateTask/GithubActionUpdateTask";
import { z } from "zod";

export async function approveGithubActionUpdateTaskAction(prevState: { ok: boolean }, formData: FormData) {
"use server";
await getAuthUser();
const e = z
.object({
repo: z.string(),
branchVersionHash: z.string(),
})
.parse(Object.fromEntries(formData.entries()));
await approveGithubActionUpdateTask(e.repo, e.branchVersionHash);
return { ok: true };
}
export async function approveGithubActionUpdateTask(repo: string, approvedHash: string) {
"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();
await GithubActionUpdateTask.findOneAndDelete({ repo });
await GithubActionUpdateTask.findOneAndUpdate(
{ repo },
{ $set: { updatedAt: new Date() } },
{ returnDocument: "after" },
);
}
export async function listGithubActionUpdateTask() {
"use server";
await getAuthUser();
return (await GithubActionUpdateTask.find({}).toArray()).map(({ _id, ...e }) => ({
...e,
updatedAt: +(e.updatedAt ?? 0),
}));
}
Loading