Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Preserve public sync coauthor attribution (#2432)

robert-inkeep02d843f129b5
diff --git a/.github/scripts/bridge-public-pr-to-monorepo.mjs b/.github/scripts/bridge-public-pr-to-monorepo.mjs
index 9d5042b5e..66bc552be 100644
--- a/.github/scripts/bridge-public-pr-to-monorepo.mjs
+++ b/.github/scripts/bridge-public-pr-to-monorepo.mjs
@@ -323,6 +323,68 @@ function buildBridgeMetadata(publicPr, mirrorPath) {
].join('\n');
}
+function fallbackPublicAuthor(publicPr) {
+ return {
+ name: publicPr.user.login,
+ email: `${publicPr.user.id}+${publicPr.user.login}@users.noreply.github.com`,
+ };
+}
+
+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`,
+ };
+}
+
+function normalizeCommitAuthor(author) {
+ const name = author?.name?.trim();
+ const email = author?.email?.trim();
+ if (!name || !email || !email.includes('@')) return null;
+ if (/[\r\n<>]/.test(name) || /[\r\n<>]/.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) {
+ 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];
+}
+
+async function listPublicPrCommitAuthors({ token, repo, prNumber, request = githubRequest }) {
+ const commitAuthors = [];
+ let page = 1;
+ while (true) {
+ const commits = await request({
+ token,
+ path: `/repos/${repo}/pulls/${prNumber}/commits?per_page=100&page=${page}`,
+ });
+ commitAuthors.push(
+ ...commits.map((commit) => normalizeGitHubUserAuthor(commit.author) ?? commit.commit?.author),
+ );
+ if (commits.length < 100) break;
+ page++;
+ }
+ return commitAuthors;
+}
+
+function buildCommitAttribution({ commitAuthors, fallbackAuthor }) {
+ const authors = uniqueCommitAuthors(commitAuthors, fallbackAuthor);
+ const trailers = authors.map((author) => `Co-authored-by: ${author.name} <${author.email}>`);
+ return { trailers };
+}
+
// GitHub PR body hard limit. Exceeding returns 422 "body is too long".
const GITHUB_PR_BODY_LIMIT = 65536;
@@ -824,7 +886,22 @@ async function syncPublicPr() {
]);
- const authorEmail = `${publicPr.user.id}+${publicPr.user.login}@users.noreply.github.com`;
+ let commitAuthors = [];
+ try {
+ commitAuthors = await listPublicPrCommitAuthors({
+ token: publicToken,
+ repo: publicRepo,
+ prNumber: publicPr.number,
+ });
+ } catch (error) {
+ console.warn(
+ `Bridge: could not fetch public PR commit authors; falling back to PR opener attribution: ${error.message}`,
+ );
+ }
+ const { trailers } = buildCommitAttribution({
+ commitAuthors,
+ fallbackAuthor: fallbackPublicAuthor(publicPr),
+ });
const commitMessage = hasConflicts
? `chore(sync): mirror ${publicRepo}#${publicPr.number} (${CONFLICT_COMMIT_MARKER})`
: `chore(sync): mirror ${publicRepo}#${publicPr.number}`;
@@ -832,10 +909,10 @@ async function syncPublicPr() {
'-C',
internalRepoDir,
'commit',
- '--author',
- `${publicPr.user.login} <${authorEmail}>`,
'-m',
commitMessage,
+ '-m',
+ trailers.join('\n'),
]);
run('git', [
@@ -1059,11 +1136,14 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
export {
applyPatchWithConflictDetection,
+ buildCommitAttribution,
buildInternalPrBody,
- commitIndicatesConflicts,
buildPublicComment,
checkOrgMembership,
+ commitIndicatesConflicts,
createClaGateGh,
+ listPublicPrCommitAuthors,
+ normalizeGitHubUserAuthor,
postCommitStatus,
prefixPatchPaths,
readCommitClaStatus,
diff --git a/.github/scripts/bridge-public-pr-to-monorepo.test.mjs b/.github/scripts/bridge-public-pr-to-monorepo.test.mjs
index 35d4fc45b..d72c5b619 100644
--- a/.github/scripts/bridge-public-pr-to-monorepo.test.mjs
+++ b/.github/scripts/bridge-public-pr-to-monorepo.test.mjs
@@ -5,10 +5,13 @@ import { tmpdir } from "node:os";
import path from "node:path";
import {
applyPatchWithConflictDetection,
+ buildCommitAttribution,
buildPublicComment,
checkOrgMembership,
commitIndicatesConflicts,
createClaGateGh,
+ listPublicPrCommitAuthors,
+ normalizeGitHubUserAuthor,
postCommitStatus,
readCommitClaStatus,
syncPublicPr,
@@ -27,6 +30,108 @@ const fakeRequest = (response) => {
return { request, calls };
};
+describe("buildCommitAttribution", () => {
+ test("credits every unique human author with native coauthor trailers", () => {
+ const attribution = buildCommitAttribution({
+ commitAuthors: [
+ { name: "Sarah Inkeep", email: "[email protected]" },
+ { name: "github-actions[bot]", email: "41898282+github-actions[bot]@users.noreply.github.com" },
+ { 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: Robert Inkeep <[email protected]>",
+ ]);
+ });
+
+ 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]>",
+ ]);
+ });
+});
+
+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 () => {
+ const pageOne = Array.from({ length: 100 }, (_, index) => ({
+ author: { login: `author-${index}`, id: index + 1 },
+ commit: { author: { name: `Commit ${index}`, email: `commit-${index}@example.com` } },
+ }));
+ const pageTwo = [
+ {
+ author: { login: "final-author", id: 101 },
+ commit: { author: { name: "Final Commit", email: "[email protected]" } },
+ },
+ ];
+ const calls = [];
+ const request = async (args) => {
+ calls.push(args);
+ return calls.length === 1 ? pageOne : pageTwo;
+ };
+
+ const authors = await listPublicPrCommitAuthors({
+ token: "t",
+ repo: "owner/repo",
+ prNumber: 123,
+ request,
+ });
+
+ expect(authors).toHaveLength(101);
+ expect(authors.at(-1)).toEqual({
+ name: "final-author",
+ email: "[email protected]",
+ });
+ 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]" } },
+ },
+ ]);
+
+ await expect(
+ listPublicPrCommitAuthors({
+ token: "t",
+ repo: "owner/repo",
+ prNumber: 123,
+ request,
+ }),
+ ).resolves.toEqual([{ name: "Patch Author", email: "[email protected]" }]);
+ });
+});
+
describe("readCommitClaStatus", () => {
test("extracts the license/cla state from the combined status", async () => {
const { request } = fakeRequest({