| // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| import 'package:collection/collection.dart'; |
| import 'package:googleapis/firestore/v1.dart'; |
| |
| import 'firestore.dart'; |
| import 'result.dart'; |
| |
| Future<RevertedChanges> getRevertedChanges( |
| String reverted, int revertIndex, FirestoreService firestore) async { |
| final revertedCommit = await firestore.getCommit(reverted); |
| if (revertedCommit == null) { |
| throw 'Cannot find commit for reverted commit hash $reverted'; |
| } |
| final index = revertedCommit.index; |
| final changes = await firestore.findRevertedChanges(index); |
| return RevertedChanges(index, revertIndex, changes, |
| groupBy(changes, (change) => getValue(change[fName]))); |
| } |
| |
| class RevertedChanges { |
| final int index; |
| final int revertIndex; |
| final List<Map<String, Value> /*!*/ > changes; |
| final Map<String /*!*/, List<Map<String, Value> /*!*/ >> changesForTest; |
| |
| RevertedChanges( |
| this.index, this.revertIndex, this.changes, this.changesForTest); |
| |
| bool approveRevert(Map<String, dynamic> revert) { |
| final reverted = changesForTest[revert[fName]]; |
| return isFailure(revert) && |
| reverted != null && |
| reverted.any( |
| (change) => revert[fResult] == getValue(change[fPreviousResult])); |
| } |
| } |