Skip to main content

gitlab/api/projects/hooks/
hooks.rs

1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7use derive_builder::Builder;
8
9use crate::api::common::NameOrId;
10use crate::api::endpoint_prelude::*;
11
12/// Query for webhooks within a project.
13#[derive(Debug, Builder, Clone)]
14pub struct Hooks<'a> {
15    /// The project to query for webhooks.
16    #[builder(setter(into))]
17    project: NameOrId<'a>,
18}
19
20impl<'a> Hooks<'a> {
21    /// Create a builder for the endpoint.
22    pub fn builder() -> HooksBuilder<'a> {
23        HooksBuilder::default()
24    }
25}
26
27impl Endpoint for Hooks<'_> {
28    fn method(&self) -> Method {
29        Method::GET
30    }
31
32    fn endpoint(&self) -> Cow<'static, str> {
33        format!("projects/{}/hooks", self.project).into()
34    }
35}
36
37impl Pageable for Hooks<'_> {}
38
39#[cfg(test)]
40mod tests {
41    use crate::api::projects::hooks::{Hooks, HooksBuilderError};
42    use crate::api::{self, Query};
43    use crate::test::client::{ExpectedUrl, SingleTestClient};
44
45    #[test]
46    fn project_is_needed() {
47        let err = Hooks::builder().build().unwrap_err();
48        crate::test::assert_missing_field!(err, HooksBuilderError, "project");
49    }
50
51    #[test]
52    fn project_is_sufficient() {
53        Hooks::builder().project(1).build().unwrap();
54    }
55
56    #[test]
57    fn endpoint() {
58        let endpoint = ExpectedUrl::builder()
59            .endpoint("projects/simple%2Fproject/hooks")
60            .build()
61            .unwrap();
62        let client = SingleTestClient::new_raw(endpoint, "");
63
64        let endpoint = Hooks::builder().project("simple/project").build().unwrap();
65        api::ignore(endpoint).query(&client).unwrap();
66    }
67}