Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat(cibtool): allow user to add information about a run
Lars Wirzenius committed 1 year ago
commit 6cd968d48078c86f866d8868d8f7fcea65c504d0
parent 5f1ce255c01c8ae2bcafc01953262fdd9abeb381
2 files changed +90 -0
modified ci-broker.md
@@ -791,6 +791,8 @@ events.
_Justification:_ This is needed for testing, and for the node operator
to be able to do this cleanly.

+
_Stakeholder:_ Lars.
+

~~~scenario
given an installed cibtool
when I run cibtool --db x.db event list
@@ -801,3 +803,21 @@ when I run cibtool --db x.db event shutdown --id-file id.txt
when I run cibtool --db x.db event show --id-file id.txt
then stdout contains "Shutdown"
~~~
+
## Add CI run information to database
+

+
_Requirement:_ `cibtool` can add information about a CI run, possibly
+
one that is imaginary.
+

+
_Justification:_ This is primarily needed for testing.
+

+
_Stakeholder:_ Lars.
+

+
~~~scenario
+
given an installed cibtool
+
when I run cibtool --db x.db run list
+
then stdout is exactly ""
+

+
when I run cibtool --db x.db run add --id x --repo rad:zwTxygwuz5LDGBq255RA2CbNGrz8 --alias x --url https://x/1 --branch main --commit f1815dde6ae406d8fe3cec0b96c4486766342716 --who x --finished --failure --timestamp 2024-07-09T02:00:00
+
when I run cibtool --db x.db run list
+
then stdout contains "rad:zwTxygwuz5LDGBq255RA2CbNGrz8"
+
~~~
modified src/bin/cibtool.rs
@@ -20,6 +20,8 @@ use radicle_ci_broker::{
    broker::BrokerError,
    db::{Db, DbError, QueueId},
    event::BrokerEvent,
+
    msg::RunId,
+
    run::{Run, Whence},
};

fn main() {
@@ -453,6 +455,7 @@ impl RunCmd {
    #[allow(clippy::result_large_err)]
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
        match &self.cmd {
+
            RunSubCmd::Add(x) => x.run(args)?,
            RunSubCmd::List(x) => x.run(args)?,
        }
        Ok(())
@@ -461,10 +464,77 @@ impl RunCmd {

#[derive(Parser)]
enum RunSubCmd {
+
    Add(AddRun),
    List(ListRuns),
}

#[derive(Parser)]
+
struct AddRun {
+
    #[clap(long)]
+
    id: RunId,
+

+
    #[clap(long)]
+
    alias: String,
+

+
    #[clap(long)]
+
    url: Option<String>,
+

+
    #[clap(long)]
+
    repo: RepoId,
+

+
    #[clap(long)]
+
    timestamp: String,
+

+
    #[clap(long)]
+
    branch: String,
+

+
    #[clap(long)]
+
    commit: Oid,
+

+
    #[clap(long)]
+
    who: Option<String>,
+

+
    #[clap(long, required_unless_present_any = ["running", "finished"])]
+
    triggered: bool,
+

+
    #[clap(long)]
+
    #[clap(long, required_unless_present_any = ["triggered", "finished"])]
+
    running: bool,
+

+
    #[clap(long)]
+
    #[clap(long, required_unless_present_any = ["triggered", "running"])]
+
    finished: bool,
+

+
    #[clap(long, required_unless_present = "failure")]
+
    success: bool,
+

+
    #[clap(long, required_unless_present = "success")]
+
    failure: bool,
+
}
+

+
impl AddRun {
+
    #[allow(clippy::result_large_err)]
+
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
+
        let db = args.open_db()?;
+

+
        let whence = Whence::Branch {
+
            name: self.branch.clone(),
+
            commit: self.commit,
+
            who: self.who.clone(),
+
        };
+
        let mut run = Run::new(self.repo, &self.alias, whence, self.timestamp.clone());
+
        run.set_adapter_run_id(RunId::default());
+
        if let Some(url) = &self.url {
+
            run.set_adapter_info_url(url);
+
        }
+

+
        db.push_run(run).unwrap();
+

+
        Ok(())
+
    }
+
}
+

+
#[derive(Parser)]
struct ListRuns {}

impl ListRuns {