From 1522e993cd507e6a06f2831fc62333c0d09f07e6 Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Thu, 25 Dec 2025 22:51:46 +0000 Subject: [PATCH] code: tsx,nextjs,githubactionsfetcher (1 files) --- .../src/components/GitHubActionsFetcher.tsx | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/frontends/nextjs/src/components/GitHubActionsFetcher.tsx b/frontends/nextjs/src/components/GitHubActionsFetcher.tsx index 84bd7d190..e53fbb93e 100644 --- a/frontends/nextjs/src/components/GitHubActionsFetcher.tsx +++ b/frontends/nextjs/src/components/GitHubActionsFetcher.tsx @@ -63,27 +63,31 @@ export function GitHubActionsFetcher() { setNeedsAuth(false) try { - // TODO: Replace with proper GitHub OAuth authentication in Next.js - // For now, use Octokit without authentication (rate limited) - // const user = await spark.user() - - // if (!user || !user.id) { - // setNeedsAuth(true) - // throw new Error('GitHub authentication required') - // } + const response = await fetch('/api/github/actions/runs', { cache: 'no-store' }) + let payload: { owner?: string; repo?: string; runs?: WorkflowRun[]; fetchedAt?: string; requiresAuth?: boolean } | null = null - const octokit = new Octokit() - - const { data: workflows } = await octokit.rest.actions.listWorkflowRunsForRepo({ - owner: 'johndoe6345789', - repo: 'metabuilder', - per_page: 20 - }) + try { + payload = await response.json() + } catch (parseError) { + payload = null + } - setData(workflows.workflow_runs as WorkflowRun[]) - setLastFetched(new Date()) + if (!response.ok) { + if (payload?.requiresAuth) { + setNeedsAuth(true) + } + const message = payload?.error || `Failed to fetch workflow runs (${response.status})` + throw new Error(message) + } + + const runs = payload?.runs || [] + setData(runs) + if (payload?.owner && payload?.repo) { + setRepoInfo({ owner: payload.owner, repo: payload.repo }) + } + setLastFetched(payload?.fetchedAt ? new Date(payload.fetchedAt) : new Date()) setSecondsUntilRefresh(30) - toast.success(`Fetched ${workflows.workflow_runs.length} workflow runs`) + toast.success(`Fetched ${runs.length} workflow runs`) } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred' setError(errorMessage)