Future updateResult()

in builder/lib/src/firestore.dart [272:315]


  Future<bool> updateResult(
      String result, String? configuration, int startIndex, int endIndex,
      {required bool failure}) async {
    late bool approved;
    await retryCommit(() async {
      final document = await getDocument(result);
      final data = SafeDocument(document);
      // Allow missing 'approved' field during transition period.
      approved = data.getBool('approved') ?? false;
      // Add the new configuration and narrow the blamelist.
      final newStart = max(startIndex, data.getInt('blamelist_start_index')!);
      final newEnd = min(endIndex, data.getInt('blamelist_end_index')!);
      // TODO(karlklose): check for pinned, and remove the pin if the new range
      // doesn't include it?
      final updates = [
        'blamelist_start_index',
        'blamelist_end_index',
        if (failure) 'active'
      ];
      document.fields!['blamelist_start_index'] = taggedValue(newStart);
      document.fields!['blamelist_end_index'] = taggedValue(newEnd);
      if (failure) {
        document.fields!['active'] = taggedValue(true);
      }
      final addConfiguration = ArrayValue()
        ..values = [taggedValue(configuration)];
      final write = Write()
        ..currentDocument = (Precondition()..updateTime = document.updateTime)
        ..update = document
        ..updateMask = (DocumentMask()..fieldPaths = updates)
        ..updateTransforms = [
          FieldTransform()
            ..fieldPath = 'configurations'
            ..appendMissingElements = addConfiguration,
          if (failure)
            FieldTransform()
              ..fieldPath = 'active_configurations'
              ..appendMissingElements = addConfiguration
        ];
      documentsWritten++;
      return write;
    });
    return approved;
  }