Update link branches to main (continued) (#146985)

I generalized the analysis to match all `googlesource.com` repos. I also
added a test and fixed more cases.

Part of https://github.com/flutter/flutter/issues/121564

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Data Driven Fixes]:
https://github.com/flutter/flutter/wiki/Data-driven-Fixes
This commit is contained in:
Pierre-Louis
2024-04-19 10:46:24 +02:00
committed by GitHub
parent 12d54de962
commit 4deff2dd9c
7 changed files with 62 additions and 28 deletions

View File

@@ -1316,38 +1316,36 @@ Future<void> verifyRepositoryLinks(String workingDirectory) async {
'tpn/winsdk-10',
};
const List<String> linkPrefixes = <String>[
'https://raw.githubusercontent.com/',
'https://github.com/',
];
// See dev/bots/test/analyze-test-input/root/packages/foo/bad_repository_links.dart
// for examples of repository links that are not allowed.
final RegExp pattern = RegExp(r'^(https:\/\/(?:cs\.opensource\.google|github|raw\.githubusercontent|source\.chromium|([a-z0-9\-]+)\.googlesource)\.)');
final List<String> problems = <String>[];
final Set<String> suggestions = <String>{};
final List<File> files = await _gitFiles(workingDirectory);
final List<File> files = await _allFiles(workingDirectory, null, minimumMatches: 10).toList();
for (final File file in files) {
for (final String linkPrefix in linkPrefixes) {
final Uint8List bytes = file.readAsBytesSync();
// We allow invalid UTF-8 here so that binaries don't trip us up.
// There's a separate test in this file that verifies that all text
// files are actually valid UTF-8 (see verifyNoBinaries below).
final String contents = utf8.decode(bytes, allowMalformed: true);
int start = 0;
while ((start = contents.indexOf(linkPrefix, start)) >= 0) {
int end = start + linkPrefixes.length;
while (end < contents.length && !stops.contains(contents[end])) {
end += 1;
}
final String url = contents.substring(start, end);
if (url.startsWith(linkPrefix) && !repoExceptions.any(url.contains)) {
if (url.contains('master')) {
problems.add('${file.path} contains $url, which uses the banned "master" branch.');
suggestions.add('Change the URLs above to the expected pattern by '
final Uint8List bytes = file.readAsBytesSync();
// We allow invalid UTF-8 here so that binaries don't trip us up.
// There's a separate test in this file that verifies that all text
// files are actually valid UTF-8 (see verifyNoBinaries below).
final String contents = utf8.decode(bytes, allowMalformed: true);
int start = 0;
while ((start = contents.indexOf('https://', start)) >= 0) { // Find all 'https://' links
int end = start + 8; // Length of 'https://'
while (end < contents.length && !stops.contains(contents[end])) {
end += 1;
}
final String url = contents.substring(start, end).replaceAll('\r', '');
if (pattern.hasMatch(url) && !repoExceptions.any(url.contains)) {
if (url.contains('master')) {
problems.add('${file.path} contains $url, which uses the banned "master" branch.');
suggestions.add('Change the URLs above to the expected pattern by '
'using the "main" branch if it exists, otherwise adding the '
'repository to the list of exceptions in analyze.dart.');
}
}
start = end;
}
start = end;
}
}
assert(problems.isEmpty == suggestions.isEmpty);