From da6bb184c9eb18e344cf37ab1a34aa04b1057edc Mon Sep 17 00:00:00 2001 From: Elias Yishak <42216813+eliasyishak@users.noreply.github.com> Date: Tue, 24 Oct 2023 12:05:53 -0400 Subject: [PATCH] Enum + event constructors added for doctor events (#178) * Enum + event constructors added for doctor events * Use flexible field for doctor results * Clean up dartdoc * Consolidate doctor events into one event instead of 2 * `timestamp` --> `doctorInvocationId` * Test for `Event.doctorValidatorResult` constructor * Additional checks on `eventData` fields * Bump version to prep for publish * Bump version * Prepare for publishing --- pkgs/unified_analytics/CHANGELOG.md | 5 ++-- pkgs/unified_analytics/lib/src/constants.dart | 2 +- pkgs/unified_analytics/lib/src/enums.dart | 9 +++++- pkgs/unified_analytics/lib/src/event.dart | 30 +++++++++++++++++++ pkgs/unified_analytics/pubspec.yaml | 2 +- pkgs/unified_analytics/test/event_test.dart | 30 +++++++++++++++++++ 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 pkgs/unified_analytics/test/event_test.dart diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index b5db90373..79dce58f8 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,7 +1,8 @@ -## 5.0.0-wip +## 5.0.0 - Update to the latest version of `package:dart_flutter_team_lints` - Using internal futures list to store send events +- Added the `Event.doctorValidatorResult` constructor ## 4.0.1 @@ -59,4 +60,4 @@ ## 0.1.0 -- Initial version. +- Initial version diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index a1baccd60..db7e22451 100644 --- a/pkgs/unified_analytics/lib/src/constants.dart +++ b/pkgs/unified_analytics/lib/src/constants.dart @@ -82,7 +82,7 @@ const int kLogFileLength = 2500; const String kLogFileName = 'dart-flutter-telemetry.log'; /// The current version of the package, should be in line with pubspec version. -const String kPackageVersion = '5.0.0-wip'; +const String kPackageVersion = '5.0.0'; /// The minimum length for a session. const int kSessionDurationMinutes = 30; diff --git a/pkgs/unified_analytics/lib/src/enums.dart b/pkgs/unified_analytics/lib/src/enums.dart index 2e401a4cd..cf41e23f4 100644 --- a/pkgs/unified_analytics/lib/src/enums.dart +++ b/pkgs/unified_analytics/lib/src/enums.dart @@ -32,6 +32,7 @@ enum DashEvent { ), // Events for the Dart CLI + dartCliCommandExecuted( label: 'dart_cli_command_executed', description: 'Information about the execution of a Dart CLI command', @@ -43,7 +44,13 @@ enum DashEvent { toolOwner: DashTool.dartTool, ), - // Events for flutter_tools + // Events for the Flutter CLI + + doctorValidatorResult( + label: 'doctor_validator_result', + description: 'Results from a specific doctor validator', + toolOwner: DashTool.flutterTool, + ), hotReloadTime( label: 'hot_reload_time', description: 'Hot reload duration', diff --git a/pkgs/unified_analytics/lib/src/event.dart b/pkgs/unified_analytics/lib/src/event.dart index f1b18df5d..b582a3b0c 100644 --- a/pkgs/unified_analytics/lib/src/event.dart +++ b/pkgs/unified_analytics/lib/src/event.dart @@ -206,6 +206,36 @@ final class Event { if (exitCode != null) 'exitCode': exitCode, }; + /// Event that contains the results for a specific doctor validator. + /// + /// [validatorName] - the name for the doctor validator. + /// + /// [result] - the final result for a specific doctor validator. + /// + /// [partOfGroupedValidator] - `true` indicates that this validator belongs + /// to a grouped validator. + /// + /// [doctorInvocationId] - epoch formatted timestamp that can be used in + /// combination with the client ID in GA4 to group the validators that + /// ran in one doctor invocation. + /// + /// [statusInfo] - optional description of the result from the + /// doctor validator. + Event.doctorValidatorResult({ + required String validatorName, + required String result, + required bool partOfGroupedValidator, + required int doctorInvocationId, + String? statusInfo, + }) : eventName = DashEvent.doctorValidatorResult, + eventData = { + 'validatorName': validatorName, + 'result': result, + 'partOfGroupedValidator': partOfGroupedValidator, + 'doctorInvocationId': doctorInvocationId, + if (statusInfo != null) 'statusInfo': statusInfo, + }; + Event.hotReloadTime({required int timeMs}) : eventName = DashEvent.hotReloadTime, eventData = {'timeMs': timeMs}; diff --git a/pkgs/unified_analytics/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index 9df3cb580..95665377a 100644 --- a/pkgs/unified_analytics/pubspec.yaml +++ b/pkgs/unified_analytics/pubspec.yaml @@ -4,7 +4,7 @@ description: >- to Google Analytics. # When updating this, keep the version consistent with the changelog and the # value in lib/src/constants.dart. -version: 5.0.0-wip +version: 5.0.0 repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics environment: diff --git a/pkgs/unified_analytics/test/event_test.dart b/pkgs/unified_analytics/test/event_test.dart new file mode 100644 index 000000000..78c4ffda2 --- /dev/null +++ b/pkgs/unified_analytics/test/event_test.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. 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:test/test.dart'; + +import 'package:unified_analytics/src/enums.dart'; +import 'package:unified_analytics/unified_analytics.dart'; + +void main() { + test('Event.doctorValidatorResult constructed', () { + Event genDoctorValidatorResult() => Event.doctorValidatorResult( + validatorName: 'validatorName', + result: 'success', + partOfGroupedValidator: false, + doctorInvocationId: 123, + statusInfo: 'statusInfo', + ); + + final constructedEvent = genDoctorValidatorResult(); + + expect(genDoctorValidatorResult, returnsNormally); + expect(constructedEvent.eventName, DashEvent.doctorValidatorResult); + expect(constructedEvent.eventData['validatorName'], 'validatorName'); + expect(constructedEvent.eventData['result'], 'success'); + expect(constructedEvent.eventData['partOfGroupedValidator'], false); + expect(constructedEvent.eventData['doctorInvocationId'], 123); + expect(constructedEvent.eventData['statusInfo'], 'statusInfo'); + }); +}