From 4b0fbb1e560fc574a440fa25b67804f688fb5137 Mon Sep 17 00:00:00 2001 From: Ricardo Amador <32242716+ricardoamador@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:05:57 -0700 Subject: [PATCH] Update the timestamp field to use the current data in the commit_service class (#3026) We are getting alert for 500 errors from the /api/github/webhook-branch-subscription endpoint when attempting to insert a commit for a release branch. The issue is with the timestamp presumably being null when we attempt to insert it into the database since it not a field in the return RepositoryCommit in the github lib. ``` "Failed to process Instance of 'PushMessage'. (500) Invalid argument(s): Error while encoding entity (Bad state: Property validation failed for property timestamp while trying to serialize entity of kind Commit. , #0 _ModelDescription._encodeProperty (package:gcloud/src/db/model_db_impl.dart:449:7) #1 _ModelDescription.encodeModel. (package:gcloud/src/db/model_db_impl.dart:429:7) #2 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13) #3 _ModelDescription.encodeModel (package:gcloud/src/db/model_db_impl.dart:428:34) #4 ModelDBImpl.toDatastoreEntity (package:gcloud/src/db/model_db_impl.dart:121:31) #5 _commitHelper (package:gcloud/src/db/db.dart:434:38) #6 Transaction.commit (package:gcloud/src/db/db.dart:118:14) #7 DatastoreService.insert.. (package:cocoon_service/src/service/datastore.dart:254:31) #8 DatastoreDB.withTransaction. (package:gcloud/src/db/db.dart:324:32) #9 _rootRunUnary (dart:async/zone.dart:1407:47) #10 DatastoreService.insert. (package:cocoon_service/src/service/datastore.dart:252:11) #11 RetryOptions.retry (package:retry/retry.dart:131:16) #12 DatastoreService.insert (package:cocoon_service/src/service/datastore.dart:250:7) #13 CommitService.handleCreateGithubRequest (package:cocoon_service/src/service/commit_service.dart:42:7) #14 GithubBranchWebhookSubscription.post (package:cocoon_service/src/request_handlers/github/branch_subscription.dart:56:7) #15 RequestHandler.service. (package:cocoon_service/src/request_handling/request_handler.dart:53:24) #16 SubscriptionHandler.service (package:cocoon_service/src/request_handling/subscription_handler.dart:138:5) #17 main.. (file:///app/bin/server.dart:303:11) ``` The data returned by the call in the Commit Service looks like this: ``` { "sha": "6fd42536b7697eb4bd2a698b19308e0aacac70c7", "node_id": "C_kwDOAeUeuNoAKDZmZDQyNTM2Yjc2OTdlYjRiZDJhNjk4YjE5MzA4ZTBhYWNhYzcwYzc", "commit": { "author": { "name": "Xilai Zhang", "email": "xilaizhang@google.com", "date": "2023-08-30T02:59:02Z" }, "committer": { "name": "GitHub", "email": "noreply@github.com", "date": "2023-08-30T02:59:02Z" }, "message": "[flutter roll] Revert \"Fix `Chip.shape`'s side is not used when provided in Material 3\" (#133615)\n\nReverts flutter/flutter#132941\r\ncontext: b/298110031\r\n\r\nThe rounded rectangle borders don't appear in some of the internal\r\ngolden image tests.", "tree": { "sha": "e5efe7f39155d9b8fc40ad0a59c72f6a36f8b66d", "url": "https://api.github.com/repos/flutter/flutter/git/trees/e5efe7f39155d9b8fc40ad0a59c72f6a36f8b66d" }, ``` The author field in this case has no createdAt timestamp. *List which issues are fixed by this PR. You must list at least one issue.* Fixes https://github.com/flutter/flutter/issues/133707 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* --- app_dart/lib/src/service/commit_service.dart | 2 +- app_dart/test/service/commit_service_test.dart | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app_dart/lib/src/service/commit_service.dart b/app_dart/lib/src/service/commit_service.dart index 2a624be2a..11b1c0869 100644 --- a/app_dart/lib/src/service/commit_service.dart +++ b/app_dart/lib/src/service/commit_service.dart @@ -53,7 +53,7 @@ class CommitService { final Key key = datastore.db.emptyKey.append(Commit, id: id); return Commit( key: key, - timestamp: commit.author?.createdAt?.millisecondsSinceEpoch, + timestamp: DateTime.now().millisecondsSinceEpoch, repository: slug.fullName, sha: commit.sha, author: commit.author?.login, diff --git a/app_dart/test/service/commit_service_test.dart b/app_dart/test/service/commit_service_test.dart index 2026b2b20..63bed6c29 100644 --- a/app_dart/test/service/commit_service_test.dart +++ b/app_dart/test/service/commit_service_test.dart @@ -61,7 +61,6 @@ void main() { RepositoryCommit( sha: sha, author: User( - createdAt: DateTime.parse(dateTimeAsString), login: username, avatarUrl: avatarUrl, ), @@ -78,7 +77,6 @@ void main() { expect(commit.repository, "$owner/$repository"); expect(commit.message, message); expect(commit.key.id, "$owner/$repository/$branch/$sha"); - expect(commit.timestamp, DateTime.parse(dateTimeAsString).millisecondsSinceEpoch); expect(commit.sha, sha); expect(commit.author, username); expect(commit.authorAvatarUrl, avatarUrl);