Skip to content

Commit 6a9ddb7

Browse files
authored
feat(dependency-manifest.ts): add support for Dependabot commit messages (#2584)
* feat(dependency-manifest.ts): add support for Dependabot commit messages Refactor regex matching to handle both Renovate and Dependabot commit messages for dependency updates. This change allows the versioning strategy to recognize and process dependency update commits from both tools, enhancing compatibility and automation in dependency management. * fix(dependency-manifest.ts): correct typo in DEPENDABOT_DEPENDENCY_UPDATE_REGEX test(dependency-manifest.ts): add tests for dependabot dependency updates Add tests to ensure correct version bumping for patch, minor, and major updates. Include tests for both 'chore(deps)' and 'build(deps)' commit messages. * style(test): reformat object initialization for better readability in dependency-manifest tests * refactor(dependency-manifest.ts): rename RENOVATE_DEPENDENCY_UPDATE_REGEX to DEPENDENCY_UPDATE_REGEX for clarity and reuse
1 parent e70680a commit 6a9ddb7

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

src/versioning-strategies/dependency-manifest.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import {
2626
const DEPENDENCY_UPDATE_REGEX =
2727
/^deps: update dependency (.*) to (v[^\s]*)(\s\(#\d+\))?$/m;
2828

29+
const DEPENDABOT_DEPENDENCY_UPDATE_REGEX =
30+
/^(?:chore|build)\(deps\): bump (.*) from [^\s]* to ([^\s]*)(\s\(#\d+\))?$/m;
31+
2932
/**
3033
* This VersioningStrategy looks at `deps` type commits and tries to
3134
* mirror the semantic version bump for that dependency update. For
@@ -85,12 +88,19 @@ export class DependencyManifest extends DefaultVersioningStrategy {
8588
}
8689
}
8790

91+
function matchCommit(commit: ConventionalCommit): RegExpMatchArray | null {
92+
return (
93+
commit.message.match(DEPENDENCY_UPDATE_REGEX) ||
94+
commit.message.match(DEPENDABOT_DEPENDENCY_UPDATE_REGEX)
95+
);
96+
}
97+
8898
function buildDependencyUpdates(
8999
commits: ConventionalCommit[]
90100
): Record<string, Version> {
91101
const versionsMap: Record<string, Version> = {};
92102
for (const commit of commits) {
93-
const match = commit.message.match(DEPENDENCY_UPDATE_REGEX);
103+
const match = matchCommit(commit);
94104
if (!match) continue;
95105

96106
const versionString = match[2];

test/versioning-strategies/dependency-manifest.ts

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,130 @@ describe('DependencyManifest', () => {
271271
expect(newVersion.toString()).to.equal('2.0.0');
272272
});
273273
});
274+
275+
describe('with a dependabot dependency update', () => {
276+
it('can bump a patch (chore)', async () => {
277+
const commits = [
278+
{
279+
sha: 'sha2',
280+
message: 'chore(deps): bump foo from 4.5.5 to 4.5.6',
281+
files: ['path1/file1.rb'],
282+
type: 'fix',
283+
scope: null,
284+
bareMessage: 'some bugfix',
285+
notes: [],
286+
references: [],
287+
breaking: false,
288+
},
289+
];
290+
const strategy = new DependencyManifest({});
291+
const oldVersion = Version.parse('1.2.3');
292+
const newVersion = await strategy.bump(oldVersion, commits);
293+
expect(newVersion.toString()).to.equal('1.2.4');
294+
});
295+
296+
it('can bump a minor (chore)', async () => {
297+
const commits = [
298+
{
299+
sha: 'sha2',
300+
message: 'chore(deps): bump foo from 4.4.9 to 4.5.0',
301+
files: ['path1/file1.rb'],
302+
type: 'fix',
303+
scope: null,
304+
bareMessage: 'some bugfix',
305+
notes: [],
306+
references: [],
307+
breaking: false,
308+
},
309+
];
310+
const strategy = new DependencyManifest({});
311+
const oldVersion = Version.parse('1.2.3');
312+
const newVersion = await strategy.bump(oldVersion, commits);
313+
expect(newVersion.toString()).to.equal('1.3.0');
314+
});
315+
316+
it('can bump a minor as a patch pre-major (chore)', async () => {
317+
const commits = [
318+
{
319+
sha: 'sha2',
320+
message: 'chore(deps): bump foo from 0.1.2 to 0.1.3',
321+
files: ['path1/file1.rb'],
322+
type: 'fix',
323+
scope: null,
324+
bareMessage: 'some bugfix',
325+
notes: [],
326+
references: [],
327+
breaking: false,
328+
},
329+
];
330+
const strategy = new DependencyManifest({
331+
bumpPatchForMinorPreMajor: true,
332+
});
333+
const oldVersion = Version.parse('0.1.2');
334+
const newVersion = await strategy.bump(oldVersion, commits);
335+
expect(newVersion.toString()).to.equal('0.1.3');
336+
});
337+
338+
it('can bump a major as a minor pre-major (chore)', async () => {
339+
const commits = [
340+
{
341+
sha: 'sha2',
342+
message: 'chore(deps): bump foo from 0.1.2 to 1.0.0',
343+
files: ['path1/file1.rb'],
344+
type: 'fix',
345+
scope: null,
346+
bareMessage: 'some bugfix',
347+
notes: [],
348+
references: [],
349+
breaking: false,
350+
},
351+
];
352+
const strategy = new DependencyManifest({
353+
bumpMinorPreMajor: true,
354+
});
355+
const oldVersion = Version.parse('0.1.2');
356+
const newVersion = await strategy.bump(oldVersion, commits);
357+
expect(newVersion.toString()).to.equal('0.2.0');
358+
});
359+
360+
it('can bump a major (with PR number, chore)', async () => {
361+
const commits = [
362+
{
363+
sha: 'sha2',
364+
message: 'chore(deps): bump foo from 3 to 4 (#1234)',
365+
files: ['path1/file1.rb'],
366+
type: 'fix',
367+
scope: null,
368+
bareMessage: 'some bugfix',
369+
notes: [],
370+
references: [],
371+
breaking: false,
372+
},
373+
];
374+
const strategy = new DependencyManifest({});
375+
const oldVersion = Version.parse('1.2.3');
376+
const newVersion = await strategy.bump(oldVersion, commits);
377+
expect(newVersion.toString()).to.equal('2.0.0');
378+
});
379+
380+
it('also matches build(deps) variant', async () => {
381+
const commits = [
382+
{
383+
sha: 'sha2',
384+
message: 'build(deps): bump bar from v1.2.3 to v1.2.4',
385+
files: ['path1/file1.rb'],
386+
type: 'fix',
387+
scope: null,
388+
bareMessage: 'some bugfix',
389+
notes: [],
390+
references: [],
391+
breaking: false,
392+
},
393+
];
394+
const strategy = new DependencyManifest({});
395+
const oldVersion = Version.parse('1.2.3');
396+
const newVersion = await strategy.bump(oldVersion, commits);
397+
expect(newVersion.toString()).to.equal('1.2.4');
398+
});
399+
});
274400
});

0 commit comments

Comments
 (0)