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 =
18
+ patchsetDocs.map ((d) => Patchset .fromFirestore (d)).toList ();
19
+ final reviewDoc = await _firestoreService.fetchReviewInfo (review);
20
+ if (reviewDoc.exists) {
21
+ return Review .fromFirestore (reviewDoc, patchsets);
22
+ }
23
+ return Review (
24
+ id: review.toString (),
25
+ subject: 'No results received yet for CL $review ' ,
26
+ patchsets: [],
27
+ );
28
+ }
29
+
30
+ Future <Map <String , TryBuild >> fetchBuilds (int review, int patchset) async {
31
+ final buildDocs = await _firestoreService.fetchTryBuilds (review);
32
+ final builds = buildDocs.map ((d) => TryBuild .fromFirestore (d));
33
+ return {for (var build in builds) build.builder: build};
34
+ }
35
+
36
+ Future <Iterable <(ChangeInResult , Result )>> fetchChanges (
37
+ int review,
38
+ int patchset,
39
+ ) async {
40
+ final changeDocs = await _firestoreService.fetchTryChanges (
41
+ review,
42
+ patchset,
43
+ );
44
+ return changeDocs.expand ((doc) {
45
+ final data = doc.data () as Map <String , dynamic >;
46
+ final result = data['result' ] ?? '' ;
47
+ final change = ChangeInResult .create (
48
+ result: result,
49
+ expected: data['expected' ] ?? '' ,
50
+ isFlaky: result.toLowerCase ().contains ('flaky' ),
51
+ previousResult: data['previous_result' ] ?? '' ,
52
+ );
53
+ final configurations = List <String >.from (data['configurations' ] ?? []);
54
+ return configurations.map ((configuration) {
55
+ final result = Result ()
56
+ ..name = data['name' ] ?? ''
57
+ ..configuration = configuration
58
+ ..result = data['result' ] ?? ''
59
+ ..expected = data['expected' ] ?? ''
60
+ ..flaky = change.flaky;
61
+ return (change, result);
62
+ });
63
+ });
64
+ }
65
+
66
+ Future <List <Comment >> fetchComments (int review) async {
67
+ final commentDocs = await _firestoreService.fetchCommentsForReview (review);
68
+ return commentDocs.map ((d) => Comment .fromFirestore (d)).toList ();
69
+ }
70
+
71
+ Future <Map <String , String >> fetchBuilders () async {
72
+ final builderDocs = await _firestoreService.fetchBuilders ();
73
+ return {for (var doc in builderDocs) doc.id: doc.get ('builder' ) as String };
74
+ }
75
+ }
0 commit comments