Skip to content

Commit 3f38b15

Browse files
committed
github: dbtool should list check runs in a check suite
1 parent 27b4835 commit 3f38b15

File tree

1 file changed

+96
-6
lines changed

1 file changed

+96
-6
lines changed

github/dbtool/src/main.rs

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*/
44

55
use anyhow::{anyhow, bail, Context, Result};
6-
use buildomat_github_database::types::{CheckRunVariety, CheckSuiteId};
6+
use buildomat_github_database::types::{
7+
CheckRunId, CheckRunVariety, CheckSuiteId,
8+
};
79
use buildomat_github_database::Database;
810
use buildomat_github_hooktypes as hooktypes;
911
use chrono::prelude::*;
@@ -18,6 +20,39 @@ use std::time::{Duration, Instant};
1820

1921
const SHORT_SHA_LEN: usize = 16;
2022

23+
trait FlagsExt {
24+
fn add_flags(&mut self, name: &'static str) -> Flags;
25+
}
26+
27+
impl FlagsExt for Row {
28+
#[must_use]
29+
fn add_flags(&mut self, name: &'static str) -> Flags {
30+
Flags { row: self, name, out: String::new() }
31+
}
32+
}
33+
34+
struct Flags<'a> {
35+
row: &'a mut Row,
36+
name: &'static str,
37+
out: String,
38+
}
39+
40+
impl<'a> Flags<'a> {
41+
#[must_use]
42+
fn flag(mut self, c: char, b: bool) -> Self {
43+
if b {
44+
self.out.push(c);
45+
} else {
46+
self.out.push('-');
47+
}
48+
self
49+
}
50+
51+
fn build(self) {
52+
self.row.add_str(self.name, &self.out);
53+
}
54+
}
55+
2156
#[derive(Default)]
2257
struct Stuff {
2358
db: Option<Database>,
@@ -322,10 +357,6 @@ async fn do_repository(mut l: Level<Stuff>) -> Result<()> {
322357
sel!(l).run().await
323358
}
324359

325-
async fn do_check_run_list(_l: Level<Stuff>) -> Result<()> {
326-
bail!("not yet implemented");
327-
}
328-
329360
async fn do_check_suite_list(mut l: Level<Stuff>) -> Result<()> {
330361
l.add_column("id", 26, true);
331362
l.add_column("ghid", 10, true);
@@ -355,6 +386,44 @@ async fn do_check_suite_list(mut l: Level<Stuff>) -> Result<()> {
355386
Ok(())
356387
}
357388

389+
async fn do_check_suite_runs(mut l: Level<Stuff>) -> Result<()> {
390+
l.add_column("id", 26, true);
391+
l.add_column("flags", 5, true);
392+
l.add_column("variety", 10, true);
393+
l.add_column("name", 30, true);
394+
l.add_column("active", 6, false);
395+
l.add_column("flushed", 7, false);
396+
397+
l.usage_args(Some("CHECKSUITE"));
398+
399+
let a = args!(l);
400+
if a.args().len() != 1 {
401+
bad_args!(l, "specify a buildomat check suite ULID");
402+
}
403+
404+
let csid = CheckSuiteId::from_str(&a.args()[0])?;
405+
406+
let mut t = a.table();
407+
408+
for run in l.context().db().list_check_runs_for_suite(csid)? {
409+
let mut r = Row::default();
410+
r.add_str("id", &run.id.to_string());
411+
r.add_flags("flags")
412+
.flag('A', run.active)
413+
.flag('F', run.flushed)
414+
.build();
415+
r.add_str("active", if run.active { "yes" } else { "no" });
416+
r.add_str("flushed", if run.flushed { "yes" } else { "no" });
417+
r.add_str("variety", &run.variety.to_string());
418+
r.add_str("name", &run.name);
419+
420+
t.add_row(r);
421+
}
422+
423+
print!("{}", t.output()?);
424+
Ok(())
425+
}
426+
358427
async fn do_check_suite_dump(mut l: Level<Stuff>) -> Result<()> {
359428
l.usage_args(Some("CHECKSUITE"));
360429

@@ -455,6 +524,22 @@ async fn do_check_run_find(mut l: Level<Stuff>) -> Result<()> {
455524
Ok(())
456525
}
457526

527+
async fn do_check_run_dump(mut l: Level<Stuff>) -> Result<()> {
528+
l.usage_args(Some("CHECKRUN"));
529+
530+
let a = args!(l);
531+
if a.args().len() != 1 {
532+
bad_args!(l, "specify a buildomat check run ULID");
533+
}
534+
535+
let csid = CheckRunId::from_str(&a.args()[0])?;
536+
537+
let cr = l.context().db().load_check_run(csid)?;
538+
539+
println!("check run: {cr:#?}");
540+
Ok(())
541+
}
542+
458543
async fn do_duplicates(mut l: Level<Stuff>) -> Result<()> {
459544
no_args!(l);
460545

@@ -566,6 +651,11 @@ async fn do_check_suite(mut l: Level<Stuff>) -> Result<()> {
566651
cmd!(do_check_suite_find),
567652
)?;
568653
l.cmd("dump", "dump a particular check suite", cmd!(do_check_suite_dump))?;
654+
l.cmd(
655+
"runs",
656+
"list check runs for a check suite",
657+
cmd!(do_check_suite_runs),
658+
)?;
569659
l.cmd(
570660
"duplicates",
571661
"look for commits that had more than one check suite",
@@ -576,8 +666,8 @@ async fn do_check_suite(mut l: Level<Stuff>) -> Result<()> {
576666
}
577667

578668
async fn do_check_run(mut l: Level<Stuff>) -> Result<()> {
579-
l.cmda("list", "ls", "list check runs", cmd!(do_check_run_list))?;
580669
l.cmd("find", "locate a particular check run", cmd!(do_check_run_find))?;
670+
l.cmd("dump", "dump a particular check run", cmd!(do_check_run_dump))?;
581671

582672
sel!(l).run().await
583673
}

0 commit comments

Comments
 (0)