Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
fix: if adapter does not provide a run id, invent one
Lars Wirzenius committed 1 year ago
commit 5f24cf53fc809861f72fd1465530553e7cf90ef6
parent fe0a86bf83dbd6280a04e47d7c48c0c45b150974
2 files changed +11 -2
modified src/broker.rs
@@ -17,7 +17,7 @@ use radicle::prelude::RepoId;
use crate::{
    adapter::Adapter,
    db::{Db, DbError},
-
    msg::{PatchEvent, PushEvent, Request},
+
    msg::{PatchEvent, PushEvent, Request, RunId},
    run::{Run, Whence},
};

@@ -68,7 +68,7 @@ impl Broker {
    pub fn execute_ci(&mut self, trigger: &Request) -> Result<Run, BrokerError> {
        info!("Start CI run");
        debug!("Start Ci run on {trigger:#?}");
-
        let run = match trigger {
+
        let mut run = match trigger {
            Request::Trigger {
                common,
                push,
@@ -121,6 +121,14 @@ impl Broker {
            }
        };
        info!("Finish CI run: {run:?}");
+

+
        // If the adapter never gave us a run ID, it has not been set.
+
        // In that case, we invent one so that it can be used by the
+
        // database as a key.
+
        if run.adapter_run_id().is_none() {
+
            run.set_adapter_run_id(RunId::default());
+
        }
+

        self.db.push_run(run.clone())?;

        Ok(run)
modified src/run.rs
@@ -56,6 +56,7 @@ impl Run {

    /// Set the run id assigned by the adapter.
    pub fn set_adapter_run_id(&mut self, run_id: RunId) {
+
        assert!(self.adapter_run_id.is_none());
        self.adapter_run_id = Some(run_id);
    }