Radish alpha
r
rad:z2UcCU1LgMshWvXj6hXSDDrwB8q8M
Radicle Job Collaborative Object
Radicle
Git
docs: add documentation comments to all public items that lack them
Merged liw opened 10 months ago

Signed-off-by: Lars Wirzenius liw@liw.fi

2 files changed +43 -1 256242f1 e917ef06
modified src/error.rs
@@ -1,22 +1,32 @@
+
//! Error types for the `radicle-job` crate.
+

use radicle::{cob, git};
use thiserror::Error;

+
/// Errors for constructing a value from COB actions.
#[derive(Debug, Error)]
pub enum Build {
+
    /// Initial action is faulty.
    #[error("initial action of job must request an OID")]
    Initial,
+
    /// Job refers to commit that doesn't exist in repository.
    #[error("missing commit for job run {oid}: {err}")]
    MissingCommit {
+
        /// Object id that is missing.
        oid: git::Oid,
+
        /// Source error.
        #[source]
        err: git::Error,
    },
}

+
/// Errors from applying COB actions.
#[derive(Debug, Error)]
pub enum Apply {
+
    /// Build error.
    #[error(transparent)]
    Build(#[from] Build),
+
    /// Error in how action is encoded.
    #[error(transparent)]
    Op(#[from] cob::op::OpEncodingError),
}
modified src/lib.rs
@@ -1,5 +1,12 @@
//! Radicle "job COB".
//!
+
//! A [`Job`] records results of automated processing of a repository
+
//! for a given Git object (typically a commit), by one or more nodes.
+
//! Each processing is a [`Run`]. For example, nodes that run CI for a
+
//! repository might add `Run` to a `Job` for a specific commit. If
+
//! there are several nodes running CI, they would each add their own
+
//! `Run` to the same `Job`.
+
//!
//! # Example
//!
//! ```
@@ -39,6 +46,8 @@
//! job.run(uuid, log, &alice.signer).unwrap();
//! ```

+
#![deny(missing_docs)]
+

use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;
@@ -409,7 +418,9 @@ impl<R: ReadRepository> Evaluate<R> for Job {
    }
}

-
/// A `Run` represents a task run for a [`Job`].
+
/// A `Run` represents a task run for a [`Job`]. A `Run` value is
+
/// created before actual processing starts. The start end finish of a
+
/// run are recorded explicitly.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Run {
    /// The status of the run.
@@ -424,6 +435,7 @@ pub struct Run {
}

impl Run {
+
    /// Create a new `Run` with a URL to a log for the run.
    pub fn new(log: Url) -> Self {
        Self {
            status: Status::Started,
@@ -431,6 +443,7 @@ impl Run {
        }
    }

+
    /// Mark `Run` as finished.
    fn finish(self, reason: Reason) -> Self {
        Self {
            status: Status::Finished(reason),
@@ -438,10 +451,12 @@ impl Run {
        }
    }

+
    /// Return latest status of a run.
    pub fn status(&self) -> &Status {
        &self.status
    }

+
    /// Has run been started?
    pub fn is_started(&self) -> bool {
        match self.status {
            Status::Started => true,
@@ -449,10 +464,12 @@ impl Run {
        }
    }

+
    /// Has run finished?
    pub fn is_finished(&self) -> bool {
        !self.is_started()
    }

+
    /// Did run succeed?
    pub fn succeeded(&self) -> bool {
        match self.status {
            Status::Started => false,
@@ -461,6 +478,7 @@ impl Run {
        }
    }

+
    /// Did run fail?
    pub fn failed(&self) -> bool {
        match self.status {
            Status::Started => false,
@@ -482,10 +500,13 @@ pub enum Status {
/// The reason for a [`Status`] to have finished.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Reason {
+
    /// The run failed.
    Failed,
+
    /// The run succeeded.
    Succeeded,
}

+
/// All the `Job` items in the repository.
pub struct Jobs<'a, R> {
    raw: store::Store<'a, Job, R>,
}
@@ -539,6 +560,7 @@ where
        })
    }

+
    /// Create a new [`Job`] in the repository.
    pub fn create<'g, G>(
        &'g mut self,
        oid: Oid,
@@ -565,7 +587,9 @@ where
    }
}

+
/// A mutable `Job`.
pub struct JobMut<'a, 'g, R> {
+
    /// Git object that the [`Job`] applies to.
    pub id: ObjectId,

    job: Job,
@@ -584,10 +608,12 @@ impl<'a, 'g, R> JobMut<'a, 'g, R>
where
    R: WriteRepository + cob::Store<Namespace = NodeId>,
{
+
    /// Create a new `JobMut`.
    pub fn new(id: ObjectId, job: Job, store: &'g mut Jobs<'a, R>) -> Self {
        Self { id, job, store }
    }

+
    /// Git object id this `JobMut` applies to.
    pub fn id(&self) -> &ObjectId {
        &self.id
    }
@@ -630,6 +656,7 @@ where
        self.transaction("Finished node job", signer, |tx| tx.finish(uuid, reason))
    }

+
    /// Apply COB operations to a `JobMut`.
    pub fn transaction<G, F>(
        &mut self,
        message: &str,
@@ -650,6 +677,8 @@ where
    }
}

+
/// An update for the `Job` COB. This applies a change to the
+
/// in-memory computed representation of the COB.
pub struct Transaction<R: ReadRepository>(store::Transaction<Job, R>);

impl<R> From<store::Transaction<Job, R>> for Transaction<R>
@@ -703,14 +732,17 @@ impl<R> Transaction<R>
where
    R: ReadRepository,
{
+
    /// Add a request operation to the transaction.
    pub fn request(&mut self, oid: Oid) -> Result<(), store::Error> {
        self.0.push(Action::Request { oid })
    }

+
    /// Add a new `Run` to a transaction.
    pub fn run(&mut self, uuid: Uuid, log: Url) -> Result<(), store::Error> {
        self.0.push(Action::Run { uuid, log })
    }

+
    /// Mark a run as finished.
    pub fn finish(&mut self, uuid: Uuid, reason: Reason) -> Result<(), store::Error> {
        self.0.push(Action::Finished { uuid, reason })
    }