import type { ConsumerSupportBundleGhResult, } from './consumer-support-bundle-gh-command-lib'; import type { ConsumerSupportBundleRepoActionsPermissionsResponse, ConsumerSupportBundleRepoResponse, ConsumerSupportBundleUserActionsBillingResponse, } from './consumer-support-bundle-contract'; import { tryRunGh, tryRunGhJson } from './consumer-support-bundle-gh-command-lib'; import { extractRepoOwner } from './consumer-startup-failure-support-bundle-lib'; export const ensureConsumerSupportBundleAuth = (): string => { const auth = tryRunGh(['auth', 'status']); if (!auth.ok) { throw new Error(`gh auth status failed: ${auth.error}`); } return auth.output ?? ''; }; export const loadConsumerSupportBundleRepoInfo = ( repo: string ): ConsumerSupportBundleGhResult => { return tryRunGhJson(['api', `repos/${repo}`]); }; export const loadConsumerSupportBundleActionsPermissions = ( repo: string ): ConsumerSupportBundleGhResult => { return tryRunGhJson([ 'api', `repos/${repo}/actions/permissions`, ]); }; export const loadConsumerSupportBundleBillingInfo = ( repo: string ): ConsumerSupportBundleGhResult => { const owner = extractRepoOwner(repo); if (!owner) { return { ok: false, error: 'Unable to detect repository owner for billing probe (expected owner/repo).', }; } return tryRunGhJson([ 'api', `users/${owner}/settings/billing/actions`, ]); };