Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert relative site URLs in release notes #7529

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ bool debugTestReleaseNotes = false;
const String? _debugReleaseNotesUrl = null;

const releaseNotesKey = Key('release_notes');
const _unsupportedPathSyntax = '{{site.url}}';
final _baseUrlRelativeMarkdownLinkPattern = RegExp(
r'(\[.*?]\()(/.*\s*)',
multiLine: true,
);
const _releaseNotesPath = '/f/devtools-releases.json';
final _flutterDocsSite = Uri.https('docs.flutter.dev');

Expand Down Expand Up @@ -97,10 +100,11 @@ class ReleaseNotesController extends SidePanelController {
final debugUri = Uri.parse(debugUrl);
final releaseNotesMarkdown = await http.read(debugUri);

// Update image links to use debug/testing URL.
markdown.value = releaseNotesMarkdown.replaceAll(
_unsupportedPathSyntax,
debugUri.replace(path: '').toString(),
// Update the base-url-relative links in the file to
// absolute links using the debug/testing URL.
markdown.value = _convertBaseUrlRelativeLinks(
releaseNotesMarkdown,
debugUri.replace(path: ''),
);

toggleVisibility(true);
Expand Down Expand Up @@ -145,7 +149,7 @@ class ReleaseNotesController extends SidePanelController {
// release notes (e.g. 2.11.4 -> 2.11.3 -> 2.11.2 -> ...).
while (patchToCheck >= minimumPatch) {
final releaseToCheck = '$majorMinor.$patchToCheck';
if (releases[releaseToCheck] case final String releaseNotePath) {
if (releases[releaseToCheck] case final releaseNotePath?) {
final String releaseNotesMarkdown;
try {
releaseNotesMarkdown = await http.read(
Expand All @@ -161,11 +165,10 @@ class ReleaseNotesController extends SidePanelController {
continue;
}

// Replace the {{site.url}} template syntax that the
// Flutter docs website uses to specify site URLs.
markdown.value = releaseNotesMarkdown.replaceAll(
_unsupportedPathSyntax,
_flutterDocsSite.toString(),
// Update the base-url-relative links in the file to absolute links.
markdown.value = _convertBaseUrlRelativeLinks(
releaseNotesMarkdown,
_flutterDocsSite,
);

toggleVisibility(true);
Expand All @@ -188,13 +191,21 @@ class ReleaseNotesController extends SidePanelController {
return;
}

/// Convert all site-base-url relative links in [markdownContent]
/// to absolute links from the specified [baseUrl].
parlough marked this conversation as resolved.
Show resolved Hide resolved
String _convertBaseUrlRelativeLinks(String markdownContent, Uri baseUrl) =>
markdownContent.replaceAllMapped(
_baseUrlRelativeMarkdownLinkPattern,
(m) => '${m[1]}${baseUrl.toString()}${m[2]}',
);

/// Retrieve and parse the release note index from the
/// Flutter website at [_flutterDocsSite]/[_releaseNotesPath].
///
/// Calls [_emptyAndClose] and returns `null` if
/// the retrieval or parsing fails.
@visibleForTesting
Future<Map<String, Object?>?> retrieveReleasesFromIndex() async {
Future<Map<String, String>?> retrieveReleasesFromIndex() async {
final Map<String, Object?> releaseIndex;
try {
final releaseIndexString = await http.read(releaseIndexUrl);
Expand All @@ -212,7 +223,7 @@ class ReleaseNotesController extends SidePanelController {
);
return null;
}
return releaseIndex;
return releases.cast<String, String>();
}

/// Set the release notes viewer as having no contents, hidden,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is draft for future release notes, that are going to land on
The 2.36.0 release of the Dart and Flutter DevTools
includes the following changes among other general improvements.
To learn more about DevTools, check out the
[DevTools overview]({{site.url}}/tools/devtools/overview).
[DevTools overview](/tools/devtools/overview).

## General updates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is draft for future release notes, that are going to land on
The <number> release of the Dart and Flutter DevTools
includes the following changes among other general improvements.
To learn more about DevTools, check out the
[DevTools overview]({{site.url}}/tools/devtools/overview).
[DevTools overview](/tools/devtools/overview).

## General updates

Expand Down
6 changes: 2 additions & 4 deletions packages/devtools_app/test/shared/release_notes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ void main() {
test('Parses expected index format correctly', () async {
await http.runWithClient(
() async {
final response = await controller.retrieveReleasesFromIndex();
expect(response!.keys, hasLength(2));
expect(response['latest'], equals('2.32.0'));
final releaseIndex = await controller.retrieveReleasesFromIndex();
expect(
response['releases'],
releaseIndex,
equals({
'2.32.0':
'/tools/devtools/release-notes/release-notes-2.32.0-src.md',
Expand Down