Skip to content

Commit a2a408e

Browse files
authored
Merge branch 'main' into docs/analytics/update_max_pagination_query_limit
2 parents f00c4bc + ca57501 commit a2a408e

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

scripts/release/__tests__/createReleasePR.test.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ describe('createReleasePR', () => {
101101
getFileChangesMock.mockResolvedValueOnce('');
102102
expect(await parseCommit(buildTestCommit())).toEqual(
103103
expect.objectContaining({
104-
error: 'missing-language-scope',
104+
author: '[@algolia-bot](https://github.com/algolia-bot/)',
105+
hash: 'b2501882',
106+
languages: [],
107+
message: 'fix: fix the thing',
108+
prNumber: 123,
109+
scope: undefined,
110+
type: 'fix',
105111
}),
106112
);
107113
});
@@ -110,7 +116,13 @@ describe('createReleasePR', () => {
110116
getFileChangesMock.mockResolvedValueOnce('specs/search/something.json');
111117
expect(await parseCommit(buildTestCommit())).toEqual(
112118
expect.objectContaining({
113-
error: 'missing-language-scope',
119+
author: '[@algolia-bot](https://github.com/algolia-bot/)',
120+
hash: 'b2501882',
121+
languages: [],
122+
message: 'fix: fix the thing',
123+
prNumber: 123,
124+
scope: undefined,
125+
type: 'fix',
114126
}),
115127
);
116128
});
@@ -138,7 +150,8 @@ describe('createReleasePR', () => {
138150
});
139151
});
140152

141-
it('returns error when it is a generated commit', async () => {
153+
it('returns early when it is a generated commit', async () => {
154+
getFileChangesMock.mockResolvedValueOnce('clients/algoliasearch-client-javascript/package.json');
142155
expect(
143156
await parseCommit(
144157
buildTestCommit({
@@ -147,7 +160,9 @@ describe('createReleasePR', () => {
147160
}),
148161
),
149162
).toEqual({
150-
error: 'generation-commit',
163+
generated: true,
164+
languages: ['javascript'],
165+
message: 'feat(specs): foo bar baz (generated)',
151166
});
152167
});
153168
});

scripts/release/createReleasePR.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,24 @@ export async function parseCommit(commit: string): Promise<Commit> {
8686
const prNumberMatch = message.match(/#(\d+)/);
8787
const prNumber = prNumberMatch ? parseInt(prNumberMatch[1], 10) : 0;
8888

89-
// We skip generation commits as they do not appear in changelogs
90-
if (isGeneratedCommit(message)) {
91-
return {
92-
error: 'generation-commit',
93-
};
89+
let commitType = typeAndScope ? typeAndScope[1] : 'fix'; // default to fix.
90+
if (!['feat', 'fix', 'chore'].includes(commitType)) {
91+
commitType = 'fix';
9492
}
9593

9694
// get the scope of the commit by checking the changes.
9795
// any changes in the folder of a language will be scoped to that language
9896
const diff = await getFileChanges(hash);
9997
if (!diff) {
98+
// for empty commits, they will be filtered out later
10099
return {
101-
error: 'missing-language-scope',
102-
message,
100+
hash,
101+
type: commitType as CommitType,
102+
languages: [],
103+
scope: typeAndScope ? (typeAndScope[2] as Scope) : undefined,
104+
message: message.replace(`(#${prNumber})`, '').trim(),
105+
prNumber,
106+
author: fetchedUsers[authorEmail],
103107
};
104108
}
105109

@@ -111,9 +115,11 @@ export async function parseCommit(commit: string): Promise<Commit> {
111115
}
112116
}
113117

114-
if (languageScopes.size === 0) {
118+
// for generated commits, we just report the languages so that the changes are attributed to the correct language and commit
119+
if (isGeneratedCommit(message)) {
115120
return {
116-
error: 'missing-language-scope',
121+
generated: true,
122+
languages: [...languageScopes] as Language[],
117123
message,
118124
};
119125
}
@@ -132,11 +138,6 @@ export async function parseCommit(commit: string): Promise<Commit> {
132138
}
133139
}
134140

135-
let commitType = typeAndScope ? typeAndScope[1] : 'fix'; // default to fix.
136-
if (!['feat', 'fix', 'chore'].includes(commitType)) {
137-
commitType = 'fix';
138-
}
139-
140141
return {
141142
hash,
142143
type: commitType as CommitType, // `fix` | `feat` | `chore` | ..., default to `fix`
@@ -246,19 +247,23 @@ async function getCommits(force?: boolean): Promise<{
246247
skippedCommits: string;
247248
}> {
248249
// Reading commits since last release
249-
const latestCommits = (await run(`git log --pretty=format:"%h|%ae|%s" ${await getLastReleasedTag()}..${MAIN_BRANCH}`))
250+
const latestCommits = (
251+
await run(`git log --reverse --pretty=format:"%h|%ae|%s" ${await getLastReleasedTag()}..${MAIN_BRANCH}`)
252+
)
250253
.split('\n')
251254
.filter(Boolean);
252255

253-
const commitsWithoutLanguageScope: string[] = [];
254-
const validCommits: ParsedCommit[] = [];
256+
let validCommits: ParsedCommit[] = [];
255257

256258
for (const commitMessage of latestCommits) {
257259
const commit = await parseCommit(commitMessage);
258260

259-
if ('error' in commit) {
260-
if (commit.error === 'missing-language-scope') {
261-
commitsWithoutLanguageScope.push(commit.message);
261+
if ('generated' in commit) {
262+
const originalCommit = validCommits.findIndex((c) => commit.message.includes(c.message));
263+
if (originalCommit !== -1) {
264+
validCommits[originalCommit].languages = [
265+
...new Set([...validCommits[originalCommit].languages, ...commit.languages]),
266+
];
262267
}
263268

264269
continue;
@@ -267,6 +272,12 @@ async function getCommits(force?: boolean): Promise<{
267272
validCommits.push(commit);
268273
}
269274

275+
// redo a pass to filter out commits without language scope
276+
const commitsWithoutLanguageScope = validCommits
277+
.filter((commit) => commit.languages.length === 0)
278+
.map((commit) => commit.message);
279+
validCommits = validCommits.filter((commit) => commit.languages.length > 0);
280+
270281
if (!force && validCommits.length === 0) {
271282
console.log(
272283
chalk.black.bgYellow('[INFO]'),
@@ -351,7 +362,7 @@ export async function createReleasePR({
351362

352363
// sometimes the scope of the commits is not set correctly and concerns another language, we can fix it.
353364
if (LANGUAGES.includes(validCommit.scope as Language) && validCommit.scope !== lang) {
354-
validCommit.message = validCommit.message.replace(`(${validCommit.scope}):`, `(${lang}):`);
365+
validCommit.message = validCommit.message.replace(`(${validCommit.scope}):`, '(clients):');
355366
}
356367

357368
const changelogCommit = [

scripts/release/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ export type ParsedCommit = {
2828
prNumber: number;
2929
};
3030

31-
export type Commit =
32-
| ParsedCommit
33-
| { error: 'generation-commit' }
34-
| { error: 'missing-language-scope'; message: string };
31+
export type Commit = ParsedCommit | { generated: true; languages: Language[]; message: string };
3532

3633
export type Changelog = {
3734
[lang in Language]?: string;

0 commit comments

Comments
 (0)