Skip to content

Commit 39ca1f1

Browse files
committed
chore(changelog): handle grouped dependabot bumps
1 parent b156478 commit 39ca1f1

File tree

1 file changed

+88
-16
lines changed

1 file changed

+88
-16
lines changed

scripts/changelog.js

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ async function main(logger) {
2929
currentVersion,
3030
);
3131

32-
const commits = combineCommits(
33-
commitsSinceLastVersion.filter((it) => {
34-
return (
35-
!it.title.includes("@types/node") &&
36-
!it.title.includes("sync generated doc files")
37-
);
38-
}),
39-
);
32+
const relevantCommits = commitsSinceLastVersion.filter((it) => {
33+
return (
34+
!it.title.includes("build(deps-dev)") &&
35+
!it.title.includes("@types/node") &&
36+
!it.title.includes("typescript-types group") &&
37+
!it.title.includes("sync generated doc files")
38+
);
39+
});
40+
41+
const splitCommits = splitGroupedDependencyBumps(relevantCommits);
42+
const commits = combineCommits(splitCommits);
43+
4044
decorateCommits(commits);
4145

4246
const proposedVersion = proposeVersionBump(currentVersion, commits);
@@ -104,6 +108,75 @@ function getChangelogHeaderAndSource(changelog) {
104108
};
105109
}
106110

111+
/**
112+
* Split grouped dependency updates.
113+
*
114+
* @param {ChangelogCommit[]} commits
115+
* @returns {ChangelogCommit[]}
116+
*/
117+
function splitGroupedDependencyBumps(commits) {
118+
const result = [];
119+
120+
// Updates `@aws-sdk/client-s3` from 3.369.0 to 3.370.0
121+
// Updates `@babel/eslint-parser` from 7.22.7 to 7.22.9
122+
const subDepStartMatch =
123+
/Updates `([\w\-@/]+)` from (\d+\.\d+\.\d+) to (\d+\.\d+\.\d+)$/g;
124+
125+
for (const commit of commits) {
126+
if (
127+
commit.title.includes("bump the") &&
128+
commit.title.includes("group with")
129+
) {
130+
// Grouped commit
131+
const [, pr] = commit.title.match(/\(#(\d+)\)?/) ?? [];
132+
const lines = commit.body.split("\n");
133+
134+
let dependency;
135+
let fromVersion;
136+
let toVersion;
137+
let body = "";
138+
139+
const finishCommit = () => {
140+
if (dependency && body) {
141+
result.push({
142+
title: `build(deps): bump ${dependency} from ${fromVersion} to ${toVersion} (#${pr})`,
143+
hash: commit.hash,
144+
body,
145+
notes: [],
146+
});
147+
}
148+
149+
dependency = undefined;
150+
fromVersion = undefined;
151+
toVersion = undefined;
152+
body = "";
153+
};
154+
155+
for (const line of lines) {
156+
subDepStartMatch.lastIndex = -1;
157+
const [, dep, from, to] = subDepStartMatch.exec(line.trim()) ?? [];
158+
159+
if (dep) {
160+
finishCommit();
161+
162+
dependency = dep;
163+
fromVersion = from;
164+
toVersion = to;
165+
} else if (dependency) {
166+
body += `${line}\n`;
167+
}
168+
}
169+
170+
finishCommit();
171+
} else {
172+
// Any other commit
173+
result.push(commit);
174+
}
175+
}
176+
177+
return result;
178+
}
179+
107180
/**
108181
* Tries to combine the dependency bump commits. This is useful for things like aws-sdk
109182
* which can have 10 bumps in a single Compas release.
@@ -115,7 +188,7 @@ function combineCommits(commits) {
115188
// build(deps): bump @types/node from 14.6.2 to 14.6.3
116189
// build(deps-dev): bump react-query from 2.12.1 to 2.13.0 (#234)
117190
const depRegex =
118-
/^build\((deps|deps-dev)\): bump ([\w\-@/]+) from (\d+\.\d+\.\d+) to (\d+\.\d+\.\d+)(?:\s\(#(\d+)\))?$/g;
191+
/^build\((deps)\): bump ([\w\-@/]+) from (\d+\.\d+\.\d+) to (\d+\.\d+\.\d+)(?:\s\(#(\d+)\))?$/g;
119192

120193
const combinable = {};
121194
const result = [];
@@ -156,11 +229,6 @@ function combineCommits(commits) {
156229
for (const pkg of Object.keys(combinable)) {
157230
const { buildType, prs, fromVersion, toVersion, body } = combinable[pkg];
158231

159-
if (buildType === "deps-dev") {
160-
// We don't need development dependency updates in the changelog
161-
continue;
162-
}
163-
164232
// Format PR numbers so the writer can create correct urls
165233
const finalPrs =
166234
prs.length > 0 ? ` (${prs.map((it) => `#${it}`).join(", ")})` : "";
@@ -201,7 +269,7 @@ function decorateCommits(commits) {
201269
// build(deps): bump @types/node from 14.6.2 to 14.6.3
202270
// build(deps-dev): bump react-query from 2.12.1 to 2.13.0 (#234)
203271
const depsCommitMatch = commit.title.match(
204-
/^build\((deps|deps-dev)\): bump ([\w\-@/]+) from (\d+\.\d+\.\d+) to (\d+\.\d+\.\d+)/i,
272+
/^build\((deps)\): bump ([\w\-@/]+) from (\d+\.\d+\.\d+) to (\d+\.\d+\.\d+)/i,
205273
);
206274

207275
// depsCommitMatch[3] is the first mentioned version, if that one exists, we also
@@ -429,7 +497,11 @@ function formatHash(commit) {
429497
* @returns {string}
430498
*/
431499
function proposeVersionBump(version, commits) {
432-
const hasBreakingChanges = commits.find((it) => it.breakingChange);
500+
const hasBreakingChanges = commits.find(
501+
(it) =>
502+
it.breakingChange ||
503+
it.notes.find((note) => note === "- Major version bump"),
504+
);
433505
const hasFeat = commits.find((it) => it.title.startsWith("feat"));
434506

435507
const type = hasBreakingChanges ? "major" : hasFeat ? "minor" : "patch";

0 commit comments

Comments
 (0)