2024-06-19 07:03:08 +01:00
//
use derive_more ::Display ;
2024-07-25 09:02:43 +01:00
use git_next_core ::{
2024-07-28 08:58:32 +01:00
git ::{ forge ::commit ::Status , Commit , UserNotification } ,
message , newtype , ForgeNotification , RegisteredWebhook , RepoConfig , WebhookAuth , WebhookId ,
2024-07-25 09:02:43 +01:00
} ;
2024-06-29 14:56:20 +01:00
message! ( LoadConfigFromRepo : " Request to load the `git-next.toml` from the git repo. " ) ;
message! ( CloneRepo : " Request to clone (or open) the git repo. " ) ;
2024-07-25 09:02:43 +01:00
message! ( ReceiveRepoConfig : RepoConfig : r #" Notification that the `git-next.toml` file has been loaded from the repo and parsed.
2024-06-19 07:03:08 +01:00
2024-06-29 14:56:20 +01:00
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 . " #);
2024-07-25 09:02:43 +01:00
message! ( WebhookRegistered : ( WebhookId , WebhookAuth ) : r #" Notification that a webhook has been registered with a forge.
2024-06-29 14:56:20 +01:00
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 . " #);
2024-06-19 07:03:08 +01:00
impl WebhookRegistered {
2024-07-25 09:02:43 +01:00
pub const fn webhook_id ( & self ) -> & WebhookId {
2024-06-19 07:03:08 +01:00
& self . 0 . 0
}
2024-07-25 09:02:43 +01:00
pub const fn webhook_auth ( & self ) -> & WebhookAuth {
2024-06-19 07:03:08 +01:00
& self . 0 . 1
}
}
2024-07-25 09:02:43 +01:00
impl From < RegisteredWebhook > for WebhookRegistered {
fn from ( value : RegisteredWebhook ) -> Self {
2024-06-19 07:03:08 +01:00
let webhook_id = value . id ( ) . clone ( ) ;
let webhook_auth = value . auth ( ) . clone ( ) ;
Self ::from ( ( webhook_id , webhook_auth ) )
}
}
2024-07-15 07:39:06 +01:00
message! ( UnRegisterWebhook : " Request that the webhook be removed from the forge, so they will stop notifying us. " ) ;
2024-07-06 19:55:39 +01:00
newtype! ( MessageToken : u32 , Copy , Default , Display , PartialOrd , Ord : r #" An incremental token used to identify the current set of messages.
2024-06-29 14:56:20 +01:00
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 . " #);
2024-06-19 07:03:08 +01:00
impl MessageToken {
2024-08-05 07:39:38 +01:00
pub const fn next ( self ) -> Self {
2024-06-19 07:03:08 +01:00
Self ( self . 0 + 1 )
}
}
2024-06-29 14:56:20 +01:00
message! ( RegisterWebhook : " Requests that a Webhook be registered with the forge. " ) ;
2024-07-28 08:58:32 +01:00
message! ( CheckCIStatus : Commit : r #" Requests that the CI status for the commit be checked.
2024-06-29 14:56:20 +01:00
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
2024-07-28 08:58:32 +01:00
message! ( ReceiveCIStatus : ( Commit , Status ) : r #" Notification of the status of the CI checks for the commit.
2024-06-29 14:56:20 +01:00
Contains a tuple of the commit that was checked ( the tip of the ` next ` branch ) and the status . " #); // commit and it's status
2024-07-28 18:50:27 +01:00
#[ derive(Clone, Debug, PartialEq, Eq) ]
pub struct AdvanceNextPayload {
pub next : Commit ,
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
2024-07-28 08:58:32 +01:00
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. " ) ;
2024-07-19 19:41:20 +01:00
message! ( NotifyUser : UserNotification : " Request to send the message payload to the notification webhook " ) ;