fix: "cibtool run remove" removed only by broker run id by default

We need to parse the run info in the database as JSON to get at the
adapter run info. This fails if the run info can't be parsed. That can
happen if the database has run info from a development version. Change
`cibtool run remove` so that it takes only broker run ids by default
so that we can delete using those even if the run info is broken.
Allow removing by adapter run id with the `--adapter` option.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2025-04-07 15:35:47 +03:00
parent 900a457157
commit 765e6b606c
2 changed files with 28 additions and 16 deletions
+1 -1
View File
@@ -1998,7 +1998,7 @@ when I run cibtool --db x.db run list --json
then stdout contains "runny"
then stdout contains ""state": "triggered""
when I run cibtool --db x.db run remove runny
when I run cibtool --db x.db run remove --adapter runny
when I run cibtool --db x.db run list
then stdout is empty
+27 -15
View File
@@ -178,27 +178,39 @@ impl Leaf for ShowRun {
pub struct RemoveRun {
/// Broker or adapter run IDs of runs to remove.
ids: Vec<RunId>,
/// The run ids are from the adapter, not the CI broker.
#[clap(long)]
adapter: bool,
}
impl Leaf for RemoveRun {
fn run(&self, args: &Args) -> Result<(), CibToolError> {
let db = args.open_db()?;
let unwanted: HashSet<RunId> = HashSet::from_iter(self.ids.iter().cloned());
let remove: Vec<Run> = db
.get_all_runs()?
.iter()
.filter(|run| {
if let Some(id) = run.adapter_run_id() {
unwanted.contains(id)
} else {
unwanted.contains(run.broker_run_id())
}
})
.cloned()
.collect();
for run in remove.iter() {
db.remove_run(run.broker_run_id())?;
if self.adapter {
let unwanted: HashSet<RunId> = HashSet::from_iter(self.ids.iter().cloned());
let remove: Vec<Run> = db
.get_all_runs()?
.iter()
.filter(|run| {
if let Some(id) = run.adapter_run_id() {
unwanted.contains(id)
} else {
unwanted.contains(run.broker_run_id())
}
})
.cloned()
.collect();
for run in remove.iter() {
db.remove_run(run.broker_run_id())?;
}
} else {
for run_id in self.ids.iter() {
db.remove_run(run_id)?;
println!("removed run {run_id}");
}
}
Ok(())
}