gw_bin/checks/
mod.rs

1use crate::context::Context;
2use mockall::automock;
3use thiserror::Error;
4
5/// A check to fetch and pull a local git repository.
6pub mod git;
7/// A check to watch a directory for changes.
8pub mod watch;
9
10/// A custom error for describing the error cases for checks
11#[derive(Debug, Error)]
12pub enum CheckError {
13    /// Cannot initialize check, because it has a misconfiguration.
14    #[error("not configured correctly: {0}")]
15    Misconfigured(String),
16    /// Cannot run check, because there isn't enough permission.
17    #[error("permission denied: {0}")]
18    PermissionDenied(String),
19    /// Cannot update the check, because there is a conflict.
20    /// This can be a merge conflict, a filesystem issue
21    #[error("there is a conflict: {0}")]
22    Conflict(String),
23    /// Running the trigger failed.
24    #[error("failed while running: {0}")]
25    FailedUpdate(String),
26}
27
28/// A check is a process that tests if there are any changes and updates it.
29///
30/// Checks may include:
31///   - git fetch and git pull ([git::GitCheck])
32///   - watch a directory for updates ([watch::WatchCheck])
33///   - etc.
34#[automock]
35pub trait Check {
36    /// Check if there are changes and update if necessary.
37    fn check(&mut self, context: &mut Context) -> Result<bool, CheckError>;
38}