diff --git a/.opencode/command/release-notes.md b/.opencode/command/release-notes.md index 11eb917..18a615d 100644 --- a/.opencode/command/release-notes.md +++ b/.opencode/command/release-notes.md @@ -30,4 +30,5 @@ After reviewing the generated notes: - tighten wording only when it improves clarity - preserve the existing section structure unless there is a strong reason to merge sections - suggest saving the finalized notes to `release-notes/v.md` when a version is known +- suggest the commands to update local `main` from the target remote before tagging, for example `git checkout main` and `git pull main` - suggest a `gh release create` command if the user wants to publish next diff --git a/scripts/release-notes.mjs b/scripts/release-notes.mjs index d31f589..f74fa5d 100644 --- a/scripts/release-notes.mjs +++ b/scripts/release-notes.mjs @@ -15,7 +15,7 @@ const { values } = parseArgs({ args: normalizedArgv, options: { from: { type: "string" }, - to: { type: "string", default: "HEAD" }, + to: { type: "string" }, draft: { type: "string" }, repo: { type: "string" }, help: { type: "boolean", short: "h", default: false }, @@ -25,7 +25,7 @@ const { values } = parseArgs({ if (values.help) { process.stdout.write( - `Usage: pnpm release:notes -- [options]\n\nOptions:\n --from Starting git tag. Defaults to latest semver tag.\n --to Ending git ref. Defaults to HEAD.\n --draft Create a draft GitHub release for the provided tag.\n --repo Override GitHub repo slug for compare links and draft release.\n -h, --help Show this help message.\n`, + `Usage: pnpm release:notes -- [options]\n\nOptions:\n --from Starting git tag. Defaults to latest semver tag.\n --to Ending git ref. Defaults to main for the public repo, otherwise HEAD.\n --draft Create a draft GitHub release for the provided tag.\n --repo Override GitHub repo slug for compare links and draft release.\n -h, --help Show this help message.\n`, ); process.exit(0); } @@ -43,6 +43,17 @@ function gh(args) { }).trim(); } +/** @param {string} remoteName */ +function getRemoteRepo(remoteName) { + try { + const remote = git(["remote", "get-url", remoteName]); + const match = remote.match(/github\.com[:/]([^/]+\/[^/.]+)(?:\.git)?$/); + return match?.[1]; + } catch { + return undefined; + } +} + function getLatestSemverTag() { const tags = git(["tag", "--sort=-version:refname"]) .split("\n") @@ -155,10 +166,13 @@ function getDefaultFromTag() { return getLatestSemverTag(); } -function getOriginRepo() { - const remote = git(["remote", "get-url", "origin"]); - const match = remote.match(/github\.com[:/]([^/]+\/[^/.]+)(?:\.git)?$/); - return match?.[1]; +function getPreferredRepo() { + return getRemoteRepo("public") ?? getRemoteRepo("origin"); +} + +/** @param {string | undefined} repo */ +function getDefaultToRef(repo) { + return repo === "every-app/open-seo" ? "main" : "HEAD"; } /** @param {readonly string[]} rangeArgs */ @@ -266,8 +280,8 @@ function buildNotes({ from, to, repo }) { } const from = values.from ?? getDefaultFromTag(); -const to = values.to; -const repo = values.repo ?? getOriginRepo(); +const repo = values.repo ?? getPreferredRepo(); +const to = values.to ?? getDefaultToRef(repo); const notes = buildNotes({ from, to, repo }); process.stdout.write(`${notes}\n`);