Skip to content

Commit

Permalink
Enum + event constructors added for build events (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasyishak authored Oct 31, 2023
1 parent e828d45 commit 5daf7bc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkgs/unified_analytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.1.0

- Added the `Event.flutterBuildInfo` constructor

## 5.0.0

- Update to the latest version of `package:dart_flutter_team_lints`
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
const String kPackageVersion = '5.1.0';

/// The minimum length for a session.
const int kSessionDurationMinutes = 30;
Expand Down
5 changes: 5 additions & 0 deletions pkgs/unified_analytics/lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ enum DashEvent {
description: 'Results from a specific doctor validator',
toolOwner: DashTool.flutterTool,
),
flutterBuildInfo(
label: 'flutter_build_info',
description: 'Information for a flutter build invocation',
toolOwner: DashTool.flutterTool,
),
hotReloadTime(
label: 'hot_reload_time',
description: 'Hot reload duration',
Expand Down
30 changes: 30 additions & 0 deletions pkgs/unified_analytics/lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,36 @@ final class Event {
if (statusInfo != null) 'statusInfo': statusInfo,
};

/// Event that is emitted from the flutter tool when a build invocation
/// has been run by the user.
///
/// [label] - the identifier for that build event.
///
/// [buildType] - the identifier for which platform the build event was for,
/// examples include "ios", "gradle", and "web".
///
/// [command] - the command that was ran to kick off the build event.
///
/// [settings] - the settings used for the build event related to
/// configuration and other relevant build information.
///
/// [error] - short identifier used to explain the cause of the build error,
/// stacktraces should not be passed to this parameter.
Event.flutterBuildInfo({
required String label,
required String buildType,
String? command,
String? settings,
String? error,
}) : eventName = DashEvent.flutterBuildInfo,
eventData = {
'label': label,
'buildType': buildType,
if (command != null) 'command': command,
if (settings != null) 'settings': settings,
if (error != null) 'error': error,
};

Event.hotReloadTime({required int timeMs})
: eventName = DashEvent.hotReloadTime,
eventData = {'timeMs': timeMs};
Expand Down
2 changes: 1 addition & 1 deletion pkgs/unified_analytics/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
version: 5.1.0
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics

environment:
Expand Down
23 changes: 22 additions & 1 deletion pkgs/unified_analytics/test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,27 @@ void main() {
expect(constructedEvent.eventData.length, 1);
});

test('Event.flutterBuildInfo constructed', () {
Event generateEvent() => Event.flutterBuildInfo(
label: 'label',
buildType: 'buildType',
command: 'command',
settings: 'settings',
error: 'error',
);

final constructedEvent = generateEvent();

expect(generateEvent, returnsNormally);
expect(constructedEvent.eventName, DashEvent.flutterBuildInfo);
expect(constructedEvent.eventData['label'], 'label');
expect(constructedEvent.eventData['buildType'], 'buildType');
expect(constructedEvent.eventData['command'], 'command');
expect(constructedEvent.eventData['settings'], 'settings');
expect(constructedEvent.eventData['error'], 'error');
expect(constructedEvent.eventData.length, 5);
});

test('Confirm all constructors were checked', () {
var constructorCount = 0;
for (var declaration in reflectClass(Event).declarations.keys) {
Expand All @@ -319,7 +340,7 @@ void main() {

// Change this integer below if your PR either adds or removes
// an Event constructor
final eventsAccountedForInTests = 17;
final eventsAccountedForInTests = 18;
expect(eventsAccountedForInTests, constructorCount,
reason: 'If you added or removed an event constructor, '
'ensure you have updated '
Expand Down

0 comments on commit 5daf7bc

Please sign in to comment.