OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'try.dart'; | 6 import 'try.dart'; |
7 import 'logger.dart'; | 7 import 'logger.dart'; |
8 import 'cache_new.dart'; | 8 import 'cache_new.dart'; |
9 import 'luci_api.dart'; | 9 import 'luci.dart'; |
| 10 import 'util.dart'; |
| 11 |
| 12 const UNINTERESTING_BUILDER_SUFFIXES = const [ |
| 13 "-dev", |
| 14 "-stable", |
| 15 "-integration" |
| 16 ]; |
10 | 17 |
11 /// Fetches all builds for a given [commit]-hash, by searching the latest | 18 /// Fetches all builds for a given [commit]-hash, by searching the latest |
12 /// [amount] builds. | 19 /// [amount] builds. |
13 Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(LuciApi api, Logger logger, | 20 Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(Luci luci, Logger logger, |
14 String client, String commit, CreateCacheFunction createCache, | 21 String client, String commit, CreateCacheFunction createCache, |
15 [int amount = 1]) async { | 22 [int amount = 1]) async { |
16 logger.debug("Finding primary bots for client $client"); | 23 logger.debug("Finding primary bots for client $client"); |
17 var buildBots = await api.getPrimaryBuilders( | 24 var buildBots = await getPrimaryBuilders( |
18 client, createCache(duration: new Duration(minutes: 30))); | 25 luci, client, createCache(duration: new Duration(minutes: 30))); |
19 | 26 |
20 var cache = createCache(duration: new Duration(minutes: 30)); | 27 var cache = createCache(duration: new Duration(minutes: 30)); |
21 return (await buildBots.bindAsync((List<LuciBuildBot> buildBots) async { | 28 |
| 29 return (await buildBots.bindAsync((List<String> buildBots) async { |
22 var buildBotBuilds = new List<List<BuildDetail>>(); | 30 var buildBotBuilds = new List<List<BuildDetail>>(); |
23 for (var buildBot in buildBots) { | 31 for (var buildBot in buildBots) { |
24 (await api.getBuildBotDetails(client, buildBot.name, cache, amount)).fold( | 32 (await luci.getBuildBotDetails(client, buildBot, cache, amount)).fold( |
25 (ex, st) { | 33 (ex, st) { |
26 logger.error("Problem getting results", ex, st); | 34 logger.error("Problem getting results", ex, st); |
27 }, buildBotBuilds.add); | 35 }, buildBotBuilds.add); |
28 } | 36 } |
29 logger.debug("All latest $amount builds found for client $client. " | 37 logger.debug("All latest $amount builds found for client $client. " |
30 "Processing results..."); | 38 "Processing results..."); |
31 return buildBotBuilds.expand((id) => id).toList(); | 39 return buildBotBuilds.expand((id) => id).toList(); |
32 })).bind((List<BuildDetail> buildDetails) { | 40 })).bind((List<BuildDetail> buildDetails) { |
33 return buildDetails.where((BuildDetail buildDetail) { | 41 return buildDetails.where((BuildDetail buildDetail) { |
34 return buildDetail.allChanges.any((change) => change.revision == commit); | 42 return buildDetail.allChanges.any((change) => change.revision == commit); |
35 }); | 43 }); |
36 }); | 44 }); |
37 } | 45 } |
| 46 |
| 47 /// [getBuilderGroups] fetches all builder groups not in -dev, -stable and |
| 48 /// -integration from CBE. |
| 49 Future<Try<List<String>>> getBuilderGroups( |
| 50 Luci luci, String client, WithCacheFunction withCache) async { |
| 51 var result = await luci.getJsonFromChromeBuildExtract(client, withCache); |
| 52 return result.bind((json) { |
| 53 var builders = json["builders"]; |
| 54 return builders.keys.fold<Map<String, Object>>({}, |
| 55 (Map<String, Object> map, builderKey) { |
| 56 if (UNINTERESTING_BUILDER_SUFFIXES.any((x) => builderKey.contains(x))) { |
| 57 return map; |
| 58 } |
| 59 map[sanitizeCategory(builders[builderKey]["category"])] = true; |
| 60 return map; |
| 61 }).keys; |
| 62 }); |
| 63 } |
| 64 |
| 65 /// [getAllBuilders] fetches all builders from CBE. |
| 66 Future<Try<List<String>>> getAllBuilders( |
| 67 Luci luci, String client, WithCacheFunction withCache) async { |
| 68 var result = await luci.getJsonFromChromeBuildExtract(client, withCache); |
| 69 return result.bind((json) { |
| 70 return json["builders"].keys; |
| 71 }); |
| 72 } |
| 73 |
| 74 /// [getPrimaryBuilders] fetches all primary builders from CBE. |
| 75 Future<Try<List<String>>> getPrimaryBuilders( |
| 76 Luci luci, String client, WithCacheFunction withCache) async { |
| 77 var result = await getAllBuilders(luci, client, withCache); |
| 78 return result.bind((builders) { |
| 79 return builders |
| 80 .where((builderKey) => |
| 81 !UNINTERESTING_BUILDER_SUFFIXES.any((x) => builderKey.contains(x))) |
| 82 .toList(); |
| 83 }); |
| 84 } |
| 85 |
| 86 /// [getPrimaryBuilders] gets all builders in builder group [builderGroup]. |
| 87 Future<Try<List<String>>> getBuildersInBuilderGroup(Luci luci, String client, |
| 88 WithCacheFunction withCache, String builderGroup) async { |
| 89 var result = await luci.getJsonFromChromeBuildExtract(client, withCache); |
| 90 return result.bind((json) { |
| 91 var builders = json["builders"]; |
| 92 return builders.keys.where((builder) { |
| 93 return sanitizeCategory(builders[builder]["category"]) == builderGroup; |
| 94 }); |
| 95 }); |
| 96 } |
OLD | NEW |