refactor: use ergo module for run commands

Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
Lars Wirzenius
2025-08-13 17:59:13 +03:00
parent cfb6998057
commit 7c3af34ac1
2 changed files with 23 additions and 5 deletions
+3
View File
@@ -363,4 +363,7 @@ enum CibToolError {
#[error(transparent)]
Event(#[from] cibtoolcmd::EventError),
#[error(transparent)]
Run(#[from] cibtoolcmd::RunError),
}
+20 -5
View File
@@ -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),
}