|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
| 3 | +from datetime import datetime, timedelta |
| 4 | + |
3 | 5 | import click |
4 | 6 | from tabulate import tabulate |
5 | 7 |
|
@@ -233,3 +235,82 @@ def get_boot_stats(ctx, giturl, branch, commit, tree_name, verbose, arch=None): |
233 | 235 | boots_with_status_mismatch, |
234 | 236 | ] |
235 | 237 | return stats |
| 238 | + |
| 239 | + |
| 240 | +def get_builds_history_stats(ctx, giturl, branch, tree_name, arch, days, verbose): |
| 241 | + checkouts = get_checkouts(ctx, giturl, branch, days) |
| 242 | + final_stats = [] |
| 243 | + builds_history = get_builds_history(ctx, checkouts, arch) |
| 244 | + for b in builds_history: |
| 245 | + missing_build_ids = find_missing_items(b[1], b[2], verbose) |
| 246 | + total_maestro_builds = len(b[1]) |
| 247 | + total_dashboard_builds = len(b[2]) |
| 248 | + stats = [ |
| 249 | + f"{tree_name}/{branch}", |
| 250 | + b[0], |
| 251 | + total_maestro_builds, |
| 252 | + total_dashboard_builds, |
| 253 | + "✅" if total_maestro_builds == total_dashboard_builds else "❌", |
| 254 | + missing_build_ids, |
| 255 | + ] |
| 256 | + final_stats.append(stats) |
| 257 | + return final_stats |
| 258 | + |
| 259 | + |
| 260 | +def get_checkouts(ctx, giturl, branch, days): |
| 261 | + """Get checkouts upto last specified days for a particular git |
| 262 | + URL and branch""" |
| 263 | + now = datetime.now() |
| 264 | + start_timestamp = now - timedelta(days=days) |
| 265 | + filters = [ |
| 266 | + "kind=checkout", |
| 267 | + "data.kernel_revision.url=" + giturl, |
| 268 | + "data.kernel_revision.branch=" + branch, |
| 269 | + "state=done", |
| 270 | + "created__gte=" + start_timestamp.isoformat(), |
| 271 | + ] |
| 272 | + checkouts = ctx.invoke( |
| 273 | + results, |
| 274 | + count=True, |
| 275 | + nodes=True, |
| 276 | + filter=filters, |
| 277 | + paginate=False, |
| 278 | + ) |
| 279 | + return checkouts |
| 280 | + |
| 281 | + |
| 282 | +def get_builds_history(ctx, checkouts, arch): |
| 283 | + """Get builds from maestro and dashboard for provided checkouts""" |
| 284 | + builds_history = [] |
| 285 | + for c in checkouts: |
| 286 | + commit = c["data"]["kernel_revision"].get("commit") |
| 287 | + filters = [ |
| 288 | + "kind=kbuild", |
| 289 | + "data.error_code__ne=node_timeout", |
| 290 | + "parent=" + c["id"], |
| 291 | + "state__in=done,available", |
| 292 | + ] |
| 293 | + if arch: |
| 294 | + filters.append(f"data.arch={arch}") |
| 295 | + maestro_builds = ctx.invoke( |
| 296 | + results, |
| 297 | + count=True, |
| 298 | + nodes=True, |
| 299 | + filter=filters, |
| 300 | + paginate=False, |
| 301 | + ) |
| 302 | + |
| 303 | + try: |
| 304 | + dashboard_builds = ctx.invoke( |
| 305 | + builds, |
| 306 | + giturl=c["data"]["kernel_revision"].get("url"), |
| 307 | + branch=c["data"]["kernel_revision"].get("branch"), |
| 308 | + commit=commit, |
| 309 | + count=True, |
| 310 | + verbose=False, |
| 311 | + arch=arch, |
| 312 | + ) |
| 313 | + builds_history.append([commit, maestro_builds, dashboard_builds]) |
| 314 | + except click.Abort: |
| 315 | + kci_msg_red("Aborted while fetching dashboard builds") |
| 316 | + return builds_history |
0 commit comments