|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:flutter_current_results/model/comment.dart'; |
| 6 | +import 'package:flutter_current_results/model/review.dart'; |
| 7 | +import 'package:flutter_current_results/model/try_build.dart'; |
| 8 | +import 'package:flutter_current_results/query.dart'; |
| 9 | +import 'package:flutter_current_results/src/generated/query.pb.dart'; |
| 10 | +import 'package:flutter_current_results/src/services/firestore_service.dart'; |
| 11 | + |
| 12 | +class ResultsService { |
| 13 | + final FirestoreService _firestoreService = FirestoreService(); |
| 14 | + |
| 15 | + Future<Review> fetchReviewInfo(int review) async { |
| 16 | + final patchsetDocs = await _firestoreService.fetchPatchsetInfo(review); |
| 17 | + final patchsets = patchsetDocs |
| 18 | + .map((d) => Patchset.fromFirestore(d)) |
| 19 | + .toList(); |
| 20 | + final reviewDoc = await _firestoreService.fetchReviewInfo(review); |
| 21 | + if (reviewDoc.exists) { |
| 22 | + return Review.fromFirestore(reviewDoc, patchsets); |
| 23 | + } |
| 24 | + return Review( |
| 25 | + id: review.toString(), |
| 26 | + subject: 'No results received yet for CL $review', |
| 27 | + patchsets: [], |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + Future<Map<String, TryBuild>> fetchBuilds(int review, int patchset) async { |
| 32 | + final buildDocs = await _firestoreService.fetchTryBuilds(review); |
| 33 | + final builds = buildDocs.map((d) => TryBuild.fromFirestore(d)); |
| 34 | + return {for (var build in builds) build.builder: build}; |
| 35 | + } |
| 36 | + |
| 37 | + Future<Iterable<(ChangeInResult, Result)>> fetchChanges( |
| 38 | + int review, |
| 39 | + int patchset, |
| 40 | + ) async { |
| 41 | + final changeDocs = await _firestoreService.fetchTryChanges( |
| 42 | + review, |
| 43 | + patchset, |
| 44 | + ); |
| 45 | + return changeDocs.expand((doc) { |
| 46 | + final data = doc.data() as Map<String, dynamic>; |
| 47 | + final result = data['result'] ?? ''; |
| 48 | + final change = ChangeInResult.create( |
| 49 | + result: result, |
| 50 | + expected: data['expected'] ?? '', |
| 51 | + isFlaky: result.toLowerCase().contains('flaky'), |
| 52 | + previousResult: data['previous_result'] ?? '', |
| 53 | + ); |
| 54 | + final configurations = List<String>.from(data['configurations'] ?? []); |
| 55 | + return configurations.map((configuration) { |
| 56 | + final result = Result() |
| 57 | + ..name = data['name'] ?? '' |
| 58 | + ..configuration = configuration |
| 59 | + ..result = data['result'] ?? '' |
| 60 | + ..expected = data['expected'] ?? '' |
| 61 | + ..flaky = change.flaky; |
| 62 | + return (change, result); |
| 63 | + }); |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + Future<List<Comment>> fetchComments(int review) async { |
| 68 | + final commentDocs = await _firestoreService.fetchCommentsForReview(review); |
| 69 | + return commentDocs.map((d) => Comment.fromFirestore(d)).toList(); |
| 70 | + } |
| 71 | + |
| 72 | + Future<Map<String, String>> fetchBuilders() async { |
| 73 | + final builderDocs = await _firestoreService.fetchBuilders(); |
| 74 | + return {for (var doc in builderDocs) doc.id: doc.get('builder') as String}; |
| 75 | + } |
| 76 | +} |
0 commit comments