Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: tools/gardening/lib/src/luci_services.dart

Issue 3005443002: Additional tools for gardening. (Closed)
Patch Set: Moved files from gardening_tools to gardening and incorporated changes from johnniwinther Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698