Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Clean up the synced pr commit message (#2477)
robert-inkeepb3755bdebd9b
diff --git a/.github/scripts/bridge-public-pr-to-monorepo.mjs b/.github/scripts/bridge-public-pr-to-monorepo.mjsindex 860c11ed5..bc2e6b9ae 100644--- a/.github/scripts/bridge-public-pr-to-monorepo.mjs+++ b/.github/scripts/bridge-public-pr-to-monorepo.mjs@@ -339,7 +339,7 @@ function buildBridgeMetadata(publicPr, mirrorPath) {].join('\n');}-function fallbackPublicAuthor(publicPr) {+function publicPrAuthor(publicPr) {return {name: publicPr.user.login,email: `${publicPr.user.id}+${publicPr.user.login}@users.noreply.github.com`,@@ -350,7 +350,6 @@ function normalizeGitHubUserAuthor(user) {const login = user?.login?.trim();const id = user?.id;if (!login || id === undefined || id === null) return null;- if (/\[bot\]$/i.test(login)) return null;return {name: login,email: `${id}+${login}@users.noreply.github.com`,@@ -360,25 +359,32 @@ function normalizeGitHubUserAuthor(user) {function normalizeCommitAuthor(author) {const name = author?.name?.trim();const email = author?.email?.trim();- if (!name || !email || !email.includes('@')) return null;+ if (!name || !email?.includes('@')) return null;if (/[\r\n<>]/.test(name) || /[\r\n<>]/.test(email)) return null;- if (/oss-sync@inkeep\.com$/i.test(email) || /public-pr-bridge@inkeep\.com$/i.test(email)) {- return null;- }- if (/\[bot\]$/i.test(name) || /\[bot\]@users\.noreply\.github\.com$/i.test(email)) {- return null;- }return { name, email };}-function uniqueCommitAuthors(authors, fallbackAuthor) {+function parseCoauthorTrailer(line) {+ const match = line.match(/^Co-authored-by:\s*(.+?)\s*<([^<>\s]+@[^<>\s]+)>\s*$/i);+ if (!match) return null;+ return normalizeCommitAuthor({ name: match[1], email: match[2] });+}++function coauthorsFromCommitMessage(message) {+ return normalizeCommitMessage(message)+ .split('\n')+ .map((line) => parseCoauthorTrailer(line.trim()))+ .filter(Boolean);+}++function uniqueCommitAuthors(authors) {const unique = new Map();for (const author of authors) {const normalized = normalizeCommitAuthor(author);if (!normalized) continue;unique.set(`${normalized.name.toLowerCase()} <${normalized.email.toLowerCase()}>`, normalized);}- return unique.size > 0 ? [...unique.values()] : [fallbackAuthor];+ return [...unique.values()];}function normalizePublicPrCommit(commit) {@@ -404,26 +410,21 @@ async function listPublicPrCommits({ token, repo, prNumber, request = githubRequreturn publicCommits;}-async function listPublicPrCommitAuthors({ token, repo, prNumber, request = githubRequest }) {- const commits = await listPublicPrCommits({ token, repo, prNumber, request });- return commits.map((commit) => commit.author);-}-function normalizeCommitMessage(message) {if (typeof message !== 'string') return '';return message.replace(/\r\n?/g, '\n').replace(/\0/g, '').trim();}-function formatOriginalCommitMessages(commitMessages) {+function formatOriginalCommitMessages(commitMessages, publicRepo) {const entries = commitMessages.map((commit) => {const message = normalizeCommitMessage(commit?.message);if (!message) return null;- const shortSha =- typeof commit?.sha === 'string' && /^[0-9a-f]{7,40}$/i.test(commit.sha)- ? commit.sha.slice(0, 7)- : null;- return { shortSha, message };+ const rawSha = typeof commit?.sha === 'string' ? commit.sha : '';+ const sha = /^[0-9a-f]{7,40}$/i.test(rawSha) ? rawSha : null;+ const shortSha = sha ? sha.slice(0, 7) : null;+ const author = normalizeCommitAuthor(commit?.author);+ return { author, sha, shortSha, message };}).filter(Boolean);@@ -431,21 +432,29 @@ function formatOriginalCommitMessages(commitMessages) {const formatted = entries.map((entry, index) => {const [subject, ...bodyLines] = entry.message.split('\n');+ const body =+ bodyLines.length > 0 ? `\n\n${bodyLines.map((line) => ` ${line}`).join('\n')}` : '';+ const author = entry.author ? `\n Author: ${entry.author.name} <${entry.author.email}>` : '';+ if (entry.sha && entry.shortSha && publicRepo) {+ return `${index + 1}. [${entry.shortSha}](https://github.com/${publicRepo}/commit/${entry.sha}) ${subject}${author}${body}`;+ }const prefix = entry.shortSha? `${index + 1}. ${entry.shortSha} ${subject}`: `${index + 1}. ${subject}`;- const body =- bodyLines.length > 0 ? `\n\n${bodyLines.map((line) => ` ${line}`).join('\n')}` : '';- return `${prefix}${body}`;+ return `${prefix}${author}${body}`;});- return ['Original public commit messages:', '', ...formatted].join('\n');+ return ['Commits:', '', ...formatted].join('\n');}-function buildCommitAttribution({ commitAuthors, commitMessages = [], fallbackAuthor }) {- const authors = uniqueCommitAuthors(commitAuthors, fallbackAuthor);+function buildCommitAttribution({ commitAuthors, commitMessages = [], publicRepo }) {+ const authors = uniqueCommitAuthors([+ ...commitAuthors,+ ...commitMessages.map((commit) => commit?.author),+ ...commitMessages.flatMap((commit) => coauthorsFromCommitMessage(commit?.message)),+ ]);const trailers = authors.map((author) => `Co-authored-by: ${author.name} <${author.email}>`);- const originalCommitMessages = formatOriginalCommitMessages(commitMessages);+ const originalCommitMessages = formatOriginalCommitMessages(commitMessages, publicRepo);const body = [originalCommitMessages, trailers.join('\n')].filter(Boolean).join('\n\n');return { trailers, originalCommitMessages, body };}@@ -962,13 +971,13 @@ async function syncPublicPr() {});} catch (error) {console.warn(- `Bridge: could not fetch public PR commits; falling back to PR opener attribution: ${error.message}`,+ `Bridge: could not fetch public PR commits for message context: ${error.message}`,);}const { body: commitBody } = buildCommitAttribution({- commitAuthors: publicCommits.map((commit) => commit.author),+ commitAuthors: [publicPrAuthor(publicPr)],commitMessages: publicCommits,- fallbackAuthor: fallbackPublicAuthor(publicPr),+ publicRepo,});const commitMessage = bridgeCommitSubject({ publicRepo, publicPr, hasConflicts });run('git', [@@ -1210,7 +1219,6 @@ export {checkOrgMembership,commitIndicatesConflicts,createClaGateGh,- listPublicPrCommitAuthors,listPublicPrCommits,normalizeGitHubUserAuthor,postCommitStatus,diff --git a/.github/scripts/bridge-public-pr-to-monorepo.test.mjs b/.github/scripts/bridge-public-pr-to-monorepo.test.mjsindex e081f8431..136eaf319 100644--- a/.github/scripts/bridge-public-pr-to-monorepo.test.mjs+++ b/.github/scripts/bridge-public-pr-to-monorepo.test.mjs@@ -11,7 +11,6 @@ import {checkOrgMembership,commitIndicatesConflicts,createClaGateGh,- listPublicPrCommitAuthors,listPublicPrCommits,normalizeGitHubUserAuthor,postCommitStatus,@@ -33,7 +32,7 @@ const fakeRequest = (response) => {};describe('buildCommitAttribution', () => {- test('credits every unique human author with native coauthor trailers', () => {+ test('credits every unique contributor with native coauthor trailers', () => {const attribution = buildCommitAttribution({commitAuthors: [{ name: 'Sarah Inkeep', email: '[email protected]' },@@ -44,77 +43,65 @@ describe('buildCommitAttribution', () => {{ name: 'Sarah Inkeep', email: '[email protected]' },{ name: 'Robert Inkeep', email: '[email protected]' },],- fallbackAuthor: { name: 'octocat', email: '[email protected]' },});expect(attribution.trailers).toEqual(['Co-authored-by: Sarah Inkeep <[email protected]>',+ 'Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>','Co-authored-by: Robert Inkeep <[email protected]>',]);});- test('preserves original public commit messages before coauthor trailers', () => {+ test('lists commits for readability and builds a deduped GitHub attribution block', () => {const attribution = buildCommitAttribution({- commitAuthors: [{ name: 'Sarah Inkeep', email: '[email protected]' }],+ commitAuthors: [{ name: 'octocat', email: '[email protected]' }],commitMessages: [- { sha: '1234567890abcdef', message: 'Add search\n\nExplain the indexing path.' },+ {+ sha: '1234567890abcdef',+ author: { name: 'Sarah Inkeep', email: '[email protected]' },+ message: 'Add search\n\nExplain the indexing path.',+ },{sha: 'fedcba9876543210',+ author: { name: 'Robert Inkeep', email: '[email protected]' },message: 'Fix empty query\r\n\r\nCo-authored-by: A <[email protected]>',},],- fallbackAuthor: { name: 'octocat', email: '[email protected]' },+ publicRepo: 'inkeep/open-knowledge',});expect(attribution.originalCommitMessages).toBe([- 'Original public commit messages:',+ 'Commits:','',- '1. 1234567 Add search',+ '1. [1234567](https://github.com/inkeep/open-knowledge/commit/1234567890abcdef) Add search',+ ' Author: Sarah Inkeep <[email protected]>','',' ',' Explain the indexing path.',- '2. fedcba9 Fix empty query',+ '2. [fedcba9](https://github.com/inkeep/open-knowledge/commit/fedcba9876543210) Fix empty query',+ ' Author: Robert Inkeep <[email protected]>','',' ',' Co-authored-by: A <[email protected]>',].join('\n'),);- expect(attribution.body).toContain('Original public commit messages:');- expect(- attribution.body.trim().endsWith('Co-authored-by: Sarah Inkeep <[email protected]>'),- ).toBe(true);- });-- test('falls back to the public PR author when commits only have invalid authors', () => {- const attribution = buildCommitAttribution({- commitAuthors: [- {- name: 'github-actions[bot]',- email: '41898282+github-actions[bot]@users.noreply.github.com',- },- { name: 'Bad\nName', email: '[email protected]' },- ],- fallbackAuthor: { name: 'octocat', email: '[email protected]' },- });-expect(attribution.trailers).toEqual(['Co-authored-by: octocat <[email protected]>',+ 'Co-authored-by: Sarah Inkeep <[email protected]>',+ 'Co-authored-by: Robert Inkeep <[email protected]>',+ 'Co-authored-by: A <[email protected]>',]);});- test('does not credit sync automation as coauthors', () => {+ test('allows an empty attribution block when no author normalizes', () => {const attribution = buildCommitAttribution({- commitAuthors: [- { name: 'Inkeep OSS Sync', email: '[email protected]' },- { name: 'Inkeep Public PR Bridge', email: '[email protected]' },- ],- fallbackAuthor: { name: 'octocat', email: '[email protected]' },+ commitAuthors: [{ name: 'Bad\nName', email: '[email protected]' }],+ commitMessages: [],});- expect(attribution.trailers).toEqual([- 'Co-authored-by: octocat <[email protected]>',- ]);+ expect(attribution.trailers).toEqual([]);+ expect(attribution.body).toBe('');});});@@ -170,74 +157,71 @@ describe('listPublicPrCommits', () => {},]);});-});--describe('normalizeGitHubUserAuthor', () => {- test('uses the GitHub-resolved user id/login noreply identity', () => {- expect(normalizeGitHubUserAuthor({ login: 'rtran9', id: 11001605 })).toEqual({- name: 'rtran9',- email: '[email protected]',- });- });- test('ignores unresolved and bot users so callers can fall back', () => {- expect(normalizeGitHubUserAuthor(null)).toBeNull();- expect(normalizeGitHubUserAuthor({ login: 'github-actions[bot]', id: 41898282 })).toBeNull();- });-});--describe('listPublicPrCommitAuthors', () => {- test('paginates through every public PR commit author', async () => {+ test('paginates until a page returns fewer than 100 commits', async () => {+ const calls = [];const pageOne = Array.from({ length: 100 }, (_, index) => ({+ sha: `${index.toString(16).padStart(7, '0')}abcdef`,author: { login: `author-${index}`, id: index + 1 },- commit: { author: { name: `Commit ${index}`, email: `commit-${index}@example.com` } },+ commit: {+ author: { name: `Raw Author ${index}`, email: `raw-${index}@example.com` },+ message: `Commit ${index}`,+ },}));const pageTwo = [{- author: { login: 'final-author', id: 101 },- commit: { author: { name: 'Final Commit', email: '[email protected]' } },+ sha: 'feedbee',+ author: { login: 'last-author', id: 101 },+ commit: {+ author: { name: 'Raw Last', email: '[email protected]' },+ message: 'Commit 100',+ },},];- const calls = [];const request = async (args) => {calls.push(args);return calls.length === 1 ? pageOne : pageTwo;};- const authors = await listPublicPrCommitAuthors({+ const commits = await listPublicPrCommits({token: 't',repo: 'owner/repo',prNumber: 123,request,});- expect(authors).toHaveLength(101);- expect(authors.at(-1)).toEqual({- name: 'final-author',- email: '[email protected]',+ expect(commits).toHaveLength(101);+ expect(commits[0]).toEqual({+ sha: '0000000abcdef',+ author: { name: 'author-0', email: '[email protected]' },+ message: 'Commit 0',+ });+ expect(commits.at(-1)).toEqual({+ sha: 'feedbee',+ author: { name: 'last-author', email: '[email protected]' },+ message: 'Commit 100',});expect(calls.map((call) => call.path)).toEqual(['/repos/owner/repo/pulls/123/commits?per_page=100&page=1','/repos/owner/repo/pulls/123/commits?per_page=100&page=2',]);});+});- test('falls back to raw commit author when GitHub has no linked user', async () => {- const { request } = fakeRequest([- {- author: null,- commit: { author: { name: 'Patch Author', email: '[email protected]' } },- },- ]);+describe('normalizeGitHubUserAuthor', () => {+ test('uses the GitHub-resolved user id/login noreply identity', () => {+ expect(normalizeGitHubUserAuthor({ login: 'rtran9', id: 11001605 })).toEqual({+ name: 'rtran9',+ email: '[email protected]',+ });+ });- await expect(- listPublicPrCommitAuthors({- token: 't',- repo: 'owner/repo',- prNumber: 123,- request,- }),- ).resolves.toEqual([{ name: 'Patch Author', email: '[email protected]' }]);+ test('ignores unresolved users but preserves bots as valid contributors', () => {+ expect(normalizeGitHubUserAuthor(null)).toBeNull();+ expect(normalizeGitHubUserAuthor({ login: 'github-actions[bot]', id: 41898282 })).toEqual({+ name: 'github-actions[bot]',+ email: '41898282+github-actions[bot]@users.noreply.github.com',+ });});});