git_next_core/git/forge/
trait.rs

1//
2use crate::{
3    git, server::RepoListenUrl, webhook, ForgeNotification, RegisteredWebhook, WebhookAuth,
4    WebhookId,
5};
6
7#[mockall::automock]
8#[async_trait::async_trait]
9pub trait ForgeLike: std::fmt::Debug + Send + Sync {
10    fn duplicate(&self) -> Box<dyn ForgeLike>;
11    fn name(&self) -> String;
12
13    /// Checks that the message has a valid authorisation.
14    fn is_message_authorised(&self, message: &ForgeNotification, expected: &WebhookAuth) -> bool;
15
16    /// Checks if the message should be ignored.
17    ///
18    /// Default implementation says that no messages should be ignored.
19    #[allow(unused_variables)]
20    fn should_ignore_message(&self, message: &ForgeNotification) -> bool {
21        false
22    }
23
24    /// Parses the webhook body into Some(Push) struct if appropriate, or None if not.
25    ///
26    /// # Errors
27    ///
28    /// Will return an `Err` if the body is not a message in the expected format.
29    fn parse_webhook_body(
30        &self,
31        body: &webhook::forge_notification::Body,
32    ) -> git::forge::webhook::Result<webhook::push::Push>;
33
34    /// Checks the results of any (e.g. CI) status checks for the commit.
35    async fn commit_status(
36        &self,
37        commit: &git::Commit,
38    ) -> git::forge::webhook::Result<git::forge::commit::Status>;
39
40    // Lists all the webhooks
41    async fn list_webhooks(
42        &self,
43        repo_listen_url: &RepoListenUrl,
44    ) -> git::forge::webhook::Result<Vec<WebhookId>>;
45
46    // Unregisters a webhook
47    async fn unregister_webhook(&self, webhook: &WebhookId) -> git::forge::webhook::Result<()>;
48
49    // Registers a webhook
50    async fn register_webhook(
51        &self,
52        repo_listen_url: &RepoListenUrl,
53    ) -> git::forge::webhook::Result<RegisteredWebhook>;
54}