import type { Database } from "bun:sqlite";
type Row = Record<string, string | number | null>;
function insert(db: Database, table: string, row: Row): void {
const columns = Object.keys(row);
db.query(`INSERT INTO ${table} (${columns.join(", ")}) VALUES (${columns.map(() => "?").join(", ")})`).run(
...Object.values(row),
);
}
/** A workflow run with every NOT NULL column of the RepoState schema filled; override what the test needs. */
export function seedRun(db: Database, row: Row & { id: string; repo_id: string }): void {
insert(db, "workflow_runs", {
source_repo_id: row.repo_id,
run_number: 1,
workflow_path: ".gitfor/workflows/ci.yml",
workflow_name: "CI",
event: "push",
ref: "refs/heads/main",
sha: "a".repeat(40),
title: "t",
status: "in_progress",
created_at: 0,
...row,
});
}
export function seedJob(db: Database, row: Row & { id: string; run_id: string; repo_id: string }): void {
insert(db, "workflow_jobs", {
job_key: row.id,
name: row.id,
runs_on: '["ubuntu-latest"]',
spec: "{}",
status: "in_progress",
created_at: 0,
...row,
});
}