|
| 1 | +#!/usr/bin/env bun |
| 2 | + |
| 3 | +import { $ } from "bun" |
| 4 | +import { parseArgs } from "util" |
| 5 | +import { getLatestRelease } from "./changelog" |
| 6 | + |
| 7 | +const paths = [ |
| 8 | + "packages/opencode", |
| 9 | + "packages/sdk", |
| 10 | + "packages/plugin", |
| 11 | + "packages/desktop", |
| 12 | + "packages/app", |
| 13 | + "sdks/vscode", |
| 14 | + "packages/extensions", |
| 15 | + "github", |
| 16 | +] |
| 17 | + |
| 18 | +const clean = (text: string) => text.split("\n").filter(Boolean) |
| 19 | + |
| 20 | +const ref = (value: string, head = false) => { |
| 21 | + if (head && value === "HEAD") return value |
| 22 | + if (value.startsWith("v")) return value |
| 23 | + return `v${value}` |
| 24 | +} |
| 25 | + |
| 26 | +const { values } = parseArgs({ |
| 27 | + args: Bun.argv.slice(2), |
| 28 | + options: { |
| 29 | + from: { type: "string", short: "f" }, |
| 30 | + to: { type: "string", short: "t", default: "HEAD" }, |
| 31 | + base: { type: "string", short: "b", default: "origin/dev" }, |
| 32 | + help: { type: "boolean", short: "h", default: false }, |
| 33 | + }, |
| 34 | +}) |
| 35 | + |
| 36 | +if (values.help) { |
| 37 | + console.log(` |
| 38 | +Usage: bun script/changelog-debug.ts [options] |
| 39 | +
|
| 40 | +Options: |
| 41 | + -f, --from <version> Starting version (default: latest GitHub release) |
| 42 | + -t, --to <ref> Ending ref (default: HEAD) |
| 43 | + -b, --base <ref> Compare base for ahead/behind (default: origin/dev) |
| 44 | + -h, --help Show this help message |
| 45 | +
|
| 46 | +Examples: |
| 47 | + bun script/changelog-debug.ts |
| 48 | + bun script/changelog-debug.ts -f 1.0.200 -t dev |
| 49 | + bun script/changelog-debug.ts -f 1.0.200 -t HEAD -b origin/dev |
| 50 | +`) |
| 51 | + process.exit(0) |
| 52 | +} |
| 53 | + |
| 54 | +const to = values.to! |
| 55 | +const from = values.from ?? (await getLatestRelease()) |
| 56 | +const fromRef = ref(from) |
| 57 | +const toRef = ref(to, true) |
| 58 | + |
| 59 | +console.log(`Debugging changelog range: ${fromRef} -> ${toRef}\n`) |
| 60 | + |
| 61 | +const [ahead, behind] = await $`git rev-list --left-right --count ${values.base}...HEAD` |
| 62 | + .text() |
| 63 | + .then((text) => text.trim().split("\t")) |
| 64 | + |
| 65 | +console.log(`Ahead/behind ${values.base}: ahead=${ahead ?? "0"} behind=${behind ?? "0"}`) |
| 66 | + |
| 67 | +const gh = await $`gh api "/repos/anomalyco/opencode/compare/${fromRef}...${toRef}" --jq '.commits[].sha'` |
| 68 | + .text() |
| 69 | + .then(clean) |
| 70 | + |
| 71 | +const localAll = await $`git log ${fromRef}..${toRef} --oneline --format="%H"`.text().then(clean) |
| 72 | +const localFiltered = await $`git log ${fromRef}..${toRef} --oneline --format="%H" -- ${paths}`.text().then(clean) |
| 73 | + |
| 74 | +const ghSet = new Set(gh) |
| 75 | +const missing = localFiltered.filter((hash) => !ghSet.has(hash)) |
| 76 | + |
| 77 | +console.log(`GitHub compare commits: ${gh.length}`) |
| 78 | +console.log(`Local commits (all): ${localAll.length}`) |
| 79 | +console.log(`Local commits (filtered paths): ${localFiltered.length}`) |
| 80 | +console.log(`Filtered commits missing from GitHub compare: ${missing.length}`) |
| 81 | + |
| 82 | +if (missing.length > 0) { |
| 83 | + console.log("\nMissing hashes (first 10):") |
| 84 | + console.log(missing.slice(0, 10).join("\n")) |
| 85 | +} |
0 commit comments