| Index: tools/gardening_tools/luci_api/lib/src/luci_services.dart
|
| diff --git a/tools/gardening_tools/luci_api/lib/src/luci_services.dart b/tools/gardening_tools/luci_api/lib/src/luci_services.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bc7ece11f1e2da71dfc1c942d183d6beb5c78468
|
| --- /dev/null
|
| +++ b/tools/gardening_tools/luci_api/lib/src/luci_services.dart
|
| @@ -0,0 +1,72 @@
|
| +import 'dart:async';
|
| +import 'dart:math';
|
| +import 'package:base_lib/base_lib.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,
|
| + PerformWithCache cache,
|
| + int amount) async {
|
| + logger.debug("Finding latest build for bot $botName...");
|
| + var result = await api.getBuildBotDetails(
|
| + client, botName, cache(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.
|
| +Future<Try<List<BuildDetail>>> fetchBuildsForCommmit(LuciApi api, Logger logger,
|
| + String client, String commit, PerformWithCache cache,
|
| + [int amount = 20]) async {
|
| + logger.info(
|
| + """Sorry - this is going to take some time, since we have to look into all $amount latest builds for all bots for client $client.
|
| +Subsequent queries run faster if caching is turned on...""");
|
| +
|
| + logger.debug("Finding all bots for client $client");
|
| + var buildBots = await api.getPrimaryBuilders(
|
| + client, cache(duration: new Duration(minutes: 30)));
|
| + return (await buildBots.bindAsync((List<LuciBuildBot> buildBots) async {
|
| + var buildBotBuilds = <Try<List<BuildDetail>>>[];
|
| + for (var buildBot in buildBots) {
|
| + buildBotBuilds.add(await fetchAndCacheLatestBuilds(
|
| + api, logger, client, buildBot.name, cache, amount));
|
| + }
|
| + logger.debug(
|
| + "All latest $amount builds found for client $client. Processing results...");
|
| + return buildBotBuilds
|
| + .map((tryBotBuild) {
|
| + if (tryBotBuild.isError()) {
|
| + logger.warning("Problem getting results", tryBotBuild.getError(),
|
| + tryBotBuild.getStackTrace());
|
| + }
|
| + return tryBotBuild.getOrDefault(new List<BuildDetail>());
|
| + })
|
| + .expand((id) => id)
|
| + .toList();
|
| + })).bind((List<BuildDetail> buildDetails) {
|
| + return buildDetails.where((BuildDetail buildDetail) {
|
| + return buildDetail.allChanges.any((change) => change.revision == commit);
|
| + });
|
| + });
|
| +}
|
|
|