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_api.dart'; |
10 | 10 |
| 11 const UNINTERESTING_BUILDER_SUFFIXES = const [ |
| 12 "-dev", |
| 13 "-stable", |
| 14 "-integration" |
| 15 ]; |
| 16 |
11 /// Fetches all builds for a given [commit]-hash, by searching the latest | 17 /// Fetches all builds for a given [commit]-hash, by searching the latest |
12 /// [amount] builds. | 18 /// [amount] builds. |
13 Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(LuciApi api, Logger logger, | 19 Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(LuciApi api, Logger logger, |
14 String client, String commit, CreateCacheFunction createCache, | 20 String client, String commit, CreateCacheFunction createCache, |
15 [int amount = 1]) async { | 21 [int amount = 1]) async { |
16 logger.debug("Finding primary bots for client $client"); | 22 logger.debug("Finding primary bots for client $client"); |
17 var buildBots = await api.getPrimaryBuilders( | 23 var buildBots = await getPrimaryBuilders( |
18 client, createCache(duration: new Duration(minutes: 30))); | 24 api, client, createCache(duration: new Duration(minutes: 30))); |
19 | 25 |
20 var cache = createCache(duration: new Duration(minutes: 30)); | 26 var cache = createCache(duration: new Duration(minutes: 30)); |
21 return (await buildBots.bindAsync((List<LuciBuildBot> buildBots) async { | 27 return (await buildBots.bindAsync((List<String> buildBots) async { |
22 var buildBotBuilds = new List<List<BuildDetail>>(); | 28 var buildBotBuilds = new List<List<BuildDetail>>(); |
23 for (var buildBot in buildBots) { | 29 for (var buildBot in buildBots) { |
24 (await api.getBuildBotDetails(client, buildBot.name, cache, amount)).fold( | 30 (await api.getBuildBotDetails(client, buildBot, cache, amount)).fold( |
25 (ex, st) { | 31 (ex, st) { |
26 logger.error("Problem getting results", ex, st); | 32 logger.error("Problem getting results", ex, st); |
27 }, buildBotBuilds.add); | 33 }, buildBotBuilds.add); |
28 } | 34 } |
29 logger.debug("All latest $amount builds found for client $client. " | 35 logger.debug("All latest $amount builds found for client $client. " |
30 "Processing results..."); | 36 "Processing results..."); |
31 return buildBotBuilds.expand((id) => id).toList(); | 37 return buildBotBuilds.expand((id) => id).toList(); |
32 })).bind((List<BuildDetail> buildDetails) { | 38 })).bind((List<BuildDetail> buildDetails) { |
33 return buildDetails.where((BuildDetail buildDetail) { | 39 return buildDetails.where((BuildDetail buildDetail) { |
34 return buildDetail.allChanges.any((change) => change.revision == commit); | 40 return buildDetail.allChanges.any((change) => change.revision == commit); |
35 }); | 41 }); |
36 }); | 42 }); |
37 } | 43 } |
| 44 |
| 45 /// [getBuilderGroups] fetches all builder groups not in -dev, -stable and |
| 46 /// -integration from CBE. |
| 47 Future<Try<List<String>>> getBuilderGroups( |
| 48 LuciApi api, String client, WithCacheFunction withCache) async { |
| 49 var result = await api.getCBEJson(client, withCache); |
| 50 return result.bind((json) { |
| 51 var builders = json["builders"]; |
| 52 return builders.keys.fold<Map<String, Object>>({}, |
| 53 (Map<String, Object> map, builderKey) { |
| 54 if (UNINTERESTING_BUILDER_SUFFIXES.any((x) => builderKey.contains(x))) { |
| 55 return map; |
| 56 } |
| 57 map[sanitizeCategory(builders[builderKey]["category"])] = true; |
| 58 return map; |
| 59 }).keys; |
| 60 }); |
| 61 } |
| 62 |
| 63 /// [getAllBuilders] fetches all builders from CBE. |
| 64 Future<Try<List<String>>> getAllBuilders( |
| 65 LuciApi api, String client, WithCacheFunction withCache) async { |
| 66 var result = await api.getCBEJson(client, withCache); |
| 67 return result.bind((json) { |
| 68 return json["builders"].keys; |
| 69 }); |
| 70 } |
| 71 |
| 72 /// [getPrimaryBuilders] fetches all primary builders from CBE. |
| 73 Future<Try<List<String>>> getPrimaryBuilders( |
| 74 LuciApi api, String client, WithCacheFunction withCache) async { |
| 75 var result = await getAllBuilders(api, client, withCache); |
| 76 return result.bind((builders) { |
| 77 return builders |
| 78 .where((builderKey) => |
| 79 !UNINTERESTING_BUILDER_SUFFIXES.any((x) => builderKey.contains(x))) |
| 80 .toList(); |
| 81 }); |
| 82 } |
| 83 |
| 84 /// [getPrimaryBuilders] gets all builders in builder group [builderGroup]. |
| 85 Future<Try<List<String>>> getBuildersInBuilderGroup(LuciApi api, String client, |
| 86 WithCacheFunction withCache, String builderGroup) async { |
| 87 var result = await api.getCBEJson(client, withCache); |
| 88 return result.bind((json) { |
| 89 var builders = json["builders"]; |
| 90 return builders.keys.where((builder) { |
| 91 return sanitizeCategory(builders[builder]["category"]) == builderGroup; |
| 92 }); |
| 93 }); |
| 94 } |
| 95 |
| 96 /// Strips un-wanted characters from string [category]. |
| 97 String sanitizeCategory(String category) { |
| 98 // Category name starts with either two or three numbers and |
| 99 // end with |all. Instead of doing any fancy regular-expr, |
| 100 // we just test if third char is a number. |
| 101 return category.substring( |
| 102 category.codeUnitAt(2) <= 64 ? 3 : 2, category.length - 4); |
| 103 } |
OLD | NEW |