Chromium Code Reviews| Index: tools/gardening/lib/src/luci_services.dart |
| diff --git a/tools/gardening/lib/src/luci_services.dart b/tools/gardening/lib/src/luci_services.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ec7216976823fbbbdf773af842e714f9d56fc4c |
| --- /dev/null |
| +++ b/tools/gardening/lib/src/luci_services.dart |
| @@ -0,0 +1,64 @@ |
| +import 'dart:async'; |
| +import 'dart:math'; |
| +import 'try.dart'; |
| +import 'logger.dart'; |
| +import 'cache_new.dart'; |
| +import 'luci_api.dart'; |
| + |
| +// /// Fetches the latest builds for a bot and caches the results. |
| +// Future<Try<List<BuildDetail>>> fetchAndCacheLatestBuilds( |
| +// LuciApi api, |
| +// Logger logger, |
| +// String client, |
| +// String botName, |
| +// CreateCacheFunction createCache, |
| +// int amount) async { |
| +// logger.debug("Finding latest build for bot $botName..."); |
| +// var result = await api.getBuildBotDetails( |
| +// client, botName, createCache(duration: new Duration(minutes: 15))); |
| +// return result |
| +// .bindAsync<List<BuildDetail>>((LuciBuildBotDetail botDetail) async { |
| +// int buildNo = botDetail.latestBuildNumber(); |
| +// int lo = max(0, buildNo - amount); |
| +// List<Future<Try<BuildDetail>>> builds = |
| +// new List<Future<Try<BuildDetail>>>(); |
| +// logger.debug("Finding builds #${lo}-#${buildNo} for bot $botName..."); |
| +// for (buildNo; buildNo > lo; buildNo--) { |
| +// builds.add(api.getBuildDetails( |
| +// client, botName, buildNo, cache(duration: new Duration(days: 1)))); |
| +// } |
| +// List<Try<BuildDetail>> buildsCompleted = await Future.wait(builds); |
| +// logger.debug("Finished finding builds for bot $botName"); |
| +// return buildsCompleted |
| +// .where((bd) => !bd.isError()) |
| +// .map((bd) => bd.get()) |
| +// .toList(); |
| +// }); |
| +// } |
| + |
| +/// Fetches all builds for a given [commit]-hash, by searching the latest [amount] builds. |
|
Johnni Winther
2017/08/28 07:14:04
Long line.
|
| +Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(LuciApi api, Logger logger, |
| + String client, String commit, CreateCacheFunction createCache, |
| + [int amount = 1]) async { |
| + logger.debug("Finding primary bots for client $client"); |
| + var buildBots = await api.getPrimaryBuilders( |
| + client, createCache(duration: new Duration(minutes: 30))); |
| + |
| + var cache = createCache(duration: new Duration(minutes: 30)); |
| + return (await buildBots.bindAsync((List<LuciBuildBot> buildBots) async { |
| + var buildBotBuilds = new List<List<BuildDetail>>(); |
| + for (var buildBot in buildBots) { |
| + (await api.getBuildBotDetails(client, buildBot.name, cache, amount)).fold( |
| + (ex, st) { |
| + logger.error("Problem getting results", ex, st); |
| + }, buildBotBuilds.add); |
| + } |
| + logger.debug( |
| + "All latest $amount builds found for client $client. Processing results..."); |
|
Johnni Winther
2017/08/28 07:14:04
Long line.
|
| + return buildBotBuilds.expand((id) => id).toList(); |
| + })).bind((List<BuildDetail> buildDetails) { |
| + return buildDetails.where((BuildDetail buildDetail) { |
| + return buildDetail.allChanges.any((change) => change.revision == commit); |
| + }); |
| + }); |
| +} |