[app_dart] branch logic fix: make 100 percent sure request is passed in (#1888)
diff --git a/app_dart/lib/src/request_handlers/github_webhook.dart b/app_dart/lib/src/request_handlers/github_webhook.dart
index ead2f5a..beeaba6 100644
--- a/app_dart/lib/src/request_handlers/github_webhook.dart
+++ b/app_dart/lib/src/request_handlers/github_webhook.dart
@@ -85,7 +85,7 @@
}
break;
case 'create':
- branchService ??= BranchService(datastore, rawRequest: stringRequest);
+ branchService = BranchService(datastore, rawRequest: stringRequest);
await branchService!.handleCreateRequest();
break;
}
diff --git a/app_dart/lib/src/service/branch_service.dart b/app_dart/lib/src/service/branch_service.dart
index 9c6ae35..455847d 100644
--- a/app_dart/lib/src/service/branch_service.dart
+++ b/app_dart/lib/src/service/branch_service.dart
@@ -26,11 +26,13 @@
/// Parse a create github webhook event, and add it to datastore.
Future<void> handleCreateRequest() async {
+ log.info('raw request passed in was $rawRequest');
final CreateEvent? createEvent = await _getCreateRequestEvent(rawRequest!);
if (createEvent == null) {
log.info('create branch event was rejected because could not parse the json webhook request');
throw const BadRequestException('Expected create request event.');
}
+ log.info('the branch parsed from string request is ${createEvent.ref}');
final String? refType = createEvent.refType;
if (refType == 'tag') {
diff --git a/app_dart/test/request_handlers/github_webhook_test.dart b/app_dart/test/request_handlers/github_webhook_test.dart
index f3d0394..b965256 100644
--- a/app_dart/test/request_handlers/github_webhook_test.dart
+++ b/app_dart/test/request_handlers/github_webhook_test.dart
@@ -2332,7 +2332,8 @@
request.headers.set('X-Hub-Signature', 'sha1=$hmac');
await tester.post(webhook);
- verify(branchService.handleCreateRequest()).called(1);
+ expect(webhook.branchService, isNotNull);
+ expect(webhook.branchService!.rawRequest, request.body);
});
});