Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
fix: "cibtool run remove" removed only by broker run id by default
Lars Wirzenius committed 1 year ago
commit 765e6b606ccc638372659a0f68c1f4cc43be8234
parent 900a457
2 files changed +29 -17
modified ci-broker.md
@@ -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
modified src/bin/cibtoolcmd/run.rs
@@ -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(())
    }