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

Side by Side Diff: tools/gardening/bin/luci_api.dart

Issue 3005723002: Added ability to find builder-groups (Closed)
Patch Set: Landing with changes from johnniwinther Created 3 years, 3 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 unified diff | Download patch
« no previous file with comments | « tools/gardening/bin/luci.dart ('k') | tools/gardening/lib/src/luci.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:gardening/src/luci_api.dart';
8 import 'package:gardening/src/luci_services.dart';
9 import 'package:gardening/src/logger.dart';
10 import 'package:gardening/src/cache_new.dart';
11 import 'package:args/args.dart';
12
13 ArgParser setupArgs() {
14 return new ArgParser()
15 ..addOption("client",
16 abbr: "c", defaultsTo: 'client.dart', help: "Set which client to use.")
17 ..addFlag("verbose",
18 abbr: "v", negatable: false, help: "Print debugging information.")
19 ..addFlag("no-cache",
20 negatable: false,
21 defaultsTo: false,
22 help: "Use this flag to bypass caching. This may be slower.")
23 ..addFlag("help",
24 negatable: false,
25 help: "Shows information on how to use the luci_api tool.")
26 ..addFlag("build-bots",
27 negatable: false,
28 help: "Use this flag to see the primary build bots for --client.")
29 ..addFlag("build-bots-all",
30 negatable: false,
31 help: "Use this flag to see all build bots for --client.")
32 ..addFlag("build-bot-details",
33 negatable: false,
34 help: "Use this flag as `--build-bot-details <name>` where "
35 "<name> is the name of the build bot, to see details of "
36 "a specific build bot.")
37 ..addFlag("build-details",
38 negatable: false,
39 help: "use this option as `--build-details <name> <buildNo>` where "
40 "<name> is the name of the bot and "
41 "<buildNo> is the number of the build.")
42 ..addFlag("commit-builds",
43 negatable: false,
44 help: "Fetches all builds for a specific commit. Use this flag as "
45 "`--commit-builds <commit-hash>` where the <commit-hash> is the "
46 "hash of the commit");
47 }
48
49 void printHelp(ArgParser parser) {
50 print("This tool calls different pages on Luci and aggregate the information "
51 "found. Below is stated information about flags and options:");
52 print("");
53 print(parser.usage);
54 }
55
56 main(List<String> args) async {
57 var parser = setupArgs();
58 var results = parser.parse(args);
59
60 if (results["help"]) {
61 printHelp(parser);
62 return;
63 }
64
65 var luciApi = new LuciApi();
66 Logger logger =
67 new StdOutLogger(results['verbose'] ? Level.debug : Level.info);
68 CreateCacheFunction createCache = results['no-cache']
69 ? noCache()
70 : initCache(Uri.base.resolve('temp/gardening-cache/'), logger);
71
72 if (results["build-bots"]) {
73 await performBuildBotsPrimary(luciApi, createCache, results);
74 } else if (results["build-bots-all"]) {
75 await performBuildBotsAll(luciApi, createCache, results);
76 } else if (results["build-bot-details"]) {
77 await performBuildBotDetails(luciApi, createCache, results);
78 } else if (results["build-details"]) {
79 await performBuildDetails(luciApi, createCache, results);
80 } else if (results["commit-builds"]) {
81 await performFindBuildsForCommit(luciApi, createCache, logger, results);
82 } else {
83 printHelp(parser);
84 }
85
86 luciApi.close();
87 }
88
89 Future performBuildBotsPrimary(
90 LuciApi api, CreateCacheFunction createCache, ArgResults results) async {
91 var res = await api.getPrimaryBuilders(
92 results['client'], createCache(duration: new Duration(hours: 1)));
93 res.fold((ex, stackTrace) {
94 print(ex);
95 print(stackTrace);
96 }, (bots) => bots.forEach(print));
97 }
98
99 Future performBuildBotsAll(
100 LuciApi api, CreateCacheFunction cache, ArgResults results) async {
101 var res = await api.getAllBuildBots(
102 results['client'], cache(duration: new Duration(hours: 1)));
103 res.fold((ex, stackTrace) {
104 print(ex);
105 print(stackTrace);
106 }, (bots) => bots.forEach(print));
107 }
108
109 Future performBuildBotDetails(
110 LuciApi api, CreateCacheFunction cache, ArgResults results) async {
111 if (results.rest.length == 0) {
112 print("No argument given for <name>. To see help, use --help");
113 return;
114 }
115 var result = await api.getBuildBotDetails(results['client'], results.rest[0],
116 cache(duration: new Duration(minutes: 15)));
117 result.fold((ex, stackTrace) {
118 print(ex);
119 print(stackTrace);
120 }, (detail) => print(detail));
121 }
122
123 Future performBuildDetails(
124 LuciApi api, CreateCacheFunction createCache, ArgResults results) async {
125 if (results.rest.length < 2) {
126 print("Missing argument for <name> or <buildNo>. To see help, use --help");
127 return;
128 }
129 int buildNumber = int.parse(results.rest[1], onError: (source) => 0);
130 if (buildNumber <= 0) {
131 print("The buildnumber ${results['build-details']} must be a integer "
132 "greater than zero");
133 return;
134 }
135
136 var result = await api.getBuildBotBuildDetails(
137 results['client'],
138 results.rest[0],
139 buildNumber,
140 createCache(duration: new Duration(minutes: 15)));
141 result.fold((ex, stackTrace) {
142 print(ex);
143 print(stackTrace);
144 }, (detail) => print(detail));
145 }
146
147 Future performFindBuildsForCommit(LuciApi api, CreateCacheFunction createCache,
148 Logger logger, ArgResults results) async {
149 if (results.rest.length == 0) {
150 print("Missing argument for <commit>. To see help, use --help");
151 return;
152 }
153
154 int amount = 25;
155 logger.info(
156 "Sorry - this is going to take some time, since we have to look into all "
157 "$amount latest builds for all bots for client ${results['client']}.\n"
158 "Subsequent queries run faster if caching is not turned off...");
159
160 var result = await fetchBuildsForCommmit(
161 api, logger, results['client'], results.rest[0], createCache, amount);
162 result.fold((ex, st) {
163 print(ex);
164 print(st);
165 }, (List<BuildDetail> details) {
166 print("The commit '${results.rest[0]} is used in the following builds:");
167 details.forEach((detail) {
168 String url = "https://luci-milo.appspot.com/buildbot/"
169 "${detail.client}/${detail.botName}/${detail.buildNumber}";
170 print("${detail.botName}: #${detail.buildNumber}\t$url");
171 });
172 });
173 }
OLDNEW
« no previous file with comments | « tools/gardening/bin/luci.dart ('k') | tools/gardening/lib/src/luci.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698