Skip to content

Commit f360137

Browse files
authored
chore: keep co-authors in spread commit (#410)
1 parent 91dcfb3 commit f360137

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

scripts/__tests__/common.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,32 @@ describe('gitCommit', () => {
2020
});
2121

2222
it('commits with co-author', () => {
23+
// This reflects how it can be retrieved from git commands.
24+
const author = `Co-authored-by: them <[email protected]>
25+
`.trim();
26+
const coAuthors = `
27+
28+
Co-authored-by: me <[email protected]>
29+
30+
31+
Co-authored-by: you <[email protected]>
32+
33+
`
34+
.split('\n')
35+
.map((coAuthor) => coAuthor.trim())
36+
.filter(Boolean);
37+
2338
gitCommit({
2439
message: 'chore: does something',
25-
coauthor: { name: 'some', email: '[email protected]' },
40+
coAuthors: [author, ...coAuthors],
2641
});
2742
expect(execa).toHaveBeenCalledTimes(1);
2843
expect(execa).toHaveBeenCalledWith(
2944
'git',
3045
[
3146
'commit',
3247
'-m',
33-
'chore: does something\n\n\nCo-authored-by: some <random@person.com>',
48+
'chore: does something\n\n\nCo-authored-by: them <[email protected]>\nCo-authored-by: me <[email protected]>\nCo-authored-by: you <you@algolia.com>',
3449
],
3550
{ cwd: expect.any(String) }
3651
);

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ async function spreadGeneration(): Promise<void> {
4242
throw new Error('Environment variable `GITHUB_TOKEN` does not exist.');
4343
}
4444

45-
const lastCommitMessage = await run(`git log -1 --format="%s"`);
46-
const name = (await run(`git log -1 --format="%an"`)).trim();
47-
const email = (await run(`git log -1 --format="%ae"`)).trim();
45+
const lastCommitMessage = await run('git log -1 --format="%s"');
46+
const author = (
47+
await run('git log -1 --format="Co-authored-by: %an <%ae>"')
48+
).trim();
49+
const coAuthors = (
50+
await run('git log -1 --format="%(trailers:key=Co-authored-by)"')
51+
)
52+
.split('\n')
53+
.map((coAuthor) => coAuthor.trim())
54+
.filter(Boolean);
55+
4856
const commitMessage = cleanUpCommitMessage(lastCommitMessage);
4957
const langs = decideWhereToSpread(lastCommitMessage);
5058

@@ -75,7 +83,7 @@ async function spreadGeneration(): Promise<void> {
7583
await run(`git add .`, { cwd: tempGitDir });
7684
await gitCommit({
7785
message: commitMessage,
78-
coauthor: { name, email },
86+
coAuthors: [author, ...coAuthors],
7987
cwd: tempGitDir,
8088
});
8189
await run(`git push`, { cwd: tempGitDir });

scripts/common.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,20 @@ export async function runIfExists(
186186

187187
export async function gitCommit({
188188
message,
189-
coauthor,
189+
coAuthors,
190190
cwd = ROOT_DIR,
191191
}: {
192192
message: string;
193-
coauthor?: {
194-
name: string;
195-
email: string;
196-
};
193+
coAuthors?: string[];
197194
cwd?: string;
198195
}): Promise<void> {
199-
await execa(
200-
'git',
201-
[
202-
'commit',
203-
'-m',
204-
message +
205-
(coauthor
206-
? `\n\n\nCo-authored-by: ${coauthor.name} <${coauthor.email}>`
207-
: ''),
208-
],
209-
{
210-
cwd,
211-
}
212-
);
196+
const messageWithCoAuthors = coAuthors
197+
? `${message}\n\n\n${coAuthors.join('\n')}`
198+
: message;
199+
200+
await execa('git', ['commit', '-m', messageWithCoAuthors], {
201+
cwd,
202+
});
213203
}
214204

215205
export async function checkForCache(

0 commit comments

Comments
 (0)