From 546d91554c7e1fe45f87ea0f9ef3d891436a75c7 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 10 Apr 2024 09:16:42 +0100 Subject: [PATCH] feat(server): next commit status is returned as pass, fail ro pending --- src/server/actors/repo/mod.rs | 2 +- src/server/actors/repo/status.rs | 21 ++++++++++++++++++--- src/server/forge/forgejo/mod.rs | 7 +++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/server/actors/repo/mod.rs b/src/server/actors/repo/mod.rs index 59f4af2..41cc55f 100644 --- a/src/server/actors/repo/mod.rs +++ b/src/server/actors/repo/mod.rs @@ -1,6 +1,6 @@ mod branch; mod config; -mod status; +pub mod status; mod webhook; use actix::prelude::*; diff --git a/src/server/actors/repo/status.rs b/src/server/actors/repo/status.rs index 2e58c3e..345048e 100644 --- a/src/server/actors/repo/status.rs +++ b/src/server/actors/repo/status.rs @@ -13,12 +13,27 @@ pub async fn check_next( addr: Addr, net: kxio::network::Network, ) { - let is_success = match repo_details.forge.forge_type { + // get the status - pass, fail, pending (all others map to fail, e.g. error) + let status = match repo_details.forge.forge_type { ForgeType::ForgeJo => { forge::forgejo::get_commit_status(next.clone(), repo_details, net).await } }; - if is_success { - addr.do_send(AdvanceMainTo(next)); + match status { + Status::Pass => { + addr.do_send(AdvanceMainTo(next)); + } + Status::Pending => (), // TODO: (#22) wait and try again OR can webhook tell us when it's done, in + // which case we can do nothing here and wait for the webhook to trigger + Status::Fail => (), // TODO: (#21) reset next and wait for dev to be updated and this + // commit removed from the commit history before trying again } } + +pub enum Status { + #[allow(dead_code)] // TODO: (#13) remove this when we have results from the forge + Pass, + #[allow(dead_code)] // TODO: (#13) remove this when we have results from the forge + Fail, + Pending, +} diff --git a/src/server/forge/forgejo/mod.rs b/src/server/forge/forgejo/mod.rs index 810ed87..fe04f78 100644 --- a/src/server/forge/forgejo/mod.rs +++ b/src/server/forge/forgejo/mod.rs @@ -2,7 +2,7 @@ use kxio::network; use terrors::OneOf; use tracing::{error, info}; -use crate::server::{config::BranchName, forge}; +use crate::server::{actors::repo::status::Status, config::BranchName, forge}; use super::CommitHistories; @@ -65,15 +65,14 @@ struct Commit { sha: String, } -#[allow(dead_code)] pub async fn get_commit_status( _next: forge::Commit, _repo_details: crate::server::config::RepoDetails, _net: network::Network, -) -> bool { +) -> Status { // TODO: (#13) check statuses for next head - if ok, advance main to next and reassess // https://{hostname}/api/v1/repos/{path}/commits/{commit}/status?token={token} - false + Status::Pending } #[derive(Debug, serde::Deserialize)]