Skip to content
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
11 changes: 11 additions & 0 deletions dashboard/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare global {
namespace App {
interface Platform {
env?: {
WORKER?: { fetch: typeof fetch };
};
}
}
}

export {};
8 changes: 5 additions & 3 deletions dashboard/src/routes/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ interface ProjectWithTrend {
latestCoverage: MetricPoint | null;
}

export const load: PageServerLoad = async ({ fetch, request }) => {
export const load: PageServerLoad = async ({ fetch, request, platform }) => {
const jwt = request.headers.get('Cf-Access-Jwt-Assertion') ?? '';
const workerUrl = (env.WORKER_URL ?? '').replace(/\/$/, '');
if (!workerUrl) throw error(500, 'WORKER_URL is not configured');

const bypass = env.DEV_BYPASS_SECRET ?? '';
const extraHeaders: Record<string, string> = bypass ? { 'x-dev-bypass': bypass } : {};

const projects = await fetchProjects(workerUrl, jwt, fetch, extraHeaders);
const apiFetch = platform?.env?.WORKER?.fetch.bind(platform.env.WORKER) ?? fetch;

const projects = await fetchProjects(workerUrl, jwt, apiFetch, extraHeaders);

const projectsWithTrend: ProjectWithTrend[] = await Promise.all(
projects.map(async (p) => {
Expand All @@ -40,7 +42,7 @@ export const load: PageServerLoad = async ({ fetch, request }) => {
'coverage',
p.default_branch,
20,
fetch,
apiFetch,
extraHeaders,
);
const latest = trend.data.at(-1) ?? null;
Expand Down
8 changes: 5 additions & 3 deletions dashboard/src/routes/[owner]/[repo]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ import { env } from '$env/dynamic/private';
import type { PageServerLoad } from './$types';
import { fetchProjects, fetchTrend } from '$lib/api';

export const load: PageServerLoad = async ({ params, url, fetch, request }) => {
export const load: PageServerLoad = async ({ params, url, fetch, request, platform }) => {
const jwt = request.headers.get('Cf-Access-Jwt-Assertion') ?? '';
const workerUrl = (env.WORKER_URL ?? '').replace(/\/$/, '');
if (!workerUrl) throw error(500, 'WORKER_URL is not configured');

const bypass = env.DEV_BYPASS_SECRET ?? '';
const extraHeaders: Record<string, string> = bypass ? { 'x-dev-bypass': bypass } : {};

const apiFetch = platform?.env?.WORKER?.fetch.bind(platform.env.WORKER) ?? fetch;

const { owner, repo } = params;
const fullSlug = `${owner}/${repo}`;
const metric = url.searchParams.get('metric') ?? 'coverage';

const projects = await fetchProjects(workerUrl, jwt, fetch, extraHeaders);
const projects = await fetchProjects(workerUrl, jwt, apiFetch, extraHeaders);
const project = projects.find((p) => p.full_slug === fullSlug);
if (!project) throw error(404, `Project ${fullSlug} not found`);

const branch = url.searchParams.get('branch') ?? project.default_branch;

let trend;
try {
trend = await fetchTrend(workerUrl, jwt, owner, repo, metric, branch, 100, fetch, extraHeaders);
trend = await fetchTrend(workerUrl, jwt, owner, repo, metric, branch, 100, apiFetch, extraHeaders);
} catch {
trend = { project: fullSlug, branch, metric, data: [] };
}
Expand Down
5 changes: 4 additions & 1 deletion dashboard/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"name": "coverage-tracker-dashboard",
"compatibility_date": "2024-11-01",
"compatibility_flags": ["nodejs_compat"],
"pages_build_output_dir": ".svelte-kit/cloudflare"
"pages_build_output_dir": ".svelte-kit/cloudflare",
"services": [
{ "binding": "WORKER", "service": "coverage-tracker" }
]
}
Loading