Compare commits

..

No commits in common. "c37bd2c64db41b3dd70ada080abe50130928484e" and "ad358ad7c2427a1d1df760cb57e055cb8cae9db3" have entirely different histories.

25 changed files with 57 additions and 291 deletions

7
Cargo.lock generated
View file

@ -993,7 +993,6 @@ dependencies = [
"secrecy",
"serde",
"serde_json",
"take-until",
"test-log",
"thiserror",
"time",
@ -3636,12 +3635,6 @@ dependencies = [
"libc",
]
[[package]]
name = "take-until"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb"
[[package]]
name = "tempfile"
version = "3.10.1"

View file

@ -84,9 +84,6 @@ anyhow = "1.0"
thiserror = "1.0"
pike = "0.1"
# iters
take-until = "0.2"
# file watcher
notify = "6.1"

View file

@ -1,10 +1,6 @@
//
use git_next_core::{git::UserNotification, message, server::Shout};
message!(UpdateShout, Shout, "Updated Shout configuration");
message!(UpdateShout: Shout: "Updated Shout configuration");
message!(
NotifyUser,
UserNotification,
"Request to send the message payload to the notification webhook"
);
message!(NotifyUser: UserNotification: "Request to send the message payload to the notification webhook");

View file

@ -6,37 +6,22 @@ use git_next_core::{
message, newtype, ForgeNotification, RegisteredWebhook, RepoConfig, WebhookAuth, WebhookId,
};
message!(
LoadConfigFromRepo,
"Request to load the `git-next.toml` from the git repo."
);
message!(CloneRepo, "Request to clone (or open) the git repo.");
message!(
ReceiveRepoConfig,
RepoConfig,
r#"Notification that the `git-next.toml` file has been loaded from the repo and parsed.
message!(LoadConfigFromRepo: "Request to load the `git-next.toml` from the git repo.");
message!(CloneRepo: "Request to clone (or open) the git repo.");
message!(ReceiveRepoConfig: RepoConfig: r#"Notification that the `git-next.toml` file has been loaded from the repo and parsed.
Contains the parsed contents of the `git-next.toml` file."#
);
message!(
ValidateRepo,
MessageToken,
r#"Request that the state of the branches in the git repo be assessed and generate any followup actions.
Contains the parsed contents of the `git-next.toml` file."#);
message!(ValidateRepo: MessageToken: r#"Request that the state of the branches in the git repo be assessed and generate any followup actions.
This is the main function of `git-next` where decisions are made on what branches need to be updated and when.
Contains a [MessageToken] to reduce duplicate messages being sent. Only messages with the latest [MessageToken] are handled,
all others are dropped."#
);
all others are dropped."#);
message!(
WebhookRegistered,
(WebhookId, WebhookAuth),
r#"Notification that a webhook has been registered with a forge.
message!(WebhookRegistered: (WebhookId, WebhookAuth): r#"Notification that a webhook has been registered with a forge.
Contains a tuple of the ID for the webhook returned from the forge, and the unique authorisation token that
incoming messages from the forge must provide."#
);
incoming messages from the forge must provide."#);
impl WebhookRegistered {
pub const fn webhook_id(&self) -> &WebhookId {
&self.0 .0
@ -53,51 +38,28 @@ impl From<RegisteredWebhook> for WebhookRegistered {
}
}
message!(
UnRegisterWebhook,
"Request that the webhook be removed from the forge, so they will stop notifying us."
);
message!(UnRegisterWebhook: "Request that the webhook be removed from the forge, so they will stop notifying us.");
newtype!(
MessageToken,
u32,
Copy,
Default,
Display,
PartialOrd,
Ord,
r#"An incremental token used to identify the current set of messages.
newtype!(MessageToken: u32, Copy, Default, Display, PartialOrd, Ord: r#"An incremental token used to identify the current set of messages.
Primarily used by [ValidateRepo] to reduce duplicate messages. The token is incremented when a new Webhook message is
received, marking that message the latest, and causing any previous messages still being processed to be dropped when
they next send a [ValidateRepo] message."#
);
they next send a [ValidateRepo] message."#);
impl MessageToken {
pub const fn next(self) -> Self {
Self(self.0 + 1)
}
}
message!(
RegisterWebhook,
"Requests that a Webhook be registered with the forge."
);
message!(
CheckCIStatus,
Commit,
r#"Requests that the CI status for the commit be checked.
message!(RegisterWebhook: "Requests that a Webhook be registered with the forge.");
message!(CheckCIStatus: Commit: r#"Requests that the CI status for the commit be checked.
Once the CI Status has been received it will be sent via a [ReceiveCIStatus] message.
Contains the commit from the tip of the `next` branch."#
); // next commit
message!(
ReceiveCIStatus,
(Commit, Status),
r#"Notification of the status of the CI checks for the commit.
Contains the commit from the tip of the `next` branch."#); // next commit
message!(ReceiveCIStatus: (Commit, Status): r#"Notification of the status of the CI checks for the commit.
Contains a tuple of the commit that was checked (the tip of the `next` branch) and the status."#
); // commit and it's status
Contains a tuple of the commit that was checked (the tip of the `next` branch) and the status."#); // commit and it's status
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AdvanceNextPayload {
@ -105,23 +67,7 @@ pub struct AdvanceNextPayload {
pub main: Commit,
pub dev_commit_history: Vec<Commit>,
}
message!(
AdvanceNext,
AdvanceNextPayload,
"Request to advance the `next` branch on to the next commit on the `dev branch."
); // next commit and the dev commit history
message!(
AdvanceMain,
Commit,
"Request to advance the `main` branch on to same commit as the `next` branch."
); // next commit
message!(
WebhookNotification,
ForgeNotification,
"Notification of a webhook message from the forge."
);
message!(
NotifyUser,
UserNotification,
"Request to send the message payload to the notification webhook"
);
message!(AdvanceNext: AdvanceNextPayload: "Request to advance the `next` branch on to the next commit on the `dev branch."); // next commit and the dev commit history
message!(AdvanceMain: Commit: "Request to advance the `main` branch on to same commit as the `next` branch."); // next commit
message!(WebhookNotification: ForgeNotification: "Notification of a webhook message from the forge.");
message!(NotifyUser: UserNotification: "Request to send the message payload to the notification webhook");

View file

@ -78,7 +78,7 @@ impl ActorLog {
}
}
message!(ExamineActor => RepoActorView, "Request a view of the current state of the [RepoActor].");
message!(ExamineActor => RepoActorView: "Request a view of the current state of the [RepoActor].");
impl Handler<ExamineActor> for RepoActor {
type Result = RepoActorView;

View file

@ -9,15 +9,11 @@ use git_next_core::{
use std::net::SocketAddr;
// receive server config
message!(
ReceiveAppConfig,
AppConfig,
"Notification of newly loaded server configuration.
message!(ReceiveAppConfig: AppConfig: "Notification of newly loaded server configuration.
This message will prompt the `git-next` server to stop and restart all repo-actors.
Contains the new server configuration."
);
Contains the new server configuration.");
// receive valid server config
#[derive(Clone, Debug, PartialEq, Eq, Constructor)]
@ -26,10 +22,6 @@ pub struct ValidAppConfig {
pub socket_address: SocketAddr,
pub storage: Storage,
}
message!(
ReceiveValidAppConfig,
ValidAppConfig,
"Notification of validated server configuration."
);
message!(ReceiveValidAppConfig: ValidAppConfig: "Notification of validated server configuration.");
message!(Shutdown, "Notification to shutdown the server actor");
message!(Shutdown: "Notification to shutdown the server actor");

View file

@ -1,4 +1,4 @@
//
use git_next_core::message;
message!(ShutdownWebhook, "Request to shutdown the Webhook actor");
message!(ShutdownWebhook: "Request to shutdown the Webhook actor");

View file

@ -57,9 +57,6 @@ serde_json = { workspace = true }
mockall = { workspace = true }
#iters
take-until = { workspace = true }
[dev-dependencies]
# Testing
assert2 = { workspace = true }

View file

@ -3,12 +3,4 @@ use serde::Serialize;
use crate::newtype;
newtype!(
BranchName,
String,
Display,
Default,
Hash,
Serialize,
"The name of a Git branch"
);
newtype!(BranchName: String, Display, Default, Hash, Serialize: "The name of a Git branch");

View file

@ -1,18 +1,6 @@
use serde::Serialize;
use crate::newtype;
newtype!(
ForgeAlias,
String,
Hash,
PartialOrd,
Ord,
derive_more::Display,
Default,
Serialize,
"The name of a Forge to connect to"
);
crate::newtype!(ForgeAlias: String, Hash, PartialOrd, Ord, derive_more::Display, Default, Serialize: "The name of a Forge to connect to");
impl From<&ForgeAlias> for std::path::PathBuf {
fn from(value: &ForgeAlias) -> Self {
Self::from(&value.0)

View file

@ -1,3 +0,0 @@
use crate::newtype;
newtype!(LogGraph, Vec<String>, "Git log showing branch positions");

View file

@ -1,10 +1,2 @@
//
use crate::newtype;
newtype!(
Hostname,
String,
derive_more::Display,
Default,
"The hostname for the forge"
);
// The hostname of a forge
crate::newtype!(Hostname: String, derive_more::Display, Default: "The hostname for the forge");

View file

@ -7,7 +7,6 @@ mod forge_config;
mod forge_details;
mod forge_type;
pub mod git_dir;
mod graphs;
mod host_name;
mod registered_webhook;
mod remote_url;

View file

@ -1,14 +1,6 @@
//
use std::borrow::ToOwned;
use crate::newtype;
newtype!(
RemoteUrl,
git_url_parse::GitUrl,
derive_more::Display,
"The URL of a remote repository"
);
crate::newtype!(RemoteUrl: git_url_parse::GitUrl, derive_more::Display: "The URL of a remote repository");
impl RemoteUrl {
pub fn parse(url: impl Into<String>) -> Option<Self> {
Some(Self::new(::git_url_parse::GitUrl::parse(&url.into()).ok()?))

View file

@ -3,16 +3,6 @@ use serde::Serialize;
use crate::newtype;
newtype!(
RepoAlias,
String,
Display,
Default,
Hash,
PartialOrd,
Ord,
Serialize,
r#"The alias of a repo.
newtype!(RepoAlias: String, Display, Default, Hash, PartialOrd, Ord, Serialize: r#"The alias of a repo.
This is the alias for the repo within `git-next-server.toml`."#
);
This is the alias for the repo within `git-next-server.toml`."#);

View file

@ -122,13 +122,8 @@ impl Listen {
}
newtype!(
ListenUrl,
String,
Serialize,
Deserialize,
PartialOrd,
Ord,
Display,
ListenUrl:
String, Serialize, Deserialize, PartialOrd, Ord, Display:
"The base url for receiving all webhooks from all forges"
);
impl ListenUrl {
@ -138,13 +133,9 @@ impl ListenUrl {
}
}
newtype!(ForgeWebhookUrl, String, "Raw URL from a forge Webhook");
newtype!(ForgeWebhookUrl: String: "Raw URL from a forge Webhook");
newtype!(
RepoListenUrl,
(ListenUrl, ForgeAlias, RepoAlias),
"URL to listen for webhook from forges"
);
newtype!(RepoListenUrl: (ListenUrl, ForgeAlias, RepoAlias): "URL to listen for webhook from forges");
impl Display for RepoListenUrl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(

View file

@ -1,14 +1,9 @@
//
use crate::newtype;
newtype!(
WebhookAuth,
ulid::Ulid,
derive_more::Display,
r#"The unique token authorisation for the webhook.
newtype!(WebhookAuth: ulid::Ulid, derive_more::Display: r#"The unique token authorisation for the webhook.
Each monitored repository has it's own unique token, and it is different each time `git-next` runs."#
);
Each monitored repository has it's own unique token, and it is different each time `git-next` runs."#);
impl WebhookAuth {
/// Parses the authorisation string as a `Ulid` to create a `WebhookAuth`.
///

View file

@ -1,9 +1,2 @@
//
use crate::newtype;
newtype!(
WebhookId,
String,
derive_more::Display,
"The ID of the webhook, as returned by the forge when it is registered."
);
crate::newtype!(WebhookId: String, derive_more::Display: "The ID of the webhook, as returned by the forge when it is registered.");

View file

@ -41,26 +41,8 @@ impl From<webhook::Push> for Commit {
}
}
newtype!(
Sha,
String,
Display,
Hash,
PartialOrd,
Ord,
Serialize,
"The unique SHA for a git commit."
);
newtype!(
Message,
String,
Display,
Hash,
PartialOrd,
Ord,
Serialize,
"The commit message for a git commit."
);
newtype!(Sha: String, Display, Hash,PartialOrd, Ord, Serialize: "The unique SHA for a git commit.");
newtype!(Message: String, Display, Hash, PartialOrd, Ord, Serialize: "The commit message for a git commit.");
#[derive(Clone, Debug)]
pub struct Histories {

View file

@ -2,16 +2,9 @@ use derive_more::Display;
use crate::newtype;
newtype!(
Generation,
u32,
Display,
Default,
Copy,
r#"A counter for the server generation.
newtype!(Generation: u32, Display, Default, Copy: r#"A counter for the server generation.
This counter is increased by one each time the server restarts itself when the configuration file is updated."#
);
This counter is increased by one each time the server restarts itself when the configuration file is updated."#);
impl Generation {
pub fn inc(&mut self) {
self.0 += 1;

View file

@ -5,7 +5,7 @@ use derive_more::Display;
use crate::git::{commit::Sha, Commit};
newtype!(GitRef, String, Display, "A git reference to a git commit.");
newtype!(GitRef: String, Display: "A git reference to a git commit.");
impl From<Commit> for GitRef {
fn from(value: Commit) -> Self {
Self(value.sha().to_string())

View file

@ -1,58 +0,0 @@
//
use std::borrow::ToOwned;
use take_until::TakeUntilExt;
use crate::{GitDir, RepoBranches};
// create a graph to log relative positions
//
// ANCESTOR=$(git merge-base --octopus origin/main origin/next origin/dev)
// SHORT_ANCESTOR=$(echo $ANCESTOR | cut -b -7)
fn ancesstor(gitdir: &GitDir, branches: &RepoBranches) -> Option<String> {
let result = std::process::Command::new("/usr/bin/git")
.current_dir(gitdir.to_path_buf())
.args([
"merge-base",
"--octopus",
format!("origin/{}", branches.main()).as_str(),
format!("origin/{}", branches.next()).as_str(),
format!("origin/{}", branches.dev()).as_str(),
])
.output();
if let Ok(output) = result {
return String::from_utf8_lossy(output.stdout.as_slice())
.split('\n')
.take(1)
.map(|line| line.chars().take(7).collect::<String>())
.collect::<Vec<_>>()
.first()
.cloned();
}
None
}
// git log --oneline --graph --decorate origin/main origin/dev origin/next | awk "1;/$SHORT_ANCESTOR/{exit}"
fn log(gitdir: &GitDir, branches: &RepoBranches, ancestor: &str) -> Vec<String> {
let result = std::process::Command::new("/usr/bin/git")
.current_dir(gitdir.to_path_buf())
.args([
"log",
"--oneline",
"--graph",
"--decorate",
format!("origin/{}", branches.main()).as_str(),
format!("origin/{}", branches.next()).as_str(),
format!("origin/{}", branches.dev()).as_str(),
])
.output();
if let Ok(output) = result {
return String::from_utf8_lossy(output.stdout.as_slice())
.split('\n')
.take_until(|line| line.starts_with(ancestor))
.map(ToOwned::to_owned)
.collect();
}
vec![]
}

View file

@ -6,7 +6,6 @@ pub mod forge;
mod generation;
mod git_ref;
mod git_remote;
pub mod graph;
pub mod push;
mod repo_details;
pub mod repository;

View file

@ -1,25 +1,25 @@
#[macro_export]
macro_rules! message {
($name:ident, $value:ty, $docs:literal) => {
git_next_core::newtype!($name, $value, $docs);
($name:ident: $value:ty: $docs:literal) => {
git_next_core::newtype!($name: $value: $docs);
impl actix::prelude::Message for $name {
type Result = ();
}
};
($name:ident, $docs:literal) => {
git_next_core::newtype!($name, $docs);
($name:ident: $docs:literal) => {
git_next_core::newtype!($name: $docs);
impl actix::prelude::Message for $name {
type Result = ();
}
};
($name:ident, $value:ty => $result:ty, $docs:literal) => {
git_next_core::newtype!($name, $value, $docs);
($name:ident: $value:ty => $result:ty: $docs:literal) => {
git_next_core::newtype!($name is a $value: $docs);
impl actix::prelude::Message for $name {
type Result = $result;
}
};
($name:ident => $result:ty, $docs:literal) => {
git_next_core::newtype!($name, $docs);
($name:ident => $result:ty: $docs:literal) => {
git_next_core::newtype!($name: $docs);
impl actix::prelude::Message for $name {
type Result = $result;
}

View file

@ -1,7 +1,7 @@
//
#[macro_export]
macro_rules! newtype {
($name:ident, $docs:literal) => {
($name:ident: $docs:literal) => {
#[doc = $docs]
#[derive(
Clone,
@ -20,7 +20,7 @@ macro_rules! newtype {
)]
pub struct $name;
};
($name:ident, $type:ty $(, $derive:ty)*, $docs:literal) => {
($name:ident: $type:ty $(, $derive:ty)*: $docs:literal) => {
#[doc = $docs]
#[derive(
Clone,