mirror of
https://seed.radicle.dev/rad:zwTxygwuz5LDGBq255RA2CbNGrz8.git
synced 2026-10-18 19:30:29 +08:00
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:
@@ -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.
|
||||
|
||||
@@ -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),
|
||||
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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()))
|
||||
|
||||
Reference in New Issue
Block a user