Move commit co-author credits into lib

This commit is contained in:
Rūdolfs Ošiņš
2026-10-01 18:20:25 +02:00
parent 6cf4d6010f
commit 71c31e234c
3 changed files with 58 additions and 27 deletions
+28
View File
@@ -4,8 +4,10 @@ import { describe, expect, test, vi } from "vitest";
import {
coAuthors,
creditedCoAuthors,
explorerHost,
explorerUrl,
formatGitIdentity,
formatRepositoryId,
formatTimestamp,
identityKey,
@@ -301,3 +303,29 @@ describe("verdicts", () => {
},
);
});
describe("commit credits", () => {
const alice = { name: "Alice", email: "alice@example.com" };
const bob = { name: "Bob", email: "bob@example.com" };
const carol = { name: "Carol", email: "carol@example.com" };
test("formatGitIdentity writes a trailer identity", () => {
expect(formatGitIdentity(alice)).toBe("Alice <alice@example.com>");
expect(formatGitIdentity({ name: "", email: "a@b.c" })).toBe("a@b.c");
});
test("creditedCoAuthors skips the author, the committer and repeats", () => {
const message = [
"Squashed",
"",
"Co-authored-by: Alice <ALICE@example.com>",
"Co-authored-by: Bob <bob@example.com>",
"Co-authored-by: Carol <carol@example.com>",
"Co-authored-by: Carol C. <Carol@example.com>",
].join("\n");
expect(
creditedCoAuthors({ author: alice, committer: bob, message }),
).toEqual([carol]);
});
});