diff --git a/src/components/login.tsx b/src/components/login.tsx index d4101ef..f9c74ef 100644 --- a/src/components/login.tsx +++ b/src/components/login.tsx @@ -1,6 +1,7 @@ import { Suspense } from "hono/jsx"; import { useRequestContext } from "hono/jsx-renderer"; import { Octokit } from "octokit"; +import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; import { getAuthenticatedUser } from "../utils/octokit"; @@ -13,7 +14,13 @@ const LoginButton = () => { ); }; -const User = async ({ user }: { user: Promise }) => { +const User = async ({ + user, +}: { + user: Promise< + RestEndpointMethodTypes["users"]["getAuthenticated"]["response"] + >; +}) => { try { const c = useRequestContext(); const { path } = c.req; diff --git a/src/components/repository.tsx b/src/components/repository.tsx index ffff4a2..27bfa96 100644 --- a/src/components/repository.tsx +++ b/src/components/repository.tsx @@ -1,5 +1,6 @@ import { JSX } from "hono/jsx/jsx-runtime"; import { Suspense } from "hono/jsx"; +import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; import { timeAgo, dateOptions } from "../utils/time"; import { constructUrl } from "../utils/url"; @@ -7,7 +8,9 @@ import { constructUrl } from "../utils/url"; export const Repository = async ({ repository, }: { - repository: Promise; + repository: Promise< + RestEndpointMethodTypes["repos"]["get"]["response"]["data"] + >; }) => { return ( {"prout"}}> @@ -19,7 +22,7 @@ export const Repository = async ({ const Container = ({ repository, }: { - repository: RepositoryResponse["data"]; + repository: RestEndpointMethodTypes["repos"]["get"]["response"]["data"]; }): JSX.Element => { const { id, diff --git a/src/global.d.ts b/src/global.d.ts index d604744..6a56dad 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,13 +1,5 @@ import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; -declare global { - type RepositoriesResponse = - RestEndpointMethodTypes["repos"]["listPublic"]["response"]; - type RepositoryResponse = RestEndpointMethodTypes["repos"]["get"]["response"]; - type UserResponse = - RestEndpointMethodTypes["users"]["getAuthenticated"]["response"]; -} - declare module "hono" { interface ContextRenderer { ( diff --git a/src/routes/api.tsx b/src/routes/api.tsx index 3cb7374..0f82215 100644 --- a/src/routes/api.tsx +++ b/src/routes/api.tsx @@ -28,13 +28,13 @@ app.use(handleTokens); app.use(apiAuth); /* SWAGGER */ -app.doc("/swagger/json", swaggerDoc); -app.get("/swagger", swaggerUI({ url: `/api/swagger/json`, version: "3.1" })); +app.doc("/swagger.json", swaggerDoc); +app.get("/swagger", swaggerUI({ url: `/api/swagger.json`, version: "3.1" })); /* ROUTES */ const route = createRoute({ method: "get", - path: "/{id}", + path: "/{id}?", request: { params: ParamsSchema, }, diff --git a/src/utils/octokit.tsx b/src/utils/octokit.tsx index e2af799..cbadf69 100644 --- a/src/utils/octokit.tsx +++ b/src/utils/octokit.tsx @@ -2,6 +2,7 @@ import { Context, Next } from "hono"; import { getCookie } from "hono/cookie"; import { createMiddleware } from "hono/factory"; import { Octokit } from "octokit"; +import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; import { version } from "../../package.json"; import { Bindings, Variables } from ".."; @@ -93,12 +94,12 @@ export const getOctokitInstance = ( * @async @function getRepositories * @param {Octokit} octokit - The Octokit instance for GitHub API. * @param {number} since - The ID to start fetching repositories from. - * @returns {Promise} A promise that resolves to the response containing an array of repositories. + * @returns {Promise} A promise that resolves to the response containing an array of repositories. */ const getRepositories = async ( octokit: Octokit, since: number -): Promise => { +): Promise => { try { return octokit.rest.repos.listPublic({ since }); // octokit.request("GET /repositories", { since }); } catch (error: any) { @@ -112,13 +113,13 @@ const getRepositories = async ( * @param {Octokit} octokit - The Octokit instance for GitHub API. * @param {string} owner - The owner of the repository. * @param {string} repo - The name of the repository. - * @returns {Promise<>} A promise that resolves to the response containing the repository information. + * @returns {Promise} A promise that resolves to the response containing the repository information. */ export const getRepos = async ( octokit: Octokit, owner: string, repo: string -): Promise => { +): Promise => { try { return octokit.rest.repos.get({ owner, repo }); // octokit.request("GET /repos/{owner}/{repo}", { owner, repo }); } catch (error: any) { @@ -131,12 +132,12 @@ export const getRepos = async ( * @async @function getRepository * @param {Octokit} octokit - The Octokit instance for GitHub API. * @param {number} id - The ID of the repository to retrieve. - * @returns {Promise} A promise that resolves to the requested repository. + * @returns {Promise} A promise that resolves to the requested repository. */ export const getRepository = async ( octokit: Octokit, id: number -): Promise => { +): Promise => { try { const { data, status, url } = await getRepositories( octokit, @@ -167,12 +168,12 @@ export const getRepository = async ( * @async @function getRandomRepository * @param {Octokit} octokit - The Octokit instance for GitHub API. * @param {number} maxId - The maximum ID to consider for repository selection. - * @returns {Promise} A promise that resolves to the selected repository. + * @returns {Promise} A promise that resolves to the selected repository. */ export const getRandomRepository = async ( octokit: Octokit, maxId: number -): Promise => { +): Promise => { try { const maxIterations = 10; // max iterations for (let loop = 0; loop < maxIterations; loop++) { @@ -225,11 +226,13 @@ export const fetchRepositoryData = async ( * Asynchronously retrieves the authenticated user's information using the provided Octokit instance. * @async @function getAuthenticatedUser * @param {Octokit} octokit - The Octokit instance for GitHub API. - * @returns {Promise} A Promise that resolves to the user's information response. + * @returns {Promise} A Promise that resolves to the user's information response. */ export const getAuthenticatedUser = async ( octokit: Octokit -): Promise => { +): Promise< + RestEndpointMethodTypes["users"]["getAuthenticated"]["response"] +> => { try { return octokit.rest.users.getAuthenticated(); // octokit.request("GET /user"); } catch (error: any) { diff --git a/src/utils/renderer.tsx b/src/utils/renderer.tsx index 31ec85f..6534bdd 100644 --- a/src/utils/renderer.tsx +++ b/src/utils/renderer.tsx @@ -2,6 +2,7 @@ import { jsxRenderer } from "hono/jsx-renderer"; import { PropsWithChildren, Suspense } from "hono/jsx"; import { JSX } from "hono/jsx/jsx-runtime"; import { useRequestContext } from "hono/jsx-renderer"; +import { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods"; import { fetchRepositoryData } from "./octokit"; import { Loader } from "../components/loader"; @@ -10,7 +11,9 @@ import { Login } from "../components/login"; const Head = ({ repository, }: { - repository: Promise; + repository: Promise< + RestEndpointMethodTypes["repos"]["get"]["response"]["data"] + >; }) => { const full_name = fetchRepositoryData(repository, "full_name"); return (