From 603bc8bda8b7c4837b1d2328594241205d10563d Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Thu, 26 Nov 2026 17:09:03 +0100 Subject: [PATCH 1/4] [dash_site] Combine staged site previews into a single PR comment with status indicators --- .../lib/src/commands/stage_preview.dart | 132 ++++----- tool/dash_site/lib/src/preview_comments.dart | 252 ++++++++++++++++++ .../dash_site/test/preview_comments_test.dart | 197 ++++++++++++++ 3 files changed, 503 insertions(+), 78 deletions(-) create mode 100644 tool/dash_site/lib/src/preview_comments.dart create mode 100644 tool/dash_site/test/preview_comments_test.dart diff --git a/tool/dash_site/lib/src/commands/stage_preview.dart b/tool/dash_site/lib/src/commands/stage_preview.dart index da5e4959bc..34879f2dd1 100644 --- a/tool/dash_site/lib/src/commands/stage_preview.dart +++ b/tool/dash_site/lib/src/commands/stage_preview.dart @@ -6,11 +6,11 @@ import 'dart:convert'; import 'dart:io'; import 'package:args/command_runner.dart'; -import 'package:github/github.dart' as github; import 'package:path/path.dart' as path; import '../firebase.dart'; import '../preview_changes.dart'; +import '../preview_comments.dart'; import '../sites.dart'; import '../utils.dart'; import 'build.dart'; @@ -164,13 +164,50 @@ final class StagePreviewCommand extends Command { return 0; } + if (prContext != null) { + try { + await updatePreviewCommentOnGitHub( + site: selectedSite, + status: PreviewStatus.pending, + prNumber: prContext.prNumber, + repoFullName: prContext.repoFullName, + commitSha: prContext.commitSha, + githubToken: prContext.githubToken, + ); + } on Exception catch (error) { + stderr.writeln( + 'Warning: Failed to post pending status on pull request: $error', + ); + } + } + final firebaseToolsVersion = await validateFirebaseCli(); if (firebaseToolsVersion == null) { + if (prContext != null) { + await updatePreviewCommentOnGitHub( + site: selectedSite, + status: PreviewStatus.failed, + prNumber: prContext.prNumber, + repoFullName: prContext.repoFullName, + commitSha: prContext.commitSha, + githubToken: prContext.githubToken, + ); + } return 1; } if (await buildSite(selectedSite, productionRelease: false) case final buildResult when buildResult != 0) { + if (prContext != null) { + await updatePreviewCommentOnGitHub( + site: selectedSite, + status: PreviewStatus.failed, + prNumber: prContext.prNumber, + repoFullName: prContext.repoFullName, + commitSha: prContext.commitSha, + githubToken: prContext.githubToken, + ); + } return buildResult; } @@ -189,6 +226,16 @@ final class StagePreviewCommand extends Command { expires: expires, ); if (stagingUrl == null) { + if (prContext != null) { + await updatePreviewCommentOnGitHub( + site: selectedSite, + status: PreviewStatus.failed, + prNumber: prContext.prNumber, + repoFullName: prContext.repoFullName, + commitSha: prContext.commitSha, + githubToken: prContext.githubToken, + ); + } return 1; } @@ -198,10 +245,14 @@ final class StagePreviewCommand extends Command { return 0; } - return await _commentStagingUrlOnGitHub( + return await updatePreviewCommentOnGitHub( site: selectedSite, + status: PreviewStatus.ready, stagingUrl: stagingUrl, - context: prContext, + prNumber: prContext.prNumber, + repoFullName: prContext.repoFullName, + commitSha: prContext.commitSha, + githubToken: prContext.githubToken, ); } } @@ -270,81 +321,6 @@ String? _extractDeployedUrl(String firebaseJsonOutput) { return null; } -/// Posts a new preview comment on the pull request, -/// or updates the existing one identified by an HTML marker that -/// includes the [site]'s name. -/// -/// Returns `0` on success or `1` if the GitHub API call fails. -Future _commentStagingUrlOnGitHub({ - required Site site, - required String stagingUrl, - required _PullRequestContext context, -}) async { - final commentMarker = ''; - final commentBody = - ''' -$commentMarker -Staged preview of the updated ${site.host} site (updated for commit ${context.commitSha}): - -$stagingUrl'''; - - print('Commenting ${site.host} staging URL on the PR...'); - final gitHub = github.GitHub( - auth: github.Authentication.withToken(context.githubToken), - ); - try { - final repository = github.RepositorySlug.full(context.repoFullName); - final existingCommentId = await _findExistingPreviewCommentId( - gitHub: gitHub, - repository: repository, - issueNumber: context.prNumber, - commentMarker: commentMarker, - ); - - if (existingCommentId == null) { - await gitHub.issues.createComment( - repository, - context.prNumber, - commentBody, - ); - } else { - await gitHub.issues.updateComment( - repository, - existingCommentId, - commentBody, - ); - } - } on github.GitHubError catch (error) { - stderr.writeln('Error: Failed to comment on the pull request: $error'); - return 1; - } finally { - gitHub.dispose(); - } - - return 0; -} - -/// Returns the id of the first comment on the issue whose body -/// contains the specified [commentMarker]. -/// -/// Returns `null` if no matching comment exists. -Future _findExistingPreviewCommentId({ - required github.GitHub gitHub, - required github.RepositorySlug repository, - required int issueNumber, - required String commentMarker, -}) async { - await for (final comment in gitHub.issues.listCommentsByIssue( - repository, - issueNumber, - )) { - if (comment.body?.contains(commentMarker) ?? false) { - return comment.id; - } - } - return null; -} - /// Builds a Firebase Hosting channel name for [site] that /// incorporates [branchOrSha] and if specified, [prNumber], /// and satisfies Firebase's naming constraints: diff --git a/tool/dash_site/lib/src/preview_comments.dart b/tool/dash_site/lib/src/preview_comments.dart new file mode 100644 index 0000000000..fc586405b5 --- /dev/null +++ b/tool/dash_site/lib/src/preview_comments.dart @@ -0,0 +1,252 @@ +// Copyright 2026 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:convert'; +import 'dart:io'; + +import 'package:github/github.dart' as github; + +import 'sites.dart'; + +/// Marker prefix used to identify staging preview comments. +const previewCommentMarker = ''; + +/// The deployment and build status of a preview. +enum PreviewStatus { + pending('⏳ Building'), + ready('✅ Ready'), + failed('❌ Failed'); + + const PreviewStatus(this.label); + + /// Human-readable label with an emoji indicator. + final String label; +} + +/// Staged preview metadata for a single [Site]. +final class PreviewEntry { + const PreviewEntry({required this.status, this.url, required this.commitSha}); + + /// The build and deployment status of this preview. + final PreviewStatus status; + + /// The public staging URL for this preview, if ready. + final String? url; + + /// The commit SHA for which this preview was built or deployed. + final String commitSha; + + Map toJson() => { + 'status': status.name, + if (url != null) 'url': url, + 'commitSha': commitSha, + }; + + static PreviewEntry? fromJson(Object? json) { + if (json + case { + 'status': final String statusName, + 'commitSha': final String commitSha, + } + when commitSha.isNotEmpty) { + final status = + PreviewStatus.values.asNameMap()[statusName] ?? PreviewStatus.ready; + final url = json['url'] as String?; + return PreviewEntry(status: status, url: url, commitSha: commitSha); + } + + if (json case {'url': final String url, 'commitSha': final String commitSha} + when url.isNotEmpty && commitSha.isNotEmpty) { + return PreviewEntry( + status: PreviewStatus.ready, + url: url, + commitSha: commitSha, + ); + } + + return null; + } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is PreviewEntry && + other.runtimeType == runtimeType && + other.status == status && + other.url == url && + other.commitSha == commitSha; + + @override + int get hashCode => Object.hash(status, url, commitSha); + + @override + String toString() => + 'PreviewEntry(status: $status, url: $url, commitSha: $commitSha)'; +} + +/// Parses existing [PreviewEntry] values by site from a preview [commentBody]. +/// +/// Reads machine-readable JSON metadata from the +/// `` marker. +Map parsePreviewCommentEntries(String commentBody) { + final entries = {}; + + final dataMatch = RegExp(r'') + .firstMatch(commentBody); + + if (dataMatch != null) { + try { + final jsonStr = dataMatch.group(1); + final decoded = jsonDecode(jsonStr!) as Object?; + if (decoded case final Map map) { + final siteMap = Site.values.asNameMap(); + for (final MapEntry(:key, :value) in map.entries) { + final site = siteMap[key]; + if (site == null) continue; + final entry = PreviewEntry.fromJson(value); + if (entry != null) { + entries[site] = entry; + } + } + } + } catch (_) { + // Ignore malformed JSON metadata. + } + } + + return entries; +} + +/// Generates the Markdown body for the combined staging preview comment. +/// +/// Formats a table dashboard with status emojis, preview links, and commit +/// links for all staged sites. +String buildPreviewCommentBody( + Map previews, { + String? repoFullName, +}) { + final buffer = StringBuffer(); + buffer.writeln(previewCommentMarker); + + final data = { + for (final MapEntry(:key, :value) in previews.entries) + key.name: value.toJson(), + }; + buffer.writeln(''); + buffer.writeln('### 🚀 Staged Previews'); + buffer.writeln(); + buffer.writeln('| Site | Status | Preview Link | Commit |'); + buffer.writeln('| :--- | :--- | :--- | :--- |'); + + final sortedSites = previews.keys.toList() + ..sort((a, b) => a.index.compareTo(b.index)); + + for (final site in sortedSites) { + final entry = previews[site]!; + final shortSha = entry.commitSha.length > 7 + ? entry.commitSha.substring(0, 7) + : entry.commitSha; + + final commitDisplay = repoFullName != null + ? '[`$shortSha`](https://github.com/$repoFullName/commit/${entry.commitSha})' + : '`$shortSha`'; + + final previewLink = switch (entry.status) { + PreviewStatus.ready when entry.url != null => + '[Visit Preview ↗](${entry.url})', + PreviewStatus.pending => '_Deploying..._', + PreviewStatus.failed => '_Failed_', + _ => '—', + }; + + buffer.writeln( + '| **${site.host}** | ${entry.status.label} | ' + '$previewLink | $commitDisplay |', + ); + } + + return buffer.toString().trimRight(); +} + +/// Finds the ID of an existing preview comment on [issueNumber], if present. +Future findExistingPreviewCommentId({ + required github.GitHub gitHub, + required github.RepositorySlug repository, + required int issueNumber, +}) async { + await for (final comment in gitHub.issues.listCommentsByIssue( + repository, + issueNumber, + )) { + final body = comment.body; + if (body != null && body.contains(previewCommentMarker)) { + return comment.id; + } + } + return null; +} + +/// Updates or creates the staged preview comment on the pull request. +/// +/// Sets the [status] and optional [stagingUrl] for [site] on the PR, +/// maintaining all site previews in a single dashboard comment. +/// +/// Returns `0` on success or `1` if the GitHub API call fails. +Future updatePreviewCommentOnGitHub({ + required Site site, + required PreviewStatus status, + String? stagingUrl, + required int prNumber, + required String repoFullName, + required String commitSha, + required String githubToken, +}) async { + final gitHub = github.GitHub( + auth: github.Authentication.withToken(githubToken), + ); + try { + final repository = github.RepositorySlug.full(repoFullName); + + github.IssueComment? existingComment; + await for (final comment in gitHub.issues.listCommentsByIssue( + repository, + prNumber, + )) { + final body = comment.body; + if (body != null && body.contains(previewCommentMarker)) { + existingComment = comment; + break; + } + } + + final previews = {}; + if (existingComment?.body case final body?) { + previews.addAll(parsePreviewCommentEntries(body)); + } + + previews[site] = PreviewEntry( + status: status, + url: stagingUrl, + commitSha: commitSha, + ); + + final commentBody = buildPreviewCommentBody( + previews, + repoFullName: repoFullName, + ); + + if (existingComment?.id case final commentId?) { + await gitHub.issues.updateComment(repository, commentId, commentBody); + } else { + await gitHub.issues.createComment(repository, prNumber, commentBody); + } + } on github.GitHubError catch (error) { + stderr.writeln('Error: Failed to comment on the pull request: $error'); + return 1; + } finally { + gitHub.dispose(); + } + + return 0; +} diff --git a/tool/dash_site/test/preview_comments_test.dart b/tool/dash_site/test/preview_comments_test.dart new file mode 100644 index 0000000000..cb9da1c045 --- /dev/null +++ b/tool/dash_site/test/preview_comments_test.dart @@ -0,0 +1,197 @@ +// Copyright 2026 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:dash_site/src/preview_comments.dart'; +import 'package:dash_site/src/sites.dart'; +import 'package:test/test.dart'; + +void main() { + group('PreviewEntry', () { + test('serializes and deserializes ready status', () { + const entry = PreviewEntry( + status: PreviewStatus.ready, + url: 'https://flutter-docs-prod--pr100.web.app', + commitSha: '4977bb96d8ac0d94e8954c0682c80adce95b810e', + ); + + final json = entry.toJson(); + expect(PreviewEntry.fromJson(json), equals(entry)); + }); + + test('serializes and deserializes pending status without url', () { + const entry = PreviewEntry( + status: PreviewStatus.pending, + commitSha: '4977bb96d8ac0d94e8954c0682c80adce95b810e', + ); + + final json = entry.toJson(); + expect(json.containsKey('url'), isFalse); + expect(PreviewEntry.fromJson(json), equals(entry)); + }); + + test('serializes and deserializes failed status', () { + const entry = PreviewEntry( + status: PreviewStatus.failed, + commitSha: '4977bb96d8ac0d94e8954c0682c80adce95b810e', + ); + + final json = entry.toJson(); + expect(PreviewEntry.fromJson(json), equals(entry)); + }); + + test('returns null on invalid JSON', () { + expect(PreviewEntry.fromJson(null), isNull); + expect(PreviewEntry.fromJson({}), isNull); + expect(PreviewEntry.fromJson({'status': 'ready'}), isNull); + }); + }); + + group('buildPreviewCommentBody', () { + test('formats a single pending site table cleanly', () { + final previews = { + Site.docs: const PreviewEntry( + status: PreviewStatus.pending, + commitSha: '4977bb96d8ac0d94e8954c0682c80adce95b810e', + ), + }; + + final body = buildPreviewCommentBody( + previews, + repoFullName: 'flutter/website', + ); + + expect(body, contains(previewCommentMarker)); + expect(body, contains(' + +### 🚀 Staged Previews +'''; + + expect(parsePreviewCommentEntries(corruptBody), isEmpty); + }); + + test('returns empty map for unrelated comment', () { + expect(parsePreviewCommentEntries('Hello world! LGTM!'), isEmpty); + }); + }); +} From 6b168ba1e553305a8370206590089ee4b0ec6328 Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Fri, 27 Nov 2026 10:29:54 +0100 Subject: [PATCH 2/4] Address review feedback on preview comments --- .../lib/src/commands/stage_preview.dart | 22 +++----- tool/dash_site/lib/src/preview_comments.dart | 55 ++++++++++++------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/tool/dash_site/lib/src/commands/stage_preview.dart b/tool/dash_site/lib/src/commands/stage_preview.dart index 34879f2dd1..96327871bb 100644 --- a/tool/dash_site/lib/src/commands/stage_preview.dart +++ b/tool/dash_site/lib/src/commands/stage_preview.dart @@ -165,20 +165,14 @@ final class StagePreviewCommand extends Command { } if (prContext != null) { - try { - await updatePreviewCommentOnGitHub( - site: selectedSite, - status: PreviewStatus.pending, - prNumber: prContext.prNumber, - repoFullName: prContext.repoFullName, - commitSha: prContext.commitSha, - githubToken: prContext.githubToken, - ); - } on Exception catch (error) { - stderr.writeln( - 'Warning: Failed to post pending status on pull request: $error', - ); - } + await updatePreviewCommentOnGitHub( + site: selectedSite, + status: PreviewStatus.pending, + prNumber: prContext.prNumber, + repoFullName: prContext.repoFullName, + commitSha: prContext.commitSha, + githubToken: prContext.githubToken, + ); } final firebaseToolsVersion = await validateFirebaseCli(); diff --git a/tool/dash_site/lib/src/preview_comments.dart b/tool/dash_site/lib/src/preview_comments.dart index fc586405b5..15d653e691 100644 --- a/tool/dash_site/lib/src/preview_comments.dart +++ b/tool/dash_site/lib/src/preview_comments.dart @@ -45,18 +45,23 @@ final class PreviewEntry { static PreviewEntry? fromJson(Object? json) { if (json - case { - 'status': final String statusName, - 'commitSha': final String commitSha, - } + case final Map map && + { + 'status': final String statusName, + 'commitSha': final String commitSha, + } when commitSha.isNotEmpty) { final status = PreviewStatus.values.asNameMap()[statusName] ?? PreviewStatus.ready; - final url = json['url'] as String?; + final url = map['url'] as String?; return PreviewEntry(status: status, url: url, commitSha: commitSha); } - if (json case {'url': final String url, 'commitSha': final String commitSha} + if (json + case { + 'url': final String url, + 'commitSha': final String commitSha, + } when url.isNotEmpty && commitSha.isNotEmpty) { return PreviewEntry( status: PreviewStatus.ready, @@ -169,8 +174,8 @@ String buildPreviewCommentBody( return buffer.toString().trimRight(); } -/// Finds the ID of an existing preview comment on [issueNumber], if present. -Future findExistingPreviewCommentId({ +/// Finds an existing preview comment on [issueNumber], if present. +Future findExistingPreviewComment({ required github.GitHub gitHub, required github.RepositorySlug repository, required int issueNumber, @@ -181,12 +186,26 @@ Future findExistingPreviewCommentId({ )) { final body = comment.body; if (body != null && body.contains(previewCommentMarker)) { - return comment.id; + return comment; } } return null; } +/// Finds the ID of an existing preview comment on [issueNumber], if present. +Future findExistingPreviewCommentId({ + required github.GitHub gitHub, + required github.RepositorySlug repository, + required int issueNumber, +}) async { + final comment = await findExistingPreviewComment( + gitHub: gitHub, + repository: repository, + issueNumber: issueNumber, + ); + return comment?.id; +} + /// Updates or creates the staged preview comment on the pull request. /// /// Sets the [status] and optional [stagingUrl] for [site] on the PR, @@ -208,17 +227,11 @@ Future updatePreviewCommentOnGitHub({ try { final repository = github.RepositorySlug.full(repoFullName); - github.IssueComment? existingComment; - await for (final comment in gitHub.issues.listCommentsByIssue( - repository, - prNumber, - )) { - final body = comment.body; - if (body != null && body.contains(previewCommentMarker)) { - existingComment = comment; - break; - } - } + final existingComment = await findExistingPreviewComment( + gitHub: gitHub, + repository: repository, + issueNumber: prNumber, + ); final previews = {}; if (existingComment?.body case final body?) { @@ -241,7 +254,7 @@ Future updatePreviewCommentOnGitHub({ } else { await gitHub.issues.createComment(repository, prNumber, commentBody); } - } on github.GitHubError catch (error) { + } on Exception catch (error) { stderr.writeln('Error: Failed to comment on the pull request: $error'); return 1; } finally { From 3f30c76bb58da9e76ef100bb7f702d4a189a8bb2 Mon Sep 17 00:00:00 2001 From: Kilian Schulte Date: Fri, 27 Nov 2026 10:41:57 +0100 Subject: [PATCH 3/4] Retain existing preview link and show rebuilding status when updating --- tool/dash_site/lib/src/preview_comments.dart | 17 +++++++--- .../dash_site/test/preview_comments_test.dart | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tool/dash_site/lib/src/preview_comments.dart b/tool/dash_site/lib/src/preview_comments.dart index 15d653e691..eabebb1f76 100644 --- a/tool/dash_site/lib/src/preview_comments.dart +++ b/tool/dash_site/lib/src/preview_comments.dart @@ -15,6 +15,7 @@ const previewCommentMarker = ''; /// The deployment and build status of a preview. enum PreviewStatus { pending('⏳ Building'), + rebuilding('⏳ Rebuilding'), ready('✅ Ready'), failed('❌ Failed'); @@ -158,9 +159,8 @@ String buildPreviewCommentBody( : '`$shortSha`'; final previewLink = switch (entry.status) { - PreviewStatus.ready when entry.url != null => - '[Visit Preview ↗](${entry.url})', - PreviewStatus.pending => '_Deploying..._', + _ when entry.url != null => '[Visit Preview ↗](${entry.url})', + PreviewStatus.pending || PreviewStatus.rebuilding => '_Deploying..._', PreviewStatus.failed => '_Failed_', _ => '—', }; @@ -238,9 +238,16 @@ Future updatePreviewCommentOnGitHub({ previews.addAll(parsePreviewCommentEntries(body)); } + final existingEntry = previews[site]; + final resolvedStatus = + status == PreviewStatus.pending && existingEntry?.url != null + ? PreviewStatus.rebuilding + : status; + final resolvedUrl = stagingUrl ?? existingEntry?.url; + previews[site] = PreviewEntry( - status: status, - url: stagingUrl, + status: resolvedStatus, + url: resolvedUrl, commitSha: commitSha, ); diff --git a/tool/dash_site/test/preview_comments_test.dart b/tool/dash_site/test/preview_comments_test.dart index cb9da1c045..1ec5924691 100644 --- a/tool/dash_site/test/preview_comments_test.dart +++ b/tool/dash_site/test/preview_comments_test.dart @@ -30,6 +30,17 @@ void main() { expect(PreviewEntry.fromJson(json), equals(entry)); }); + test('serializes and deserializes rebuilding status with url', () { + const entry = PreviewEntry( + status: PreviewStatus.rebuilding, + url: 'https://flutter-docs-prod--pr100.web.app', + commitSha: '4977bb96d8ac0d94e8954c0682c80adce95b810e', + ); + + final json = entry.toJson(); + expect(PreviewEntry.fromJson(json), equals(entry)); + }); + test('serializes and deserializes failed status', () { const entry = PreviewEntry( status: PreviewStatus.failed, @@ -97,6 +108,26 @@ void main() { expect(body, contains('`4977bb9`')); }); + test('formats a rebuilding site table retaining the preview link', () { + final previews = { + Site.docs: const PreviewEntry( + status: PreviewStatus.rebuilding, + url: 'https://flutter-docs-prod--pr100.web.app', + commitSha: 'aabbcc112233', + ), + }; + + final body = buildPreviewCommentBody(previews); + + expect(body, contains('**docs.flutter.dev**')); + expect(body, contains('⏳ Rebuilding')); + expect( + body, + contains('[Visit Preview ↗](https://flutter-docs-prod--pr100.web.app)'), + ); + expect(body, contains('`aabbcc1`')); + }); + test('formats a failed site table cleanly', () { final previews = { Site.docs: const PreviewEntry( From aed5af699796a1627e6ac1cf6b1b5c17e981e21e Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 1 Dec 2026 18:26:20 -0600 Subject: [PATCH 4/4] Minor adjustments and cleanup --- tool/dash_site/lib/src/preview_comments.dart | 46 +++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/tool/dash_site/lib/src/preview_comments.dart b/tool/dash_site/lib/src/preview_comments.dart index eabebb1f76..f58c215d41 100644 --- a/tool/dash_site/lib/src/preview_comments.dart +++ b/tool/dash_site/lib/src/preview_comments.dart @@ -10,7 +10,7 @@ import 'package:github/github.dart' as github; import 'sites.dart'; /// Marker prefix used to identify staging preview comments. -const previewCommentMarker = ''; +const String previewCommentMarker = ''; /// The deployment and build status of a preview. enum PreviewStatus { @@ -38,12 +38,19 @@ final class PreviewEntry { /// The commit SHA for which this preview was built or deployed. final String commitSha; + /// Returns a JSON-encodable representation of this entry, + /// suitable for parsing with [fromJson]. Map toJson() => { 'status': status.name, - if (url != null) 'url': url, + 'url': ?url, 'commitSha': commitSha, }; + /// Parses a [PreviewEntry] from decoded [json] as produced by [toJson]. + /// + /// Also accepts the legacy format without a `status`, + /// treating it as [PreviewStatus.ready]. + /// Returns `null` if [json] isn't a valid entry. static PreviewEntry? fromJson(Object? json) { if (json case final Map map && @@ -126,8 +133,8 @@ Map parsePreviewCommentEntries(String commentBody) { /// Generates the Markdown body for the combined staging preview comment. /// -/// Formats a table dashboard with status emojis, preview links, and commit -/// links for all staged sites. +/// Formats a table dashboard with status emojis, preview links, and +/// commit links for all staged sites. String buildPreviewCommentBody( Map previews, { String? repoFullName, @@ -140,9 +147,9 @@ String buildPreviewCommentBody( key.name: value.toJson(), }; buffer.writeln(''); - buffer.writeln('### 🚀 Staged Previews'); + buffer.writeln('### 🚀 Staged previews'); buffer.writeln(); - buffer.writeln('| Site | Status | Preview Link | Commit |'); + buffer.writeln('| Site | Status | Preview link | Commit |'); buffer.writeln('| :--- | :--- | :--- | :--- |'); final sortedSites = previews.keys.toList() @@ -155,13 +162,14 @@ String buildPreviewCommentBody( : entry.commitSha; final commitDisplay = repoFullName != null - ? '[`$shortSha`](https://github.com/$repoFullName/commit/${entry.commitSha})' + ? '[`$shortSha`]' + '(https://github.com/$repoFullName/commit/${entry.commitSha})' : '`$shortSha`'; final previewLink = switch (entry.status) { - _ when entry.url != null => '[Visit Preview ↗](${entry.url})', - PreviewStatus.pending || PreviewStatus.rebuilding => '_Deploying..._', - PreviewStatus.failed => '_Failed_', + _ when entry.url != null => '[Visit preview ↗](${entry.url})', + .pending || .rebuilding => '_Deploying..._', + .failed => '_Failed_', _ => '—', }; @@ -175,7 +183,7 @@ String buildPreviewCommentBody( } /// Finds an existing preview comment on [issueNumber], if present. -Future findExistingPreviewComment({ +Future _findExistingPreviewComment({ required github.GitHub gitHub, required github.RepositorySlug repository, required int issueNumber, @@ -192,20 +200,6 @@ Future findExistingPreviewComment({ return null; } -/// Finds the ID of an existing preview comment on [issueNumber], if present. -Future findExistingPreviewCommentId({ - required github.GitHub gitHub, - required github.RepositorySlug repository, - required int issueNumber, -}) async { - final comment = await findExistingPreviewComment( - gitHub: gitHub, - repository: repository, - issueNumber: issueNumber, - ); - return comment?.id; -} - /// Updates or creates the staged preview comment on the pull request. /// /// Sets the [status] and optional [stagingUrl] for [site] on the PR, @@ -227,7 +221,7 @@ Future updatePreviewCommentOnGitHub({ try { final repository = github.RepositorySlug.full(repoFullName); - final existingComment = await findExistingPreviewComment( + final existingComment = await _findExistingPreviewComment( gitHub: gitHub, repository: repository, issueNumber: prNumber,