Compare commits
3 commits
84af6da22f
...
dda5992596
Author | SHA1 | Date | |
---|---|---|---|
dda5992596 | |||
f8375ed1fc | |||
eb7d14bc33 |
14 changed files with 65 additions and 172 deletions
|
@ -1,16 +1,10 @@
|
|||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
||||
#[display("{}", sha)]
|
||||
pub struct Commit {
|
||||
sha: Sha,
|
||||
message: Message,
|
||||
}
|
||||
impl Commit {
|
||||
pub fn new(sha: &str, message: &str) -> Self {
|
||||
Self {
|
||||
sha: Sha::new(sha.to_string()),
|
||||
message: Message::new(message.to_string()),
|
||||
}
|
||||
}
|
||||
pub const fn sha(&self) -> &Sha {
|
||||
&self.sha
|
||||
}
|
||||
|
@ -19,18 +13,8 @@ impl Commit {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
||||
pub struct Sha(String);
|
||||
impl Sha {
|
||||
pub const fn new(value: String) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
||||
pub struct Message(String);
|
||||
impl Message {
|
||||
pub const fn new(value: String) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::Commit;
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, derive_more::Display)]
|
||||
pub struct GitRef(pub String);
|
||||
pub struct GitRef(String);
|
||||
impl From<Commit> for GitRef {
|
||||
fn from(value: Commit) -> Self {
|
||||
Self(value.sha().to_string())
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
use git_next_config::{Hostname, RepoPath};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Display)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Display)]
|
||||
#[display("{}:{}", host, repo_path)]
|
||||
pub struct GitRemote {
|
||||
host: Hostname,
|
||||
repo_path: RepoPath,
|
||||
}
|
||||
impl GitRemote {
|
||||
pub const fn new(host: Hostname, repo_path: RepoPath) -> Self {
|
||||
Self { host, repo_path }
|
||||
}
|
||||
pub const fn host(&self) -> &Hostname {
|
||||
&self.host
|
||||
}
|
||||
|
|
|
@ -7,17 +7,13 @@ use tracing::{debug, info};
|
|||
|
||||
const CHECK_INTERVAL: Duration = Duration::from_secs(1);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct WatchFile;
|
||||
impl Message for WatchFile {
|
||||
type Result = ();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct FileUpdated;
|
||||
impl Message for FileUpdated {
|
||||
type Result = ();
|
||||
}
|
||||
|
||||
#[derive(Debug, derive_more::From, derive_more::Display)]
|
||||
pub enum Error {
|
||||
|
@ -72,13 +68,3 @@ impl Handler<WatchFile> for FileWatcher {
|
|||
}
|
||||
}
|
||||
}
|
||||
// impl Handler<Stop> for FileWatcher {
|
||||
// type Result = anyhow::Result<()>;
|
||||
//
|
||||
// fn handle(&mut self, _msg: Stop, ctx: &mut Self::Context) -> Self::Result {
|
||||
// warn!("Stopping file watcher actor");
|
||||
// self.run_interval.take();
|
||||
// ctx.stop();
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -16,6 +16,8 @@ use crate::{actors::repo::webhook::WebhookAuth, config::Webhook, gitforge, types
|
|||
|
||||
use self::webhook::WebhookId;
|
||||
|
||||
#[derive(Debug, derive_more::Display)]
|
||||
#[display("{}:{}:{}", generation, details.forge.forge_name(), details.repo_alias)]
|
||||
pub struct RepoActor {
|
||||
generation: Generation,
|
||||
message_token: MessageToken,
|
||||
|
@ -79,17 +81,6 @@ impl Actor for RepoActor {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for RepoActor {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}:{}:{}",
|
||||
self.generation,
|
||||
self.details.forge.forge_name(),
|
||||
self.details.repo_alias
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
|
@ -136,7 +127,7 @@ impl Handler<LoadConfigFromRepo> for RepoActor {
|
|||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
struct LoadedConfig(pub RepoConfig);
|
||||
struct LoadedConfig(RepoConfig);
|
||||
impl Handler<LoadedConfig> for RepoActor {
|
||||
type Result = ();
|
||||
#[tracing::instrument(name = "RepoActor::LoadedConfig", skip_all, fields(repo = %self.details, branches = %msg.0))]
|
||||
|
@ -151,16 +142,11 @@ impl Handler<LoadedConfig> for RepoActor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[derive(derive_more::Constructor, Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct ValidateRepo {
|
||||
message_token: MessageToken,
|
||||
}
|
||||
impl ValidateRepo {
|
||||
pub const fn new(message_token: MessageToken) -> Self {
|
||||
Self { message_token }
|
||||
}
|
||||
}
|
||||
impl Handler<ValidateRepo> for RepoActor {
|
||||
type Result = ();
|
||||
#[tracing::instrument(name = "RepoActor::ValidateRepo", skip_all, fields(repo = %self.details, token = %msg.message_token))]
|
||||
|
@ -208,17 +194,19 @@ impl Handler<ValidateRepo> for RepoActor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Message)]
|
||||
#[derive(Debug, derive_more::Constructor, Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct StartMonitoring {
|
||||
pub main: git::Commit,
|
||||
pub next: git::Commit,
|
||||
pub dev: git::Commit,
|
||||
pub dev_commit_history: Vec<git::Commit>,
|
||||
main: git::Commit,
|
||||
next: git::Commit,
|
||||
dev: git::Commit,
|
||||
dev_commit_history: Vec<git::Commit>,
|
||||
}
|
||||
impl Handler<StartMonitoring> for RepoActor {
|
||||
type Result = ();
|
||||
#[tracing::instrument(name = "RepoActor::StartMonitoring", skip_all, fields(token = %self.message_token, repo = %self.details, main = %msg.main, next= %msg.next, dev = %msg.dev))]
|
||||
#[tracing::instrument(name = "RepoActor::StartMonitoring", skip_all,
|
||||
fields(token = %self.message_token, repo = %self.details, main = %msg.main, next= %msg.next, dev = %msg.dev))
|
||||
]
|
||||
fn handle(&mut self, msg: StartMonitoring, ctx: &mut Self::Context) -> Self::Result {
|
||||
info!("Message Received");
|
||||
let Some(repo_config) = self.details.repo_config.clone() else {
|
||||
|
@ -259,7 +247,7 @@ impl Handler<StartMonitoring> for RepoActor {
|
|||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct WebhookRegistered(pub WebhookId, pub WebhookAuth);
|
||||
pub struct WebhookRegistered(WebhookId, WebhookAuth);
|
||||
impl Handler<WebhookRegistered> for RepoActor {
|
||||
type Result = ();
|
||||
#[tracing::instrument(name = "RepoActor::WebhookRegistered", skip_all, fields(repo = %self.details, webhook_id = %msg.0))]
|
||||
|
@ -272,7 +260,7 @@ impl Handler<WebhookRegistered> for RepoActor {
|
|||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct AdvanceMainTo(pub git::Commit);
|
||||
pub struct AdvanceMainTo(git::Commit);
|
||||
impl Handler<AdvanceMainTo> for RepoActor {
|
||||
type Result = ();
|
||||
#[tracing::instrument(name = "RepoActor::AdvanceMainTo", skip_all, fields(repo = %self.details, commit = %msg.0))]
|
||||
|
|
|
@ -6,13 +6,25 @@ mod branch {
|
|||
|
||||
#[actix_rt::test]
|
||||
async fn test_find_next_commit_on_dev() {
|
||||
let next = git::Commit::new("current-next", "foo");
|
||||
let expected = git::Commit::new("dev-next", "next-should-go-here");
|
||||
let next = git::Commit::new(
|
||||
git::commit::Sha::new("current-next".to_string()),
|
||||
git::commit::Message::new("foo".to_string()),
|
||||
);
|
||||
let expected = git::Commit::new(
|
||||
git::commit::Sha::new("dev-next".to_string()),
|
||||
git::commit::Message::new("next-should-go-here".to_string()),
|
||||
);
|
||||
let dev_commit_history = vec![
|
||||
git::Commit::new("dev", "future"),
|
||||
git::Commit::new(
|
||||
git::commit::Sha::new("dev".to_string()),
|
||||
git::commit::Message::new("future".to_string()),
|
||||
),
|
||||
expected.clone(),
|
||||
next.clone(),
|
||||
git::Commit::new("current-main", "history"),
|
||||
git::Commit::new(
|
||||
git::commit::Sha::new("current-main".to_string()),
|
||||
git::commit::Message::new("history".to_string()),
|
||||
),
|
||||
];
|
||||
|
||||
let next_commit = find_next_commit_on_dev(next, dev_commit_history);
|
||||
|
|
|
@ -5,7 +5,7 @@ use kxio::network::{self, json};
|
|||
use tracing::{debug, info, warn};
|
||||
use ulid::DecodeError;
|
||||
|
||||
use std::{collections::HashMap, fmt::Display, ops::Deref, str::FromStr};
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
|
||||
use crate::{
|
||||
actors::{
|
||||
|
@ -15,27 +15,12 @@ use crate::{
|
|||
config::{Webhook, WebhookUrl},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, Eq, derive_more::Constructor, derive_more::Deref, derive_more::Display,
|
||||
)]
|
||||
pub struct WebhookId(String);
|
||||
impl WebhookId {
|
||||
#[allow(dead_code)]
|
||||
pub const fn new(id: String) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
}
|
||||
impl Deref for WebhookId {
|
||||
type Target = String;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
impl Display for WebhookId {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, derive_more::Deref)]
|
||||
pub struct WebhookAuth(ulid::Ulid);
|
||||
impl WebhookAuth {
|
||||
pub fn from_str(authorisation: &str) -> Result<Self, DecodeError> {
|
||||
|
@ -51,12 +36,6 @@ impl WebhookAuth {
|
|||
format!("Basic {}", self.0.to_string())
|
||||
}
|
||||
}
|
||||
impl Deref for WebhookAuth {
|
||||
type Target = ulid::Ulid;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all, fields(%webhook_id))]
|
||||
pub async fn unregister(webhook_id: WebhookId, repo_details: RepoDetails, net: network::Network) {
|
||||
|
@ -301,7 +280,10 @@ impl Push {
|
|||
}
|
||||
|
||||
pub fn commit(&self) -> git::Commit {
|
||||
git::Commit::new(&self.after, &self.head_commit.message)
|
||||
git::Commit::new(
|
||||
git::commit::Sha::new(self.after.clone()),
|
||||
git::commit::Message::new(self.head_commit.message.clone()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,46 +3,21 @@ use actix::prelude::*;
|
|||
|
||||
use crate::actors::repo::webhook::WebhookAuth;
|
||||
|
||||
#[derive(Message, Debug, Clone)]
|
||||
#[derive(Message, Debug, Clone, derive_more::Constructor)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct WebhookMessage {
|
||||
id: String,
|
||||
path: String,
|
||||
authorisation: String,
|
||||
// query: String,
|
||||
// headers: warp::http::HeaderMap,
|
||||
body: String,
|
||||
}
|
||||
impl WebhookMessage {
|
||||
pub const fn new(
|
||||
id: String,
|
||||
path: String,
|
||||
// query: String,
|
||||
// headers: warp::http::HeaderMap,
|
||||
body: String,
|
||||
authorisation: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
id,
|
||||
path,
|
||||
// query,
|
||||
// headers,
|
||||
body,
|
||||
authorisation,
|
||||
}
|
||||
}
|
||||
pub const fn id(&self) -> &String {
|
||||
&self.id
|
||||
}
|
||||
pub const fn path(&self) -> &String {
|
||||
&self.path
|
||||
}
|
||||
// pub const fn query(&self) -> &String {
|
||||
// &self.query
|
||||
// }
|
||||
// pub const fn headers(&self) -> &warp::http::HeaderMap {
|
||||
// &self.headers
|
||||
// }
|
||||
pub const fn body(&self) -> &String {
|
||||
&self.body
|
||||
}
|
||||
|
|
|
@ -42,11 +42,9 @@ impl Actor for WebhookActor {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Message)]
|
||||
#[rtype(result = "()")]
|
||||
pub struct ShutdownWebhook;
|
||||
impl Message for ShutdownWebhook {
|
||||
type Result = ();
|
||||
}
|
||||
impl Handler<ShutdownWebhook> for WebhookActor {
|
||||
type Result = ();
|
||||
|
||||
|
|
|
@ -8,15 +8,7 @@ use crate::gitforge::{self, ForgeFileError};
|
|||
pub async fn load(
|
||||
details: &RepoDetails,
|
||||
forge: &gitforge::Forge,
|
||||
) -> Result<
|
||||
RepoConfig,
|
||||
OneOf<(
|
||||
ForgeFileError,
|
||||
crate::config::Error,
|
||||
toml::de::Error,
|
||||
RepoConfigValidationErrors,
|
||||
)>,
|
||||
> {
|
||||
) -> Result<RepoConfig, OneOf<(ForgeFileError, crate::config::Error, toml::de::Error, Error)>> {
|
||||
let contents = forge
|
||||
.file_contents_get(&details.branch, ".git-next.toml")
|
||||
.await
|
||||
|
@ -27,42 +19,33 @@ pub async fn load(
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RepoConfigValidationErrors {
|
||||
pub enum Error {
|
||||
Forge(gitforge::ForgeBranchError),
|
||||
BranchNotFound(BranchName),
|
||||
}
|
||||
|
||||
pub async fn validate(
|
||||
config: RepoConfig,
|
||||
forge: &gitforge::Forge,
|
||||
) -> Result<RepoConfig, RepoConfigValidationErrors> {
|
||||
pub async fn validate(config: RepoConfig, forge: &gitforge::Forge) -> Result<RepoConfig, Error> {
|
||||
let branches = forge.branches_get_all().await.map_err(|e| {
|
||||
error!(?e, "Failed to list branches");
|
||||
RepoConfigValidationErrors::Forge(e)
|
||||
Error::Forge(e)
|
||||
})?;
|
||||
if !branches
|
||||
.iter()
|
||||
.any(|branch| branch == &config.branches().main())
|
||||
{
|
||||
return Err(RepoConfigValidationErrors::BranchNotFound(
|
||||
config.branches().main(),
|
||||
));
|
||||
return Err(Error::BranchNotFound(config.branches().main()));
|
||||
}
|
||||
if !branches
|
||||
.iter()
|
||||
.any(|branch| branch == &config.branches().next())
|
||||
{
|
||||
return Err(RepoConfigValidationErrors::BranchNotFound(
|
||||
config.branches().next(),
|
||||
));
|
||||
return Err(Error::BranchNotFound(config.branches().next()));
|
||||
}
|
||||
if !branches
|
||||
.iter()
|
||||
.any(|branch| branch == &config.branches().dev())
|
||||
{
|
||||
return Err(RepoConfigValidationErrors::BranchNotFound(
|
||||
config.branches().dev(),
|
||||
));
|
||||
return Err(Error::BranchNotFound(config.branches().dev()));
|
||||
}
|
||||
Ok(config)
|
||||
}
|
||||
|
|
|
@ -89,13 +89,8 @@ impl Webhook {
|
|||
}
|
||||
|
||||
/// The URL for the webhook where forges should send their updates
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize, derive_more::AsRef)]
|
||||
pub struct WebhookUrl(String);
|
||||
impl AsRef<str> for WebhookUrl {
|
||||
fn as_ref(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// The directory to store server data, such as cloned repos
|
||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)]
|
||||
|
|
|
@ -254,6 +254,9 @@ struct RepoCommit {
|
|||
}
|
||||
impl From<Commit> for git::Commit {
|
||||
fn from(value: Commit) -> Self {
|
||||
Self::new(&value.sha, &value.commit.message)
|
||||
Self::new(
|
||||
git::commit::Sha::new(value.sha),
|
||||
git::commit::Message::new(value.commit.message),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,12 +59,7 @@ impl super::ForgeLike for ForgeJoEnv {
|
|||
dev,
|
||||
dev_commit_history,
|
||||
}) => {
|
||||
addr.do_send(StartMonitoring {
|
||||
main,
|
||||
next,
|
||||
dev,
|
||||
dev_commit_history,
|
||||
});
|
||||
addr.do_send(StartMonitoring::new(main, next, dev, dev_commit_history));
|
||||
}
|
||||
Err(err) => {
|
||||
warn!("{}", err);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, derive_more::Display)]
|
||||
pub struct MessageToken(u32);
|
||||
impl MessageToken {
|
||||
pub fn new() -> Self {
|
||||
|
@ -8,8 +8,3 @@ impl MessageToken {
|
|||
Self(self.0 + 1)
|
||||
}
|
||||
}
|
||||
impl std::fmt::Display for MessageToken {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue