Skip to content

chore: keep co-authors in spread commit #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions scripts/__tests__/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,32 @@ describe('gitCommit', () => {
});

it('commits with co-author', () => {
// This reflects how it can be retrieved from git commands.
const author = `Co-authored-by: them <[email protected]>
`.trim();
const coAuthors = `

Co-authored-by: me <[email protected]>


Co-authored-by: you <[email protected]>

`
.split('\n')
.map((coAuthor) => coAuthor.trim())
.filter(Boolean);

gitCommit({
message: 'chore: does something',
coauthor: { name: 'some', email: '[email protected]' },
coauthors: [author, ...coAuthors],
});
expect(execa).toHaveBeenCalledTimes(1);
expect(execa).toHaveBeenCalledWith(
'git',
[
'commit',
'-m',
'chore: does something\n\n\nCo-authored-by: some <random@person.com>',
'chore: does something\n\n\nCo-authored-by: them <[email protected]>\nCo-authored-by: me <[email protected]>\nCo-authored-by: you <you@algolia.com>',
],
{ cwd: expect.any(String) }
);
Expand Down
16 changes: 12 additions & 4 deletions scripts/ci/codegen/spreadGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ async function spreadGeneration(): Promise<void> {
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);

Expand Down Expand Up @@ -75,7 +83,7 @@ async function spreadGeneration(): Promise<void> {
await run(`git add .`, { cwd: tempGitDir });
await gitCommit({
message: commitMessage,
coauthor: { name, email },
coauthors: [author, ...coAuthors],
cwd: tempGitDir,
});
await run(`git push`, { cwd: tempGitDir });
Expand Down
28 changes: 9 additions & 19 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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(
Expand Down