feat: cibool run remove

Also fix Db::remove_run, which has never actually worked, because the
run id column was named wrongly. Oops.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2025-03-04 17:43:05 +02:00
parent e167d05e04
commit fe9ffca3d2
4 changed files with 65 additions and 1 deletions
+28
View File
@@ -1883,6 +1883,34 @@ when I run cibtool --db x.db run list --adapter-run-id abracadabra
then stdout is empty
~~~
## Remove information about a run from the database
_Want:_ `cibtool` can removed information about a CI run.
_Why:_ This is primarily for completeness.
_Who:_ `cib-devs`
~~~scenario
given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
given a Git repository xyzzy in the Radicle node
given the Radicle node emits a refsUpdated event for xyzzy
when I run ./env.sh synthetic-events synt.sock event.json --log log.txt
when I run cibtool --db x.db run list
then stdout is empty
when I run ./env.sh cibtool --db x.db run add --id runny --repo xyzzy --branch main --commit main --triggered
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 list
then stdout is empty
~~~
## Update and show information about run to running
_Want:_ `cibtool` can update information about a CI run.
+4
View File
@@ -224,6 +224,7 @@ impl Subcommand for RunCmd {
RunSubCmd::Add(x) => x.run(args)?,
RunSubCmd::List(x) => x.run(args)?,
RunSubCmd::Update(x) => x.run(args)?,
RunSubCmd::Remove(x) => x.run(args)?,
RunSubCmd::Show(x) => x.run(args)?,
}
Ok(())
@@ -239,6 +240,9 @@ enum RunSubCmd {
/// Update information about a CI run to the database.
Update(cibtoolcmd::UpdateRun),
/// Remove information about a CI run to the database.
Remove(cibtoolcmd::RemoveRun),
/// Show a CI run as JSON.
Show(cibtoolcmd::ShowRun),
+32
View File
@@ -1,3 +1,5 @@
use std::collections::HashSet;
use radicle_ci_broker::run::RunBuilder;
use super::*;
@@ -172,6 +174,36 @@ impl Leaf for ShowRun {
}
}
#[derive(Parser)]
pub struct RemoveRun {
/// Broker or adapter run IDs of runs to remove.
ids: Vec<RunId>,
}
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())?;
}
Ok(())
}
}
#[derive(Parser)]
pub struct ListRuns {
#[clap(long)]
+1 -1
View File
@@ -450,7 +450,7 @@ impl Db {
/// Remove a CI run from database, given its id. It's OK if the run is
/// not in the database, that is just silently ignored.
pub fn remove_run(&self, id: &RunId) -> Result<(), DbError> {
let mut remove = self.prepare("DELETE FROM ci_runs WHERE id = :id")?;
let mut remove = self.prepare("DELETE FROM ci_runs WHERE broker_run_id = :id")?;
remove
.stmt
.bind((":id", id.to_string().as_str()))