@@ -168,6 +168,25 @@ final class CiStaging extends AppDocument<CiStaging> {
168168 /// The check_run to complete when this stage is closed.
169169 String get checkRunGuard => fields[kCheckRunGuardField]! .stringValue! ;
170170
171+ static const keysOfImport = [
172+ kRemainingField,
173+ kTotalField,
174+ kFailedField,
175+ kCheckRunGuardField,
176+ fieldRepoFullPath,
177+ fieldCommitSha,
178+ fieldStage,
179+ ];
180+
181+ /// The recorded check-runs, a map of "test_name": "check_run id".
182+ Map <String , TaskConclusion > get checkRuns {
183+ return {
184+ for (final MapEntry (: key, : value) in fields.entries)
185+ if (! keysOfImport.contains (key))
186+ key: TaskConclusion .fromName (value.stringValue),
187+ };
188+ }
189+
171190 /// Mark a [checkRun] for a given [stage] with [conclusion] .
172191 ///
173192 /// Returns a [StagingConclusion] record or throws. If the check_run was
@@ -190,17 +209,7 @@ final class CiStaging extends AppDocument<CiStaging> {
190209 // updated correctly. For that to happen correctly; we need to perform a
191210 // read of the document in the transaction as well. So start the transaction
192211 // first thing.
193- final docRes = await firestoreService.documentResource ();
194- final transactionResponse = await docRes.beginTransaction (
195- BeginTransactionRequest (
196- options: TransactionOptions (readWrite: ReadWrite ()),
197- ),
198- kDatabase,
199- );
200- final transaction = transactionResponse.transaction;
201- if (transaction == null ) {
202- throw '$logCrumb : transaction was null when updating $conclusion ' ;
203- }
212+ final transaction = await firestoreService.beginTransaction ();
204213
205214 var remaining = - 1 ;
206215 var failed = - 1 ;
@@ -215,7 +224,10 @@ final class CiStaging extends AppDocument<CiStaging> {
215224 try {
216225 // First: read the fields we want to change.
217226 final documentName = documentNameFor (slug: slug, stage: stage, sha: sha);
218- doc = await docRes.get (documentName, transaction: transaction);
227+ doc = await firestoreService.getDocument (
228+ documentName,
229+ transaction: transaction,
230+ );
219231
220232 final fields = doc.fields;
221233 if (fields == null ) {
@@ -254,10 +266,7 @@ final class CiStaging extends AppDocument<CiStaging> {
254266 log.info (
255267 '$logCrumb : $checkRun not present in doc for $transaction / $doc ' ,
256268 );
257- await docRes.rollback (
258- RollbackRequest (transaction: transaction),
259- kDatabase,
260- );
269+ await firestoreService.rollback (transaction);
261270 return StagingConclusion (
262271 result: StagingConclusionResult .missing,
263272 remaining: remaining,
@@ -326,10 +335,7 @@ final class CiStaging extends AppDocument<CiStaging> {
326335 if (e.status == 404 ) {
327336 // An attempt to read a document not in firestore should not be retried.
328337 log.info ('$logCrumb : staging document not found for $transaction ' );
329- await docRes.rollback (
330- RollbackRequest (transaction: transaction),
331- kDatabase,
332- );
338+ await firestoreService.rollback (transaction);
333339 return StagingConclusion (
334340 result: StagingConclusionResult .internalError,
335341 remaining: - 1 ,
@@ -347,28 +353,21 @@ $stack
347353 );
348354 }
349355 // All other errors should bubble up and be retried.
350- await docRes.rollback (
351- RollbackRequest (transaction: transaction),
352- kDatabase,
353- );
356+ await firestoreService.rollback (transaction);
354357 rethrow ;
355358 } catch (e) {
356359 // All other errors should bubble up and be retried.
357- await docRes.rollback (
358- RollbackRequest (transaction: transaction),
359- kDatabase,
360- );
360+ await firestoreService.rollback (transaction);
361361 rethrow ;
362362 }
363363
364364 // Commit this write firebase and if no one else was writing at the same time, return success.
365365 // If this commit fails, that means someone else modified firestore and the caller should try again.
366366 // We do not need to rollback the transaction; firebase documentation says a failed commit takes care of that.
367- final commitRequest = CommitRequest (
368- transaction: transaction ,
369- writes : documentsToWrites ([doc], exists: true ),
367+ final response = await firestoreService. commit (
368+ transaction,
369+ documentsToWrites ([doc], exists: true ),
370370 );
371- final response = await docRes.commit (commitRequest, kDatabase);
372371 log.info (
373372 '$logCrumb : results = ${response .writeResults ?.map ((e ) => e .toJson ())}' ,
374373 );
@@ -433,12 +432,9 @@ For CI stage $stage:
433432 // Calling createDocument multiple times for the same documentId will return a 409 - ALREADY_EXISTS error;
434433 // this is good because it means we don't have to do any transactions.
435434 // curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <TOKEN>" "https://firestore.googleapis.com/v1beta1/projects/flutter-dashboard/databases/cocoon/documents/ciStaging?documentId=foo_bar_baz" -d '{"fields": {"test": {"stringValue": "baz"}}}'
436- final databasesDocumentsResource =
437- await firestoreService.documentResource ();
438- final newDoc = await databasesDocumentsResource.createDocument (
435+ final newDoc = await firestoreService.createDocument (
439436 document,
440- kDocumentParent,
441- _collectionId,
437+ collectionId: _collectionId,
442438 documentId:
443439 documentIdFor (
444440 slug: slug,
0 commit comments