diff --git a/scripts/__tests__/common.test.ts b/scripts/__tests__/common.test.ts index d953c3d48d..27558fe0fa 100644 --- a/scripts/__tests__/common.test.ts +++ b/scripts/__tests__/common.test.ts @@ -20,9 +20,24 @@ describe('gitCommit', () => { }); it('commits with co-author', () => { + // This reflects how it can be retrieved from git commands. + const author = `Co-authored-by: them + `.trim(); + const coAuthors = ` + + Co-authored-by: me + + + Co-authored-by: you + + ` + .split('\n') + .map((coAuthor) => coAuthor.trim()) + .filter(Boolean); + gitCommit({ message: 'chore: does something', - coauthor: { name: 'some', email: 'random@person.com' }, + coAuthors: [author, ...coAuthors], }); expect(execa).toHaveBeenCalledTimes(1); expect(execa).toHaveBeenCalledWith( @@ -30,7 +45,7 @@ describe('gitCommit', () => { [ 'commit', '-m', - 'chore: does something\n\n\nCo-authored-by: some ', + 'chore: does something\n\n\nCo-authored-by: them \nCo-authored-by: me \nCo-authored-by: you ', ], { cwd: expect.any(String) } ); diff --git a/scripts/ci/codegen/spreadGeneration.ts b/scripts/ci/codegen/spreadGeneration.ts index 51bfceab66..c9d847357d 100644 --- a/scripts/ci/codegen/spreadGeneration.ts +++ b/scripts/ci/codegen/spreadGeneration.ts @@ -42,9 +42,17 @@ async function spreadGeneration(): Promise { throw new Error('Environment variable `GITHUB_TOKEN` does not exist.'); } - const lastCommitMessage = await run(`git log -1 --format="%s"`); - const name = (await run(`git log -1 --format="%an"`)).trim(); - const email = (await run(`git log -1 --format="%ae"`)).trim(); + const lastCommitMessage = await run('git log -1 --format="%s"'); + const author = ( + await run('git log -1 --format="Co-authored-by: %an <%ae>"') + ).trim(); + const coAuthors = ( + await run('git log -1 --format="%(trailers:key=Co-authored-by)"') + ) + .split('\n') + .map((coAuthor) => coAuthor.trim()) + .filter(Boolean); + const commitMessage = cleanUpCommitMessage(lastCommitMessage); const langs = decideWhereToSpread(lastCommitMessage); @@ -75,7 +83,7 @@ async function spreadGeneration(): Promise { await run(`git add .`, { cwd: tempGitDir }); await gitCommit({ message: commitMessage, - coauthor: { name, email }, + coAuthors: [author, ...coAuthors], cwd: tempGitDir, }); await run(`git push`, { cwd: tempGitDir }); diff --git a/scripts/common.ts b/scripts/common.ts index cbacf5cafc..da1af81d99 100644 --- a/scripts/common.ts +++ b/scripts/common.ts @@ -186,30 +186,20 @@ export async function runIfExists( export async function gitCommit({ message, - coauthor, + coAuthors, cwd = ROOT_DIR, }: { message: string; - coauthor?: { - name: string; - email: string; - }; + coAuthors?: string[]; cwd?: string; }): Promise { - await execa( - 'git', - [ - 'commit', - '-m', - message + - (coauthor - ? `\n\n\nCo-authored-by: ${coauthor.name} <${coauthor.email}>` - : ''), - ], - { - cwd, - } - ); + const messageWithCoAuthors = coAuthors + ? `${message}\n\n\n${coAuthors.join('\n')}` + : message; + + await execa('git', ['commit', '-m', messageWithCoAuthors], { + cwd, + }); } export async function checkForCache(