6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
75 lines
2.4 KiB
TypeScript
75 lines
2.4 KiB
TypeScript
/**
|
|
* Shared plumbing for the GitHub GraphQL tools: the endpoint, its headers, and
|
|
* the two response shapes every query has to handle the same way.
|
|
*/
|
|
|
|
import { isRecord, readGitHubErrorMessage } from '@/tools/github/response-parsers'
|
|
|
|
export const GITHUB_GRAPHQL_URL = 'https://api.github.com/graphql'
|
|
|
|
/** The largest page GitHub's GraphQL connections accept for a `first` argument. */
|
|
export const GITHUB_GRAPHQL_MAX_PAGE_SIZE = 100
|
|
|
|
export function githubGraphQlHeaders(apiKey: string): Record<string, string> {
|
|
return {
|
|
Authorization: `Bearer ${apiKey}`,
|
|
'Content-Type': 'application/json',
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Reads the `data` payload of a GitHub GraphQL response.
|
|
*
|
|
* GitHub answers a failed query with HTTP 200 and an `errors` array, so an ok
|
|
* response is not a successful query — a caller that only checked the status
|
|
* would read a permission failure as an empty result. Throws on either failure
|
|
* shape rather than returning a partial payload.
|
|
*/
|
|
export async function readGraphQlData(
|
|
response: Response,
|
|
context: string
|
|
): Promise<Record<string, unknown>> {
|
|
if (!response.ok) {
|
|
throw new Error(
|
|
(await readGitHubErrorMessage(response)) ?? `${context} failed (HTTP ${response.status})`
|
|
)
|
|
}
|
|
|
|
const payload: unknown = await response.json()
|
|
if (!isRecord(payload)) throw new Error(`${context} must be an object`)
|
|
|
|
const errors = payload.errors
|
|
if (Array.isArray(errors) && errors.length > 0) {
|
|
const first: unknown = errors[0]
|
|
const message =
|
|
isRecord(first) && typeof first.message === 'string' && first.message.trim()
|
|
? first.message
|
|
: 'unknown GraphQL error'
|
|
throw new Error(`${context} returned an error: ${message}`)
|
|
}
|
|
|
|
const data = payload.data
|
|
if (!isRecord(data)) throw new Error(`${context}.data must be an object`)
|
|
return data
|
|
}
|
|
|
|
/**
|
|
* Reads a `pageInfo` block, tolerating GitHub's `endCursor: null` on the last
|
|
* page.
|
|
*/
|
|
export function parsePageInfo(
|
|
value: unknown,
|
|
context: string
|
|
): { hasNextPage: boolean; endCursor: string | null } {
|
|
if (!isRecord(value)) throw new Error(`${context} must be an object`)
|
|
const hasNextPage = value.hasNextPage
|
|
if (typeof hasNextPage !== 'boolean') {
|
|
throw new Error(`${context}.hasNextPage must be a boolean`)
|
|
}
|
|
const endCursor = value.endCursor
|
|
if (endCursor !== null && typeof endCursor !== 'string') {
|
|
throw new Error(`${context}.endCursor must be a string or null`)
|
|
}
|
|
return { hasNextPage, endCursor }
|
|
}
|