Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 89eff49

Browse files
[tool] Handle dependabot commit messages (#6127)
1 parent e92ede2 commit 89eff49

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

script/tool/lib/src/version_check_command.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,12 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.
627627

628628
// A string that is in all Dependabot PRs, but extremely unlikely to be in
629629
// any other PR, to identify Dependabot PRs.
630-
const String dependabotMarker = 'Dependabot commands and options';
630+
const String dependabotPRDescriptionMarker =
631+
'Dependabot commands and options';
632+
// The same thing, but for the Dependabot commit message, to work around
633+
// https://github.com/cirruslabs/cirrus-ci-docs/issues/1029.
634+
const String dependabotCommitMessageMarker =
635+
'Signed-off-by: dependabot[bot]';
631636
// Expression to extract the name of the dependency being updated.
632637
final RegExp dependencyRegex =
633638
RegExp(r'Bumps? \[(.*?)\]\(.*?\) from [\d.]+ to [\d.]+');
@@ -641,7 +646,8 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.
641646
'mockito-' // mockito-core, mockito-inline, etc.
642647
};
643648

644-
if (changeDescription.contains(dependabotMarker)) {
649+
if (changeDescription.contains(dependabotPRDescriptionMarker) ||
650+
changeDescription.contains(dependabotCommitMessageMarker)) {
645651
final Match? match = dependencyRegex.firstMatch(changeDescription);
646652
if (match != null) {
647653
final String dependency = match.group(1)!;

script/tool/test/version_check_command_test.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ You can trigger Dependabot actions by commenting on this PR:
8989
''';
9090
}
9191

92+
String _generateFakeDependabotCommitMessage(String package) {
93+
return '''
94+
Bumps [$package](https://github.com/foo/$package) from 1.0.0 to 2.0.0.
95+
- [Release notes](https://github.com/foo/$package/releases)
96+
- [Commits](foo/$package@v4.3.1...v4.6.1)
97+
98+
---
99+
updated-dependencies:
100+
- dependency-name: $package
101+
dependency-type: direct:production
102+
update-type: version-update:semver-minor
103+
...
104+
105+
Signed-off-by: dependabot[bot] <support@github.com>
106+
''';
107+
}
108+
92109
class MockProcessResult extends Mock implements io.ProcessResult {}
93110

94111
void main() {
@@ -1290,6 +1307,47 @@ packages/plugin/android/build.gradle
12901307
]),
12911308
);
12921309
});
1310+
1311+
// Tests workaround for
1312+
// https://github.com/cirruslabs/cirrus-ci-docs/issues/1029.
1313+
test('allow list works for commit messages', () async {
1314+
final RepositoryPackage plugin =
1315+
createFakePlugin('plugin', packagesDir, version: '1.0.0');
1316+
1317+
const String changelog = '''
1318+
## 1.0.0
1319+
* Some changes.
1320+
''';
1321+
plugin.changelogFile.writeAsStringSync(changelog);
1322+
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
1323+
MockProcess(stdout: 'version: 1.0.0'),
1324+
];
1325+
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
1326+
MockProcess(stdout: '''
1327+
packages/plugin/android/build.gradle
1328+
'''),
1329+
];
1330+
1331+
final File changeDescriptionFile =
1332+
fileSystem.file('change_description.txt');
1333+
changeDescriptionFile.writeAsStringSync(
1334+
_generateFakeDependabotCommitMessage('mockito-core'));
1335+
1336+
final List<String> output =
1337+
await _runWithMissingChangeDetection(<String>[
1338+
'--change-description-file=${changeDescriptionFile.path}'
1339+
]);
1340+
1341+
expect(
1342+
output,
1343+
containsAllInOrder(<Matcher>[
1344+
contains('Ignoring lack of version change for Dependabot '
1345+
'change to a known internal dependency.'),
1346+
contains('Ignoring lack of CHANGELOG update for Dependabot '
1347+
'change to a known internal dependency.'),
1348+
]),
1349+
);
1350+
});
12931351
});
12941352
});
12951353

0 commit comments

Comments
 (0)