Skip to main content

mesa_dev/client/
webhooks.rs

1use crate::low_level::apis::{webhooks_api, Error};
2use crate::models;
3
4use super::RepoClient;
5
6/// Client for webhook operations (`/{org}/{repo}/webhooks`).
7#[derive(Clone, Debug)]
8pub struct WebhooksClient<'a> {
9    pub(super) repo: &'a RepoClient<'a>,
10}
11
12impl WebhooksClient<'_> {
13    /// List webhooks for the repository.
14    ///
15    /// # Errors
16    ///
17    /// Returns an error if the API request fails.
18    pub async fn list(
19        &self,
20    ) -> Result<
21        models::GetByOrgByRepoWebhooks200Response,
22        Error<webhooks_api::GetByOrgByRepoWebhooksError>,
23    > {
24        webhooks_api::get_by_org_by_repo_webhooks(
25            self.repo.org.config,
26            self.repo.org.org,
27            self.repo.repo,
28        )
29        .await
30    }
31
32    /// Create a webhook.
33    ///
34    /// # Errors
35    ///
36    /// Returns an error if the API request fails.
37    pub async fn create(
38        &self,
39        request: models::PostByOrgByRepoWebhooksRequest,
40    ) -> Result<
41        models::PostByOrgByRepoWebhooks201Response,
42        Error<webhooks_api::PostByOrgByRepoWebhooksError>,
43    > {
44        webhooks_api::post_by_org_by_repo_webhooks(
45            self.repo.org.config,
46            self.repo.org.org,
47            self.repo.repo,
48            Some(request),
49        )
50        .await
51    }
52
53    /// Delete a webhook by its ID.
54    ///
55    /// # Errors
56    ///
57    /// Returns an error if the API request fails.
58    pub async fn delete(
59        &self,
60        webhook_id: &str,
61    ) -> Result<
62        models::DeleteByOrgApiKeysById200Response,
63        Error<webhooks_api::DeleteByOrgByRepoWebhooksByWebhookIdError>,
64    > {
65        webhooks_api::delete_by_org_by_repo_webhooks_by_webhook_id(
66            self.repo.org.config,
67            self.repo.org.org,
68            self.repo.repo,
69            webhook_id,
70        )
71        .await
72    }
73}