Skip to main content

ephemeris_forge_github/api/http/
webhooks.rs

1use ephemeris_forge::{RepoRef, encode};
2use reqwest::Method;
3
4use crate::api::HttpApi;
5use crate::api::error::ForgeError;
6use crate::api::model::Webhook;
7use crate::api::operations::WebhooksApi;
8use crate::api::request::{WebhookBody, WebhookPatch};
9
10impl WebhooksApi for HttpApi {
11    async fn create_webhook(
12        &self,
13        repository: &RepoRef,
14        webhook: &WebhookBody,
15    ) -> Result<(), ForgeError> {
16        self.empty(Method::POST, &path(repository), Some(encode(webhook)))
17            .await
18    }
19
20    async fn delete_webhook(&self, repository: &RepoRef, id: u64) -> Result<(), ForgeError> {
21        self.empty(Method::DELETE, &format!("{}/{id}", path(repository)), None)
22            .await
23    }
24
25    async fn update_webhook(
26        &self,
27        repository: &RepoRef,
28        id: u64,
29        webhook: &WebhookPatch,
30    ) -> Result<(), ForgeError> {
31        self.empty(
32            Method::PATCH,
33            &format!("{}/{id}", path(repository)),
34            Some(encode(webhook)),
35        )
36        .await
37    }
38
39    async fn webhooks(&self, repository: &RepoRef) -> Result<Vec<Webhook>, ForgeError> {
40        let route = path(repository);
41        self.paged(&route).await
42    }
43}
44
45fn path(repository: &RepoRef) -> String {
46    repository.path("hooks")
47}