| 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 | 6 |
| 7 import 'package:gardening/src/luci_api.dart'; | 7 import 'package:gardening/src/luci.dart'; |
| 8 import 'package:gardening/src/luci_services.dart'; | 8 import 'package:gardening/src/luci_services.dart'; |
| 9 import 'package:gardening/src/logger.dart'; | 9 import 'package:gardening/src/logger.dart'; |
| 10 import 'package:gardening/src/cache_new.dart'; | 10 import 'package:gardening/src/cache_new.dart'; |
| 11 import 'package:args/args.dart'; | 11 import 'package:args/args.dart'; |
| 12 | 12 |
| 13 ArgParser setupArgs() { | 13 ArgParser setupArgs() { |
| 14 return new ArgParser() | 14 return new ArgParser() |
| 15 ..addOption("client", | 15 ..addOption("client", |
| 16 abbr: "c", defaultsTo: 'client.dart', help: "Set which client to use.") | 16 abbr: "c", defaultsTo: 'client.dart', help: "Set which client to use.") |
| 17 ..addFlag("verbose", | 17 ..addFlag("verbose", |
| 18 abbr: "v", negatable: false, help: "Print debugging information.") | 18 abbr: "v", negatable: false, help: "Print debugging information.") |
| 19 ..addFlag("no-cache", | 19 ..addFlag("no-cache", |
| 20 negatable: false, | 20 negatable: false, |
| 21 defaultsTo: false, | 21 defaultsTo: false, |
| 22 help: "Use this flag to bypass caching. This may be slower.") | 22 help: "Use this flag to bypass caching. This may be slower.") |
| 23 ..addFlag("help", | 23 ..addFlag("help", |
| 24 negatable: false, | 24 negatable: false, |
| 25 help: "Shows information on how to use the luci_api tool.") | 25 help: "Shows information on how to use the luci tool.") |
| 26 ..addFlag("build-bots", | 26 ..addFlag("build-bots", |
| 27 negatable: false, | 27 negatable: false, |
| 28 help: "Use this flag to see the primary build bots for --client.") | 28 help: "Use this flag to see the primary build bots for --client.") |
| 29 ..addFlag("build-bots-all", | 29 ..addFlag("build-bots-all", |
| 30 negatable: false, | 30 negatable: false, |
| 31 help: "Use this flag to see all build bots for --client.") | 31 help: "Use this flag to see all build bots for --client.") |
| 32 ..addFlag("master", |
| 33 negatable: false, |
| 34 help: "Use this flag to see information about master for --client.") |
| 35 ..addFlag("build-groups", |
| 36 negatable: false, |
| 37 help: "Use this flag to see all builder-groups not -dev, -stable " |
| 38 "or -integration for --client.") |
| 39 ..addFlag("builders-in-group", |
| 40 negatable: false, |
| 41 help: "Use this flag as `--build-bot-details <group>` to see all " |
| 42 "builders (incl. shards) for a build group <group>.") |
| 32 ..addFlag("build-bot-details", | 43 ..addFlag("build-bot-details", |
| 33 negatable: false, | 44 negatable: false, |
| 34 help: "Use this flag as `--build-bot-details <name>` where " | 45 help: "Use this flag as `--build-bot-details <name>` where " |
| 35 "<name> is the name of the build bot, to see details of " | 46 "<name> is the name of the build bot, to see details of " |
| 36 "a specific build bot.") | 47 "a specific build bot.") |
| 37 ..addFlag("build-details", | 48 ..addFlag("build-details", |
| 38 negatable: false, | 49 negatable: false, |
| 39 help: "use this option as `--build-details <name> <buildNo>` where " | 50 help: "use this option as `--build-details <name> <buildNo>` where " |
| 40 "<name> is the name of the bot and " | 51 "<name> is the name of the bot and " |
| 41 "<buildNo> is the number of the build.") | 52 "<buildNo> is the number of the build.") |
| 42 ..addFlag("commit-builds", | 53 ..addFlag("builds-with-commit", |
| 43 negatable: false, | 54 negatable: false, |
| 44 help: "Fetches all builds for a specific commit. Use this flag as " | 55 help: "Fetches all builds with a specific commit. Use this flag as " |
| 45 "`--commit-builds <commit-hash>` where the <commit-hash> is the " | 56 "`--builds-with-commit <commit-hash>` where the <commit-hash> is " |
| 46 "hash of the commit"); | 57 "the hash of the commit"); |
| 47 } | 58 } |
| 48 | 59 |
| 49 void printHelp(ArgParser parser) { | 60 void printHelp(ArgParser parser) { |
| 50 print("This tool calls different pages on Luci and aggregate the information " | 61 print("This tool calls different pages on Luci and aggregate the information " |
| 51 "found. Below is stated information about flags and options:"); | 62 "found. Below is stated information about flags and options:"); |
| 52 print(""); | 63 print(""); |
| 53 print(parser.usage); | 64 print(parser.usage); |
| 54 } | 65 } |
| 55 | 66 |
| 56 main(List<String> args) async { | 67 main(List<String> args) async { |
| 57 var parser = setupArgs(); | 68 var parser = setupArgs(); |
| 58 var results = parser.parse(args); | 69 var results = parser.parse(args); |
| 59 | 70 |
| 60 if (results["help"]) { | 71 if (results["help"]) { |
| 61 printHelp(parser); | 72 printHelp(parser); |
| 62 return; | 73 return; |
| 63 } | 74 } |
| 64 | 75 |
| 65 var luciApi = new LuciApi(); | 76 var luci = new Luci(); |
| 66 Logger logger = | 77 Logger logger = |
| 67 new StdOutLogger(results['verbose'] ? Level.debug : Level.info); | 78 new StdOutLogger(results['verbose'] ? Level.debug : Level.info); |
| 68 CreateCacheFunction createCache = results['no-cache'] | 79 CreateCacheFunction createCache = results['no-cache'] |
| 69 ? noCache() | 80 ? noCache() |
| 70 : initCache(Uri.base.resolve('temp/gardening-cache/'), logger); | 81 : initCache(Uri.base.resolve('temp/gardening-cache/'), logger); |
| 71 | 82 |
| 72 if (results["build-bots"]) { | 83 if (results["build-bots"]) { |
| 73 await performBuildBotsPrimary(luciApi, createCache, results); | 84 await performBuildBotsPrimary(luci, createCache, results); |
| 74 } else if (results["build-bots-all"]) { | 85 } else if (results["build-bots-all"]) { |
| 75 await performBuildBotsAll(luciApi, createCache, results); | 86 await performBuildBotsAll(luci, createCache, results); |
| 87 } else if (results["master"]) { |
| 88 await performMaster(luci, createCache, results); |
| 89 } else if (results["build-groups"]) { |
| 90 await performBuilderGroups(luci, createCache, results); |
| 91 } else if (results["builders-in-group"]) { |
| 92 await performBuildersInGroup(luci, createCache, results); |
| 76 } else if (results["build-bot-details"]) { | 93 } else if (results["build-bot-details"]) { |
| 77 await performBuildBotDetails(luciApi, createCache, results); | 94 await performBuildBotDetails(luci, createCache, results); |
| 78 } else if (results["build-details"]) { | 95 } else if (results["build-details"]) { |
| 79 await performBuildDetails(luciApi, createCache, results); | 96 await performBuildDetails(luci, createCache, results); |
| 80 } else if (results["commit-builds"]) { | 97 } else if (results["builds-with-commit"]) { |
| 81 await performFindBuildsForCommit(luciApi, createCache, logger, results); | 98 await performFindBuildsForCommit(luci, createCache, logger, results); |
| 82 } else { | 99 } else { |
| 83 printHelp(parser); | 100 printHelp(parser); |
| 84 } | 101 } |
| 85 | 102 |
| 86 luciApi.close(); | 103 luci.close(); |
| 87 } | 104 } |
| 88 | 105 |
| 89 Future performBuildBotsPrimary( | 106 Future performBuildBotsPrimary( |
| 90 LuciApi api, CreateCacheFunction createCache, ArgResults results) async { | 107 Luci luci, CreateCacheFunction createCache, ArgResults results) async { |
| 91 var res = await api.getPrimaryBuilders( | 108 var res = await getPrimaryBuilders( |
| 92 results['client'], createCache(duration: new Duration(hours: 1))); | 109 luci, results['client'], createCache(duration: new Duration(hours: 1))); |
| 93 res.fold((ex, stackTrace) { | 110 res.fold((ex, stackTrace) { |
| 94 print(ex); | 111 print(ex); |
| 95 print(stackTrace); | 112 print(stackTrace); |
| 96 }, (bots) => bots.forEach(print)); | 113 }, (bots) => bots.forEach(print)); |
| 97 } | 114 } |
| 98 | 115 |
| 99 Future performBuildBotsAll( | 116 Future performBuildBotsAll( |
| 100 LuciApi api, CreateCacheFunction cache, ArgResults results) async { | 117 Luci luci, CreateCacheFunction cache, ArgResults results) async { |
| 101 var res = await api.getAllBuildBots( | 118 var res = await getAllBuilders( |
| 102 results['client'], cache(duration: new Duration(hours: 1))); | 119 luci, results['client'], cache(duration: new Duration(hours: 1))); |
| 103 res.fold((ex, stackTrace) { | 120 res.fold((ex, stackTrace) { |
| 104 print(ex); | 121 print(ex); |
| 105 print(stackTrace); | 122 print(stackTrace); |
| 106 }, (bots) => bots.forEach(print)); | 123 }, (bots) => bots.forEach(print)); |
| 107 } | 124 } |
| 108 | 125 |
| 126 Future performMaster( |
| 127 Luci luci, CreateCacheFunction cache, ArgResults results) async { |
| 128 var res = await luci.getMaster( |
| 129 results['client'], cache(duration: new Duration(minutes: 15))); |
| 130 res.fold((ex, stackTrace) { |
| 131 print(ex); |
| 132 print(stackTrace); |
| 133 }, (res) => print(res)); |
| 134 } |
| 135 |
| 136 Future performBuilderGroups( |
| 137 Luci luci, CreateCacheFunction cache, ArgResults results) async { |
| 138 var res = await getBuilderGroups( |
| 139 luci, results['client'], cache(duration: new Duration(minutes: 15))); |
| 140 res.fold((ex, stackTrace) { |
| 141 print(ex); |
| 142 print(stackTrace); |
| 143 }, (res) => res.forEach(print)); |
| 144 } |
| 145 |
| 146 Future performBuildersInGroup( |
| 147 Luci luci, CreateCacheFunction cache, ArgResults results) async { |
| 148 if (results.rest.length == 0) { |
| 149 print("No argument given for <group>. To see help, use --help"); |
| 150 return; |
| 151 } |
| 152 |
| 153 var res = await getBuildersInBuilderGroup(luci, results['client'], |
| 154 cache(duration: new Duration(minutes: 15)), results.rest[0]); |
| 155 res.fold((ex, stackTrace) { |
| 156 print(ex); |
| 157 print(stackTrace); |
| 158 }, (res) => res.forEach(print)); |
| 159 } |
| 160 |
| 109 Future performBuildBotDetails( | 161 Future performBuildBotDetails( |
| 110 LuciApi api, CreateCacheFunction cache, ArgResults results) async { | 162 Luci luci, CreateCacheFunction cache, ArgResults results) async { |
| 111 if (results.rest.length == 0) { | 163 if (results.rest.length == 0) { |
| 112 print("No argument given for <name>. To see help, use --help"); | 164 print("No argument given for <name>. To see help, use --help"); |
| 113 return; | 165 return; |
| 114 } | 166 } |
| 115 var result = await api.getBuildBotDetails(results['client'], results.rest[0], | 167 var result = await luci.getBuildBotDetails(results['client'], results.rest[0], |
| 116 cache(duration: new Duration(minutes: 15))); | 168 cache(duration: new Duration(minutes: 15))); |
| 117 result.fold((ex, stackTrace) { | 169 result.fold((ex, stackTrace) { |
| 118 print(ex); | 170 print(ex); |
| 119 print(stackTrace); | 171 print(stackTrace); |
| 120 }, (detail) => print(detail)); | 172 }, (detail) => print(detail)); |
| 121 } | 173 } |
| 122 | 174 |
| 123 Future performBuildDetails( | 175 Future performBuildDetails( |
| 124 LuciApi api, CreateCacheFunction createCache, ArgResults results) async { | 176 Luci luci, CreateCacheFunction createCache, ArgResults results) async { |
| 125 if (results.rest.length < 2) { | 177 if (results.rest.length < 2) { |
| 126 print("Missing argument for <name> or <buildNo>. To see help, use --help"); | 178 print("Missing argument for <name> or <buildNo>. To see help, use --help"); |
| 127 return; | 179 return; |
| 128 } | 180 } |
| 129 int buildNumber = int.parse(results.rest[1], onError: (source) => 0); | 181 int buildNumber = int.parse(results.rest[1], onError: (source) => 0); |
| 130 if (buildNumber <= 0) { | 182 if (buildNumber <= 0) { |
| 131 print("The buildnumber ${results['build-details']} must be a integer " | 183 print("The buildnumber ${results['build-details']} must be a integer " |
| 132 "greater than zero"); | 184 "greater than zero"); |
| 133 return; | 185 return; |
| 134 } | 186 } |
| 135 | 187 |
| 136 var result = await api.getBuildBotBuildDetails( | 188 var result = await luci.getBuildBotBuildDetails( |
| 137 results['client'], | 189 results['client'], |
| 138 results.rest[0], | 190 results.rest[0], |
| 139 buildNumber, | 191 buildNumber, |
| 140 createCache(duration: new Duration(minutes: 15))); | 192 createCache(duration: new Duration(minutes: 15))); |
| 141 result.fold((ex, stackTrace) { | 193 result.fold((ex, stackTrace) { |
| 142 print(ex); | 194 print(ex); |
| 143 print(stackTrace); | 195 print(stackTrace); |
| 144 }, (detail) => print(detail)); | 196 }, (detail) => print(detail)); |
| 145 } | 197 } |
| 146 | 198 |
| 147 Future performFindBuildsForCommit(LuciApi api, CreateCacheFunction createCache, | 199 Future performFindBuildsForCommit(Luci luci, CreateCacheFunction createCache, |
| 148 Logger logger, ArgResults results) async { | 200 Logger logger, ArgResults results) async { |
| 149 if (results.rest.length == 0) { | 201 if (results.rest.length == 0) { |
| 150 print("Missing argument for <commit>. To see help, use --help"); | 202 print("Missing argument for <commit>. To see help, use --help"); |
| 151 return; | 203 return; |
| 152 } | 204 } |
| 153 | 205 |
| 154 int amount = 25; | 206 int amount = 25; |
| 155 logger.info( | 207 logger.info( |
| 156 "Sorry - this is going to take some time, since we have to look into all " | 208 "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" | 209 "$amount latest builds for all bots for client ${results['client']}.\n" |
| 158 "Subsequent queries run faster if caching is not turned off..."); | 210 "Subsequent queries run faster if caching is not turned off..."); |
| 159 | 211 |
| 160 var result = await fetchBuildsForCommmit( | 212 var result = await fetchBuildsForCommmit( |
| 161 api, logger, results['client'], results.rest[0], createCache, amount); | 213 luci, logger, results['client'], results.rest[0], createCache, amount); |
| 162 result.fold((ex, st) { | 214 result.fold((ex, st) { |
| 163 print(ex); | 215 print(ex); |
| 164 print(st); | 216 print(st); |
| 165 }, (List<BuildDetail> details) { | 217 }, (List<BuildDetail> details) { |
| 166 print("The commit '${results.rest[0]} is used in the following builds:"); | 218 print("The commit '${results.rest[0]} is used in the following builds:"); |
| 167 details.forEach((detail) { | 219 details.forEach((detail) { |
| 168 String url = "https://luci-milo.appspot.com/buildbot/" | 220 String url = "https://luci-milo.appspot.com/buildbot/" |
| 169 "${detail.client}/${detail.botName}/${detail.buildNumber}"; | 221 "${detail.client}/${detail.botName}/${detail.buildNumber}"; |
| 170 print("${detail.botName}: #${detail.buildNumber}\t$url"); | 222 print("${detail.botName}: #${detail.buildNumber}\t$url"); |
| 171 }); | 223 }); |
| 172 }); | 224 }); |
| 173 } | 225 } |
| OLD | NEW |