import { browser } from "$app/environment"; import type { PipelineSummary } from "$lib/components/repo/types"; export type CommitStatuses = Record; // the server has no spindle session, resolve empty so the boundary doesn't hang const none: Promise = Promise.resolve({}); export const commitStatuses = ( spindle: string | undefined, ownerHandle: string, repoName: string, shas: string[] ): Promise | undefined => { // only repos with a spindle run CI if (!spindle || shas.length === 0) return undefined; if (!browser) return none; const params = new URLSearchParams(); for (const sha of new Set(shas)) params.append("sha", sha); const path = `/${encodeURIComponent(ownerHandle)}/${encodeURIComponent(repoName)}/commit-statuses?${params}`; return fetch(path) .then((res) => (res.ok ? (res.json() as Promise) : ({} as CommitStatuses))) .catch(() => ({})); };