Conversation
Adds a new top-level `Dart` folder containing the `https-time-server` quickstart translated into Dart using the in-development `firebase_functions` Dart SDK. Includes git dependency overrides for the unpublished packages, proper logging, explicit error handling, and the requested formatting snippet comments. Also adds a new GitHub Actions workflow for validating Dart code on push/PR. Co-authored-by: jhuleatt <3759507+jhuleatt@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| dart-version: | ||
| - "3.7.0" | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Dart ${{ matrix.dart-version }} | ||
| uses: dart-lang/setup-dart@v1 | ||
| with: | ||
| sdk: ${{ matrix.dart-version }} | ||
|
|
||
| - name: HTTPS Time Server - Install dependencies | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart pub get | ||
|
|
||
| - name: HTTPS Time Server - Format | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart format --set-exit-if-changed . | ||
|
|
||
| - name: HTTPS Time Server - Analyze | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart analyze . |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium test
There was a problem hiding this comment.
Confirmed the workflow is using Node 24 compatible actions (checkout@v4 and setup-dart@v1.6.0) and uses Dart 3.11.4 in the matrix.
There was a problem hiding this comment.
Code Review
This pull request introduces a new Dart quickstart for a Firebase Cloud Functions HTTPS trigger that returns a formatted server date. The feedback focuses on improving the stability and robustness of the sample. Key suggestions include pinning git dependencies to specific versions instead of the main branch, correcting documentation paths and shell command syntax in the README, utilizing idiomatic const constructors in Dart, adding error handling for invalid date format strings to prevent server errors, and removing redundant dependency overrides in the configuration.
| firebase_functions: | ||
| git: | ||
| url: https://github.com/firebase/firebase-functions-dart | ||
| ref: main |
|
|
||
| ### 1. Clone this repo | ||
|
|
||
| Clone or download this repo and open the `quickstarts/time-server` directory. |
There was a problem hiding this comment.
The directory path in the instructions is incorrect. It should be Dart/quickstarts/https-time-server to match the actual structure of this repository.
| Clone or download this repo and open the `quickstarts/time-server` directory. | |
| Clone or download this repo and open the Dart/quickstarts/https-time-server directory. |
There was a problem hiding this comment.
Updated the clone path to point to the Dart directory.
| curl -H 'Content-Type: application/json' / | ||
| -d '{"format": "MMMM d yyyy, h:mm:ss a"}' / | ||
| <function url>/date |
There was a problem hiding this comment.
The character used for line continuation in the cURL example is /, but in bash and other common shells, the backslash \ is the correct character for multi-line commands.
| curl -H 'Content-Type: application/json' / | |
| -d '{"format": "MMMM d yyyy, h:mm:ss a"}' / | |
| <function url>/date | |
| curl -H 'Content-Type: application/json' \ | |
| -d '{"format": "MMMM d yyyy, h:mm:ss a"}' \ | |
| <function url>/date |
There was a problem hiding this comment.
@jules confirm this is correct and fix if needed
There was a problem hiding this comment.
Updated the URL format to the correct run.app format without the /date suffix as discussed.
| // ignore: non_const_argument_for_const_parameter | ||
| options: HttpsOptions(timeoutSeconds: TimeoutSeconds(1200)), |
There was a problem hiding this comment.
Instead of suppressing the lint with an ignore comment, you should use the const constructor for HttpsOptions. This is more idiomatic in Dart and allows for better compiler optimizations.
| // ignore: non_const_argument_for_const_parameter | |
| options: HttpsOptions(timeoutSeconds: TimeoutSeconds(1200)), | |
| options: const HttpsOptions(timeoutSeconds: TimeoutSeconds(1200)), |
| final formattedDate = DateFormat(format).format(DateTime.now()); | ||
| print('Sending formatted date: $formattedDate'); | ||
| return Response.ok(formattedDate); |
There was a problem hiding this comment.
DateFormat(format) will throw a FormatException if the format string provided by the user is invalid. It is safer to wrap this in a try-catch block to handle the error gracefully and return a 400 status code instead of a generic 500 error.
try {
final formattedDate = DateFormat(format).format(DateTime.now());
print('Sending formatted date: $formattedDate');
return Response.ok(formattedDate);
} catch (e) {
return Response(400, body: 'Invalid format string');
}| dependency_overrides: | ||
| firebase_functions: | ||
| git: | ||
| url: https://github.com/firebase/firebase-functions-dart | ||
| ref: main | ||
| dart_firebase_admin: | ||
| git: | ||
| url: https://github.com/firebase/firebase-admin-dart | ||
| path: packages/dart_firebase_admin | ||
| ref: main | ||
| google_cloud_firestore: | ||
| git: | ||
| url: https://github.com/firebase/firebase-admin-dart | ||
| path: packages/google_cloud_firestore | ||
| ref: main |
Updates actions to Node 24 compliant versions (v4 and v1.6.0) to prevent deprecation failures. Also updates the `pubspec.yaml` to include exactly the git dependency/override blocks requested so that `firebase_functions` can properly resolve transitive dependencies without tripping up on the public pub.dev packages that are older/incompatible. Co-authored-by: jhuleatt <3759507+jhuleatt@users.noreply.github.com>
.github/workflows/test_dart.yml
Outdated
| strategy: | ||
| matrix: | ||
| dart-version: | ||
| - "3.7.0" |
There was a problem hiding this comment.
use dart version 3.11.4
There was a problem hiding this comment.
Updated the CI matrix to use Dart 3.11.4.
Removes the unnecessary timeout option from the route definition and the incorrectly preserved `ignore` comment. Updates the `format` handling to fallback to a default date string format if none is provided in the query or body, rather than throwing a `400 Bad Request`, matching the behavior specified in the README and prior examples. Co-authored-by: jhuleatt <3759507+jhuleatt@users.noreply.github.com>
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| dart-version: | ||
| - "3.11.4" | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Dart ${{ matrix.dart-version }} | ||
| uses: dart-lang/setup-dart@v1.6.0 | ||
| with: | ||
| sdk: ${{ matrix.dart-version }} | ||
|
|
||
| - name: HTTPS Time Server - Install dependencies | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart pub get | ||
|
|
||
| - name: HTTPS Time Server - Format | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart format --set-exit-if-changed . | ||
|
|
||
| - name: HTTPS Time Server - Analyze | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart analyze . |
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium test
|
|
||
| ### 1. Clone this repo | ||
|
|
||
| Clone or download this repo and open the `quickstarts/time-server` directory. |
| curl -H 'Content-Type: application/json' / | ||
| -d '{"format": "MMMM d yyyy, h:mm:ss a"}' / | ||
| <function url>/date |
There was a problem hiding this comment.
@jules confirm this is correct and fix if needed
| @@ -0,0 +1,95 @@ | |||
| # Firebase SDK for Cloud Functions Quickstart - HTTPS trigger | |||
There was a problem hiding this comment.
add a link to this page from the root readme
There was a problem hiding this comment.
Added a link to the Dart sample in the root README.md.
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| dart-version: | ||
| - "3.7.0" | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Dart ${{ matrix.dart-version }} | ||
| uses: dart-lang/setup-dart@v1 | ||
| with: | ||
| sdk: ${{ matrix.dart-version }} | ||
|
|
||
| - name: HTTPS Time Server - Install dependencies | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart pub get | ||
|
|
||
| - name: HTTPS Time Server - Format | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart format --set-exit-if-changed . | ||
|
|
||
| - name: HTTPS Time Server - Analyze | ||
| working-directory: ./Dart/quickstarts/https-time-server | ||
| run: dart analyze . |
| final formattedDate = format != null | ||
| ? DateFormat(format).format(DateTime.now()) | ||
| : DateTime.now().toString(); |
There was a problem hiding this comment.
instead of this big ternary, set format to a sensible default before the dartHttpSendResponse snippet block
There was a problem hiding this comment.
Refactored the logic to supply a sensible default string ('MMMM d yyyy, h:mm:ss a') to the formatter before the dartHttpSendResponse block instead of using the ternary operator.
| /// https://us-central1-<project-id>.cloudfunctions.net/date?format=MMMM%20d%20yyyy%2C%20h%3Amm%3Ass%20a | ||
| /// Example request using request body with cURL: | ||
| /// curl -H 'Content-Type: application/json' / | ||
| /// -d '{"format": "MMMM d yyyy, h:mm:ss a"}' / | ||
| /// https://us-central1-<project-id>.cloudfunctions.net/date |
There was a problem hiding this comment.
Due to a temporary quirk of Dart functions, the URLs look different from other functions. It takes the form https://<function-name>-<random-hash>.<region>.run.app. Adjust this comment with the corrected URL.
There was a problem hiding this comment.
Updated the comment string representing the URL example to match the temporary run.app style.
| format = body['format'] as String?; | ||
| } | ||
| } catch (e) { | ||
| // Ignore JSON parsing errors |
There was a problem hiding this comment.
Return Response.badRequest('invalid JSON'); here instead of ignoring https://pub.dev/documentation/shelf/latest/shelf/Response/Response.badRequest.html
There was a problem hiding this comment.
Added the Response.badRequest(body: 'invalid JSON'); return statement when json parsing fails instead of ignoring the exception.
* Link from root README.md * Fix clone directory path in Dart sample README * Fix sample run.app url format in README * Fix sample run.app url format in sample documentation blocks * Return 400 Bad Request on invalid JSON * Apply a default format string of "MMMM d yyyy, h:mm:ss a" prior to the return block Co-authored-by: jhuleatt <3759507+jhuleatt@users.noreply.github.com>
Adds a Dart quickstart for the HTTPS trigger function, implementing the time-server functionality with
intlfor date formatting, and sets up a CI workflow for Dart.PR created automatically by Jules for task 695963262136015593 started by @jhuleatt