Skip to content

Commit 90762d1

Browse files
authored
chore(scripts): improve generation commit message (#3419)
1 parent fa43c59 commit 90762d1

File tree

6 files changed

+20
-43
lines changed

6 files changed

+20
-43
lines changed

scripts/ci/codegen/__tests__/spreadGeneration.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ describe('spread generation', () => {
3232
`);
3333
});
3434

35-
it('provides a link to the automation repo for commit with hash', () => {
36-
const commitMessage = `${text.commitStartMessage} ed33e02f3e45fd72b4f420a56e4be7c6929fca9f. [skip ci]`;
37-
expect(cleanUpCommitMessage(commitMessage, '')).toMatchInlineSnapshot(`
38-
"chore: generated code for commit ed33e02f. [skip ci]
39-
40-
https://github.com/algolia/api-clients-automation/commit/ed33e02f3e45fd72b4f420a56e4be7c6929fca9f"
41-
`);
35+
it('generated commits have a link to the origin pull request', () => {
36+
expect(
37+
cleanUpCommitMessage('feat(ci): make ci push generated code (#244) (generated).', '')
38+
).toEqual(
39+
`feat(ci): make ci push generated code\n\nhttps://github.com/algolia/api-clients-automation/pull/244`
40+
);
4241
});
4342
});
4443
});

scripts/ci/codegen/pushGeneratedCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export async function pushGeneratedCode(): Promise<void> {
5858

5959
const skipCi = isMainBranch ? '[skip ci]' : '';
6060
let message = await run(
61-
`git show -s ${baseBranch} --format="${text.commitStartMessage} %H. ${skipCi}"`,
61+
`git show -s ${baseBranch} --format="%s ${text.commitEndMessage} ${skipCi}"`,
6262
);
6363
const authors = await run(
6464
`git show -s ${baseBranch} --format="

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,14 @@ import { getNewReleasedTag } from '../../release/common.js';
1818
import type { Language } from '../../types.js';
1919
import { cloneRepository, getNbGitDiff } from '../utils.js';
2020

21-
import text, { commitStartRelease } from './text.js';
21+
import { commitStartRelease } from './text.js';
2222

2323
export function cleanUpCommitMessage(commitMessage: string, version: string): string {
2424
if (commitMessage.startsWith(commitStartRelease)) {
2525
return `chore: release ${version}`;
2626
}
2727

28-
const isCodeGenCommit = commitMessage.startsWith(text.commitStartMessage);
29-
30-
if (isCodeGenCommit) {
31-
const hash = commitMessage.split(text.commitStartMessage)[1].replace('. [skip ci]', '').trim();
32-
33-
if (!hash) {
34-
return commitMessage;
35-
}
36-
37-
return [
38-
`${text.commitStartMessage} ${hash.substring(0, 8)}. [skip ci]`,
39-
`${REPO_URL}/commit/${hash}`,
40-
].join('\n\n');
41-
}
42-
43-
const prCommit = commitMessage.match(/(.+)\s\(#(\d+)\)$/);
28+
const prCommit = commitMessage.match(/(.+)\s\(#(\d+)\)/);
4429

4530
if (!prCommit) {
4631
return commitMessage;

scripts/ci/codegen/text.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import { TODAY } from '../../common.js';
33
export const commitStartPrepareRelease = 'chore: prepare release';
44
export const commitStartRelease = 'chore: release';
55

6+
const commitEndMessage = '(generated).';
7+
68
export default {
7-
commitStartMessage: 'chore: generated code for commit',
9+
commitEndMessage,
810
commitPrepareReleaseMessage: `${commitStartPrepareRelease} ${TODAY}`,
911
commitReleaseMessage: `${commitStartRelease} ${TODAY}`,
1012
};
13+
14+
export function isGeneratedCommit(text: string): boolean {
15+
return text.endsWith(commitEndMessage);
16+
}

scripts/release/__tests__/createReleasePR.test.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,8 @@ describe('createReleasePR', () => {
132132
expect(
133133
await parseCommit(
134134
buildTestCommit({
135-
type: 'chore',
136-
message: 'generated code for commit',
137-
})
138-
)
139-
).toEqual({
140-
error: 'generation-commit',
141-
});
142-
});
143-
144-
it('returns error when it is a generated commit, even with other casing', async () => {
145-
expect(
146-
await parseCommit(
147-
buildTestCommit({
148-
type: 'chore',
149-
message: 'GENERATED CODE FOR COMMIT',
135+
type: 'feat(specs)',
136+
message: 'foo bar baz (generated).',
150137
})
151138
)
152139
).toEqual({

scripts/release/createReleasePR.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import chalk from 'chalk';
55
import dotenv from 'dotenv';
66
import semver from 'semver';
77

8-
import generationCommitText from '../ci/codegen/text.js';
8+
import generationCommitText, { isGeneratedCommit } from '../ci/codegen/text.js';
99
import { getNbGitDiff } from '../ci/utils.js';
1010
import {
1111
LANGUAGES,
@@ -133,7 +133,7 @@ export async function parseCommit(commit: string): Promise<Commit> {
133133
}
134134

135135
// We skip generation commits as they do not appear in changelogs
136-
if (message.toLocaleLowerCase().startsWith(generationCommitText.commitStartMessage)) {
136+
if (isGeneratedCommit(message)) {
137137
return {
138138
error: 'generation-commit',
139139
};

0 commit comments

Comments
 (0)