From d28eb8887e43d4d6dd2f74983b6de37e7a17fa89 Mon Sep 17 00:00:00 2001 From: Catherine Lee Date: Fri, 11 Jul 2025 11:34:08 -0700 Subject: [PATCH] tc --- torchci/components/commit/CommitInfo.tsx | 61 +++++++++++++++++++ .../[repoOwner]/[repoName]/commit/[sha].tsx | 61 +------------------ .../[repoName]/pull/[prNumber].tsx | 58 +----------------- 3 files changed, 66 insertions(+), 114 deletions(-) create mode 100644 torchci/components/commit/CommitInfo.tsx diff --git a/torchci/components/commit/CommitInfo.tsx b/torchci/components/commit/CommitInfo.tsx new file mode 100644 index 0000000000..6a4ffae5dd --- /dev/null +++ b/torchci/components/commit/CommitInfo.tsx @@ -0,0 +1,61 @@ +import CommitStatus from "components/commit/CommitStatus"; +import { fetcher } from "lib/GeneralUtils"; +import { CommitApiResponse } from "pages/api/[repoOwner]/[repoName]/commit/[sha]"; +import { IssueLabelApiResponse } from "pages/api/issue/[label]"; +import useSWR from "swr"; + +export function CommitInfo({ + repoOwner, + repoName, + sha, + isCommitPage, +}: { + repoOwner: string; + repoName: string; + sha: string; + isCommitPage: boolean; +}) { + const { data: commitData, error } = useSWR( + sha && `/api/${repoOwner}/${repoName}/commit/${sha}`, + fetcher, + { + refreshInterval: 60 * 1000, // refresh every minute + // Refresh even when the user isn't looking, so that switching to the tab + // will always have fresh info. + refreshWhenHidden: true, + } + ); + + const { data: unstableIssuesData } = useSWR( + `/api/issue/unstable`, + fetcher, + { + dedupingInterval: 300 * 1000, + refreshInterval: 300 * 1000, // refresh every 5 minutes + } + ); + + if (error != null) { + return
Error occured
; + } + + if (commitData === undefined) { + return
Loading...
; + } + + const { commit, jobs } = commitData; + + return ( +
+ {isCommitPage &&

{commit.commitTitle}

} + +
+ ); +} diff --git a/torchci/pages/[repoOwner]/[repoName]/commit/[sha].tsx b/torchci/pages/[repoOwner]/[repoName]/commit/[sha].tsx index 438012912c..94b6b5b3a9 100644 --- a/torchci/pages/[repoOwner]/[repoName]/commit/[sha].tsx +++ b/torchci/pages/[repoOwner]/[repoName]/commit/[sha].tsx @@ -1,64 +1,6 @@ -import CommitStatus from "components/commit/CommitStatus"; +import { CommitInfo } from "components/commit/CommitInfo"; import { useSetTitle } from "components/layout/DynamicTitle"; -import { fetcher } from "lib/GeneralUtils"; import { useRouter } from "next/router"; -import { CommitApiResponse } from "pages/api/[repoOwner]/[repoName]/commit/[sha]"; -import { IssueLabelApiResponse } from "pages/api/issue/[label]"; -import useSWR from "swr"; - -export function CommitInfo({ - repoOwner, - repoName, - sha, -}: { - repoOwner: string; - repoName: string; - sha: string; -}) { - const { data: commitData, error } = useSWR( - `/api/${repoOwner}/${repoName}/commit/${sha}`, - fetcher, - { - refreshInterval: 60 * 1000, // refresh every minute - // Refresh even when the user isn't looking, so that switching to the tab - // will always have fresh info. - refreshWhenHidden: true, - } - ); - - const { data: unstableIssuesData } = useSWR( - `/api/issue/unstable`, - fetcher, - { - dedupingInterval: 300 * 1000, - refreshInterval: 300 * 1000, // refresh every 5 minutes - } - ); - - if (error != null) { - return
Error occured
; - } - - if (commitData === undefined) { - return
Loading...
; - } - - const { commit, jobs } = commitData; - - return ( -
-

{commit.commitTitle}

- -
- ); -} export default function Page() { const router = useRouter(); @@ -86,6 +28,7 @@ export default function Page() { repoOwner={repoOwner as string} repoName={repoName as string} sha={sha as string} + isCommitPage={true} /> )} diff --git a/torchci/pages/[repoOwner]/[repoName]/pull/[prNumber].tsx b/torchci/pages/[repoOwner]/[repoName]/pull/[prNumber].tsx index 099ffd216e..b1830bcd15 100644 --- a/torchci/pages/[repoOwner]/[repoName]/pull/[prNumber].tsx +++ b/torchci/pages/[repoOwner]/[repoName]/pull/[prNumber].tsx @@ -1,67 +1,14 @@ import { Stack } from "@mui/material"; -import CommitStatus from "components/commit/CommitStatus"; +import { CommitInfo } from "components/commit/CommitInfo"; import DrCIButton from "components/common/DrCIButton"; import ErrorBoundary from "components/common/ErrorBoundary"; import { useSetTitle } from "components/layout/DynamicTitle"; +import { fetcher } from "lib/GeneralUtils"; import { PRData } from "lib/types"; import { useRouter } from "next/router"; -import { CommitApiResponse } from "pages/api/[repoOwner]/[repoName]/commit/[sha]"; -import { IssueLabelApiResponse } from "pages/api/issue/[label]"; import { useEffect, useState } from "react"; import useSWR from "swr"; -const fetcher = (url: string) => fetch(url).then((res) => res.json()); - -function CommitInfo({ - repoOwner, - repoName, - sha, -}: { - repoOwner: string; - repoName: string; - sha: string; -}) { - const { data: commitData, error } = useSWR( - sha != null ? `/api/${repoOwner}/${repoName}/commit/${sha}` : null, - fetcher, - { - refreshInterval: 60 * 1000, // refresh every minute - // Refresh even when the user isn't looking, so that switching to the tab - // will always have fresh info. - refreshWhenHidden: true, - } - ); - - const { data: unstableIssuesData } = useSWR( - `/api/issue/unstable`, - fetcher, - { - dedupingInterval: 300 * 1000, - refreshInterval: 300 * 1000, // refresh every 5 minutes - } - ); - - if (error != null) { - return
Error occurred
; - } - - if (commitData === undefined) { - return
Loading...
; - } - const { commit, jobs } = commitData; - - return ( - - ); -} - function CommitHeader({ repoOwner, repoName, @@ -171,6 +118,7 @@ function Page() { repoOwner={repoOwner as string} repoName={repoName as string} sha={selectedSha} + isCommitPage={false} /> )}