Skip to content

chore(scripts): improve generation commit message #3419

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 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 6 additions & 7 deletions scripts/ci/codegen/__tests__/spreadGeneration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ describe('spread generation', () => {
`);
});

it('provides a link to the automation repo for commit with hash', () => {
const commitMessage = `${text.commitStartMessage} ed33e02f3e45fd72b4f420a56e4be7c6929fca9f. [skip ci]`;
expect(cleanUpCommitMessage(commitMessage, '')).toMatchInlineSnapshot(`
"chore: generated code for commit ed33e02f. [skip ci]

https://github.com/algolia/api-clients-automation/commit/ed33e02f3e45fd72b4f420a56e4be7c6929fca9f"
`);
it('generated commits have a link to the origin pull request', () => {
expect(
cleanUpCommitMessage('feat(ci): make ci push generated code (#244) (generated).', '')
).toEqual(
`feat(ci): make ci push generated code\n\nhttps://github.com/algolia/api-clients-automation/pull/244`
);
});
});
});
2 changes: 1 addition & 1 deletion scripts/ci/codegen/pushGeneratedCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function pushGeneratedCode(): Promise<void> {

const skipCi = isMainBranch ? '[skip ci]' : '';
let message = await run(
`git show -s ${baseBranch} --format="${text.commitStartMessage} %H. ${skipCi}"`,
`git show -s ${baseBranch} --format="%s ${text.commitEndMessage} ${skipCi}"`,
);
const authors = await run(
`git show -s ${baseBranch} --format="
Expand Down
19 changes: 2 additions & 17 deletions scripts/ci/codegen/spreadGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,14 @@ import { getNewReleasedTag } from '../../release/common.js';
import type { Language } from '../../types.js';
import { cloneRepository, getNbGitDiff } from '../utils.js';

import text, { commitStartRelease } from './text.js';
import { commitStartRelease } from './text.js';

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

const isCodeGenCommit = commitMessage.startsWith(text.commitStartMessage);

if (isCodeGenCommit) {
const hash = commitMessage.split(text.commitStartMessage)[1].replace('. [skip ci]', '').trim();

if (!hash) {
return commitMessage;
}

return [
`${text.commitStartMessage} ${hash.substring(0, 8)}. [skip ci]`,
`${REPO_URL}/commit/${hash}`,
].join('\n\n');
}

const prCommit = commitMessage.match(/(.+)\s\(#(\d+)\)$/);
const prCommit = commitMessage.match(/(.+)\s\(#(\d+)\)/);

if (!prCommit) {
return commitMessage;
Expand Down
8 changes: 7 additions & 1 deletion scripts/ci/codegen/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { TODAY } from '../../common.js';
export const commitStartPrepareRelease = 'chore: prepare release';
export const commitStartRelease = 'chore: release';

const commitEndMessage = '(generated).';

export default {
commitStartMessage: 'chore: generated code for commit',
commitEndMessage,
commitPrepareReleaseMessage: `${commitStartPrepareRelease} ${TODAY}`,
commitReleaseMessage: `${commitStartRelease} ${TODAY}`,
};

export function isGeneratedCommit(text: string): boolean {
return text.endsWith(commitEndMessage);
}
17 changes: 2 additions & 15 deletions scripts/release/__tests__/createReleasePR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,8 @@ describe('createReleasePR', () => {
expect(
await parseCommit(
buildTestCommit({
type: 'chore',
message: 'generated code for commit',
})
)
).toEqual({
error: 'generation-commit',
});
});

it('returns error when it is a generated commit, even with other casing', async () => {
expect(
await parseCommit(
buildTestCommit({
type: 'chore',
message: 'GENERATED CODE FOR COMMIT',
type: 'feat(specs)',
message: 'foo bar baz (generated).',
})
)
).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions scripts/release/createReleasePR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chalk from 'chalk';
import dotenv from 'dotenv';
import semver from 'semver';

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

// We skip generation commits as they do not appear in changelogs
if (message.toLocaleLowerCase().startsWith(generationCommitText.commitStartMessage)) {
if (isGeneratedCommit(message)) {
return {
error: 'generation-commit',
};
Expand Down
Loading