CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | /**
* Block J15 — Release-notes generator. Pure helpers + route-auth smoke.
*/
import { describe, it, expect } from "bun:test";
import app from "../app";
import {
classifyCommit,
groupCommits,
contributorsFrom,
renderNotesMarkdown,
BUCKET_ORDER,
__internal,
} from "../lib/release-notes";
describe("release-notes — classifyCommit", () => {
it("recognises feat / fix / perf / refactor / docs / chore / revert prefixes", () => {
expect(classifyCommit({ sha: "a", message: "feat: thing" }).bucket).toBe(
"features"
);
expect(classifyCommit({ sha: "b", message: "fix: thing" }).bucket).toBe(
"fixes"
);
expect(classifyCommit({ sha: "c", message: "perf: thing" }).bucket).toBe(
"perf"
);
expect(classifyCommit({ sha: "d", message: "refactor: thing" }).bucket).toBe(
"refactor"
);
expect(classifyCommit({ sha: "e", message: "docs: thing" }).bucket).toBe(
"docs"
);
expect(classifyCommit({ sha: "f", message: "chore: thing" }).bucket).toBe(
"chore"
);
expect(classifyCommit({ sha: "g", message: "revert: thing" }).bucket).toBe(
"revert"
);
});
it("treats aliases (feature, bugfix, doc) as canonical", () => {
expect(classifyCommit({ sha: "a", message: "feature: x" }).bucket).toBe(
"features"
);
expect(classifyCommit({ sha: "b", message: "bugfix: x" }).bucket).toBe(
"fixes"
);
expect(classifyCommit({ sha: "c", message: "doc: x" }).bucket).toBe("docs");
expect(classifyCommit({ sha: "d", message: "tests: x" }).bucket).toBe("test");
});
it("is case-insensitive on the prefix", () => {
expect(classifyCommit({ sha: "a", message: "Feat: x" }).bucket).toBe(
"features"
);
expect(classifyCommit({ sha: "b", message: "FIX: x" }).bucket).toBe("fixes");
});
it("extracts scope from feat(scope): ...", () => {
const c = classifyCommit({ sha: "a", message: "feat(api): add endpoint" });
expect(c.bucket).toBe("features");
expect(c.scope).toBe("api");
expect(c.subject).toBe("add endpoint");
});
it("flags breaking with the `!` marker", () => {
const c = classifyCommit({ sha: "a", message: "feat(api)!: drop v1" });
expect(c.isBreaking).toBe(true);
expect(c.scope).toBe("api");
});
it("flags breaking with BREAKING CHANGE in subject", () => {
expect(
classifyCommit({ sha: "a", message: "feat: drop v1 BREAKING CHANGE" })
.isBreaking
).toBe(true);
});
it("captures trailing (#NNN) PR number", () => {
const c = classifyCommit({
sha: "a",
message: "fix: off-by-one (#123)",
});
expect(c.prNumber).toBe(123);
expect(c.subject).toBe("off-by-one");
});
it("parses Merge pull request #N commits into merges bucket", () => {
const c = classifyCommit({
sha: "a",
message: "Merge pull request #42 from user/branch",
});
expect(c.bucket).toBe("merges");
expect(c.prNumber).toBe(42);
});
it("parses Merge branch commits into merges bucket", () => {
const c = classifyCommit({
sha: "a",
message: "Merge branch 'main' into feature",
});
expect(c.bucket).toBe("merges");
expect(c.prNumber).toBeNull();
});
it("falls back to 'other' for non-conventional subjects", () => {
expect(
classifyCommit({ sha: "a", message: "fix the thing that broke" }).bucket
).toBe("other");
expect(classifyCommit({ sha: "b", message: "WIP" }).bucket).toBe("other");
});
it("does not match fake prefixes embedded in words", () => {
// `fixed: ...` shouldn't match `fix:` — the regex needs the literal prefix+colon.
const c = classifyCommit({ sha: "a", message: "fixed some stuff" });
expect(c.bucket).toBe("other");
});
it("handles blank subjects gracefully", () => {
const c = classifyCommit({ sha: "a", message: "" });
expect(c.bucket).toBe("other");
expect(c.subject).toBe("");
});
it("preserves author on the classified row", () => {
const c = classifyCommit({
sha: "a",
message: "feat: x",
author: "ada",
});
expect(c.author).toBe("ada");
});
});
describe("release-notes — groupCommits", () => {
it("splits a mixed list into the right buckets", () => {
const groups = groupCommits([
{ sha: "1", message: "feat: a" },
{ sha: "2", message: "fix: b" },
{ sha: "3", message: "chore: c" },
{ sha: "4", message: "feat: d" },
{ sha: "5", message: "nothing special" },
]);
expect(groups.features.map((x) => x.sha)).toEqual(["1", "4"]);
expect(groups.fixes.map((x) => x.sha)).toEqual(["2"]);
expect(groups.chore.map((x) => x.sha)).toEqual(["3"]);
expect(groups.other.map((x) => x.sha)).toEqual(["5"]);
});
it("preserves input order within each bucket", () => {
const groups = groupCommits([
{ sha: "b", message: "feat: b" },
{ sha: "a", message: "feat: a" },
{ sha: "c", message: "feat: c" },
]);
expect(groups.features.map((x) => x.sha)).toEqual(["b", "a", "c"]);
});
});
describe("release-notes — contributorsFrom", () => {
it("returns unique authors sorted case-insensitively", () => {
expect(
contributorsFrom([
{ sha: "1", message: "x", author: "Zoe" },
{ sha: "2", message: "y", author: "ada" },
{ sha: "3", message: "z", author: "Zoe" },
{ sha: "4", message: "w", author: "" },
])
).toEqual(["ada", "Zoe"]);
});
it("returns [] when no authors", () => {
expect(contributorsFrom([{ sha: "1", message: "x" }])).toEqual([]);
});
});
describe("release-notes — renderNotesMarkdown", () => {
it("returns a placeholder for empty input", () => {
const md = renderNotesMarkdown([]);
expect(md).toContain("No commits between these refs");
});
it("renders bucket headings in BUCKET_ORDER", () => {
const md = renderNotesMarkdown([
{ sha: "1", message: "chore: c" },
{ sha: "2", message: "feat: a" },
{ sha: "3", message: "fix: b" },
]);
const featIdx = md.indexOf("## Features");
const fixIdx = md.indexOf("## Bug fixes");
const choreIdx = md.indexOf("## Chores");
expect(featIdx).toBeGreaterThanOrEqual(0);
expect(fixIdx).toBeGreaterThan(featIdx);
expect(choreIdx).toBeGreaterThan(fixIdx);
});
it("surfaces a 'Breaking changes' section at the top", () => {
const md = renderNotesMarkdown([
{ sha: "1", message: "feat!: drop v1" },
{ sha: "2", message: "fix: tidy" },
]);
const breakIdx = md.indexOf("Breaking changes");
const featIdx = md.indexOf("## Features");
expect(breakIdx).toBeGreaterThanOrEqual(0);
expect(breakIdx).toBeLessThan(featIdx);
});
it("emits bold scope prefixes in list rows", () => {
const md = renderNotesMarkdown([
{ sha: "abcdef1", message: "feat(api): add endpoint" },
]);
expect(md).toContain("**api:**");
expect(md).toContain("add endpoint");
expect(md).toContain("abcdef1");
});
it("includes a Contributors section when authors present", () => {
const md = renderNotesMarkdown(
[{ sha: "1", message: "feat: a", author: "ada" }],
{ includeContributors: true }
);
expect(md).toContain("## Contributors");
expect(md).toContain("@ada");
});
it("skips Contributors when includeContributors: false", () => {
const md = renderNotesMarkdown(
[{ sha: "1", message: "feat: a", author: "ada" }],
{ includeContributors: false }
);
expect(md).not.toContain("## Contributors");
});
it("emits a compare link when owner/repo + tags provided", () => {
const md = renderNotesMarkdown(
[{ sha: "1", message: "feat: a" }],
{ ownerRepo: "acme/widget", previousTag: "v1", newTag: "v2" }
);
expect(md).toContain("/acme/widget/compare/v1...v2");
});
it("produces Markdown links for PR numbers when ownerRepo provided", () => {
const md = renderNotesMarkdown(
[{ sha: "abcdef0", message: "feat: a (#7)" }],
{ ownerRepo: "acme/widget", newTag: "v1" }
);
expect(md).toContain("/acme/widget/pulls/7");
expect(md).toContain("/acme/widget/commit/abcdef0");
});
});
describe("release-notes — BUCKET_ORDER", () => {
it("lists features before fixes before perf", () => {
expect(BUCKET_ORDER.indexOf("features")).toBeLessThan(
BUCKET_ORDER.indexOf("fixes")
);
expect(BUCKET_ORDER.indexOf("fixes")).toBeLessThan(
BUCKET_ORDER.indexOf("perf")
);
});
it("puts 'other' last", () => {
expect(BUCKET_ORDER[BUCKET_ORDER.length - 1]).toBe("other");
});
});
describe("release-notes — route smoke", () => {
it("POST /generate-notes requires auth (redirects or 401)", async () => {
const res = await app.request(
"/alice/nope/releases/generate-notes",
{ method: "POST", body: "target=main" }
);
expect([302, 401, 404].includes(res.status)).toBe(true);
});
it("POST with invalid bearer → 401 JSON", async () => {
const res = await app.request(
"/alice/nope/releases/generate-notes",
{
method: "POST",
headers: { authorization: "Bearer glc_garbage" },
body: "target=main",
}
);
expect(res.status).toBe(401);
});
});
describe("release-notes — __internal symmetry", () => {
it("re-exports the same classifyCommit / groupCommits / renderNotesMarkdown", () => {
expect(__internal.classifyCommit).toBe(classifyCommit);
expect(__internal.groupCommits).toBe(groupCommits);
expect(__internal.renderNotesMarkdown).toBe(renderNotesMarkdown);
});
});
|