diff --git a/app/api/repos/route.ts b/app/api/repos/route.ts index b1bdbe9..5e5c8ba 100644 --- a/app/api/repos/route.ts +++ b/app/api/repos/route.ts @@ -40,3 +40,14 @@ export async function POST(request: Request) { const finalRes = JSON.stringify(formattedRes, null, 2) return NextResponse.json(finalRes); } + +export async function GET(request: Request) { + + const { searchParams } = new URL(request.url) + const userName = searchParams.get('userName') + console.log('userName', userName) + + const res = await (await fetch(`https://api.github.com/users/${userName}/repos`)).json() + + return NextResponse.json(res); +} diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..339869d --- /dev/null +++ b/app/dashboard/page.tsx @@ -0,0 +1,68 @@ +async function getData() { + const res = await fetch("https://api.github.com/users/lexmin0412/repos"); + // The return value is *not* serialized + // You can return Date, Map, Set, etc. + + if (!res.ok) { + // This will activate the closest `error.js` Error Boundary + throw new Error("Failed to fetch data"); + } + + const repoList = await res.json(); + + return repoList?.map((item) => { + return { + name: item.name, + description: item.description, + href: item.html_url, + }; + }); +} + +interface IItemProps { + name: string; + href: string; + description: string; +} + +const Item = (props: IItemProps) => { + return ( +
+
+ +
+
+
+
+
{props.name}
+
+ +
+

{props.description}

+
+
+ ); +}; + +export default async function Dashboard() { + const item = { + name: "名称", + description: "描述", + href: "/", + }; + + const data = await getData(); + + console.log("data11", data); + + return ( +
+ {data.map((item) => { + return ; + })} +
+ ); +} diff --git a/app/globals.css b/app/globals.css index 875c01e..d803fdd 100644 --- a/app/globals.css +++ b/app/globals.css @@ -17,6 +17,7 @@ } body { + height: 100vh; color: rgb(var(--foreground-rgb)); background: linear-gradient( to bottom, diff --git a/app/layout.tsx b/app/layout.tsx index d60b8fc..04905d4 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,10 @@ import type { Metadata } from "next"; import { Inter } from "next/font/google"; +import IconGithub from "./../components/icons/github"; +import Logo from "../assets/logo.png"; +import Image from "next/image"; import "./globals.css"; +import Sidebar from "@/components/sidebar"; const inter = Inter({ subsets: ["latin"] }); @@ -14,9 +18,29 @@ export default function RootLayout({ }: Readonly<{ children: React.ReactNode; }>) { + return ( - - {children} - - ); + + +
+
+ Woodpecker Logo + + + +
+ +
+ +
+
+ +
+
{children}
+
+ + + ); } diff --git a/app/page.tsx b/app/page.tsx index 96f0d64..c610b51 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,39 +1,92 @@ -import Editor from "@/components/editor"; import React from "react"; -console.log('process.cwd', process.cwd()) +console.log("process.cwd", process.cwd()); export default async function Home() { + return ( +
+
+
+ Your Company +

+ Github 登录 +

+
- return ( -
-
- - - Woodpecker - - - -
+
+
+
+ +
+ +
+
-
- 你的代码仓库健康检查工具。 -
+
+
+ + +
+
+ +
+
- -
- ); +
+ +
+ + +

+ 不是 Github 项目?{" "} + + 使用其他方式 + +

+
+
+
+ ); } diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000..0429cde Binary files /dev/null and b/assets/logo.png differ diff --git a/components/editor.tsx b/components/editor.tsx index ecfdc4b..4dc5dc9 100644 --- a/components/editor.tsx +++ b/components/editor.tsx @@ -1,80 +1,137 @@ "use client"; import fetch from "@toolkit-fe/request"; -import {useEffect, useRef, useState} from "react"; +import { useEffect, useRef, useState } from "react"; interface EditorProps { - // onGen: () => void; + // onGen: () => void; } export default function Editor(props: EditorProps) { - const userNameRef = useRef(null); const repoNameRef = useRef(null); const contentRef = useRef(null); const [content, setContent] = useState(""); - const getRepoReadme = (userName: string, repoName: string) => { - return fetch( - `https://api.github.com/repos/${userName}/${repoName}/readme`, - { - headers: { - "Content-Type": "application/json", - }, - } - ).then((res: any) => { - if (res.message === "Not Found") { - throw new Error( - `https://api.github.com/repos/${userName}/${repoName}/readme.md 指向的文件不存在, 请确保仓库中存在该文件` - ); - } - return Buffer.from(res.content, "base64").toString(); - }); - }; + const getRepoReadme = (userName: string, repoName: string) => { + return fetch( + `https://api.github.com/repos/${userName}/${repoName}/readme`, + { + headers: { + "Content-Type": "application/json", + }, + } + ).then((res: any) => { + if (res.message === "Not Found") { + throw new Error( + `https://api.github.com/repos/${userName}/${repoName}/readme.md 指向的文件不存在, 请确保仓库中存在该文件` + ); + } + return Buffer.from(res.content, "base64").toString(); + }); + }; - async function handleClick() { - console.log('fetch begin') - // const result = await getRepoReadme("lexmin0412", "woodpecker"); + async function handleClick() { + console.log("fetch begin"); + // const result = await getRepoReadme("lexmin0412", "woodpecker"); // props.onGen() - const result = await fetch("/api/repos", { + const result = (await fetch("/api/repos", { method: "post", body: JSON.stringify({ userName: userNameRef.current?.value, repoName: repoNameRef.current?.value, }), - }) as string - console.log("result", result); + })) as string; + console.log("result", result); setContent(result); if (contentRef.current) { console.log("contentRef.current", contentRef.current); contentRef.current.value = result; } - } + } - return ( -
-
- -
/
- +
+ Your Company +

+ Sign in to your account +

- -
- 结果: -