Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
refactor: use ergo module for run commands
Lars Wirzenius committed 8 months ago
commit 7c3af34ac135dcabd23669008a30c8e8d053061e
parent cfb6998
2 files changed +23 -5
modified src/bin/cibtool.rs
@@ -363,4 +363,7 @@ enum CibToolError {

    #[error(transparent)]
    Event(#[from] cibtoolcmd::EventError),
+

+
    #[error(transparent)]
+
    Run(#[from] cibtoolcmd::RunError),
}
modified src/bin/cibtoolcmd/run.rs
@@ -1,6 +1,6 @@
use std::collections::HashSet;

-
use radicle_ci_broker::run::RunBuilder;
+
use radicle_ci_broker::{ergo, run::RunBuilder};
use radicle_job::JobId;

use super::*;
@@ -62,9 +62,18 @@ impl Leaf for AddRun {
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
        let db = args.open_db()?;

-
        let profile = util::load_profile()?;
-
        let (rid, repo_name) = util::lookup_repo(&profile, &self.repo)?;
-
        let oid = util::oid_from_cli_arg(&profile, rid, &self.commit)?;
+
        let r = ergo::Radicle::new().map_err(RunError::Ergonomic)?;
+
        let repo = r
+
            .repository_by_name(&self.repo)
+
            .map_err(RunError::Ergonomic)?;
+
        let repo_name = r
+
            .project(&repo.id)
+
            .map_err(RunError::Ergonomic)?
+
            .name()
+
            .to_string();
+
        let oid = r
+
            .resolve_commit(&repo.id, &self.commit)
+
            .map_err(RunError::Ergonomic)?;
        let ts = self.timestamp.clone().unwrap_or(util::now()?);

        let whence = Whence::Branch {
@@ -74,7 +83,7 @@ impl Leaf for AddRun {
        };
        let mut run = RunBuilder::default()
            .broker_run_id(RunId::default())
-
            .repo_id(rid)
+
            .repo_id(repo.id)
            .repo_name(&repo_name)
            .whence(whence)
            .timestamp(ts)
@@ -264,3 +273,9 @@ impl Leaf for ListRuns {
        Ok(())
    }
}
+

+
#[derive(Debug, thiserror::Error)]
+
pub enum RunError {
+
    #[error(transparent)]
+
    Ergonomic(#[from] radicle_ci_broker::ergo::ErgoError),
+
}