Skip to main content

gitlab/api/projects/releases/links/
links.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 crate::api::common::{self, NameOrId};
8use crate::api::endpoint_prelude::*;
9use derive_builder::Builder;
10
11/// Get assets as links from a release.
12#[derive(Debug, Builder, Clone)]
13pub struct ListReleaseLinks<'a> {
14    /// The project to query for the packages.
15    #[builder(setter(into))]
16    project: NameOrId<'a>,
17
18    /// The tag associated with the Release.
19    #[builder(setter(into))]
20    tag_name: Cow<'a, str>,
21}
22
23impl<'a> ListReleaseLinks<'a> {
24    /// Create a builder for the endpoint.
25    pub fn builder() -> ListReleaseLinksBuilder<'a> {
26        ListReleaseLinksBuilder::default()
27    }
28}
29
30impl Endpoint for ListReleaseLinks<'_> {
31    fn method(&self) -> Method {
32        Method::GET
33    }
34
35    fn endpoint(&self) -> Cow<'static, str> {
36        format!(
37            "projects/{}/releases/{}/assets/links",
38            self.project,
39            common::path_escaped(self.tag_name.as_ref()),
40        )
41        .into()
42    }
43}
44
45impl Pageable for ListReleaseLinks<'_> {}
46
47#[cfg(test)]
48mod tests {
49    use http::Method;
50
51    use crate::{
52        api::{self, projects::releases::links::ListReleaseLinksBuilderError, Query},
53        test::client::{ExpectedUrl, SingleTestClient},
54    };
55
56    use super::ListReleaseLinks;
57
58    #[test]
59    fn project_is_needed() {
60        let err = ListReleaseLinks::builder()
61            .tag_name("1.2.3")
62            .build()
63            .unwrap_err();
64
65        crate::test::assert_missing_field!(err, ListReleaseLinksBuilderError, "project");
66    }
67
68    #[test]
69    fn tag_name_is_needed() {
70        let err = ListReleaseLinks::builder().project(1).build().unwrap_err();
71
72        crate::test::assert_missing_field!(err, ListReleaseLinksBuilderError, "tag_name");
73    }
74
75    #[test]
76    fn required_parameter_are_sufficient() {
77        ListReleaseLinks::builder()
78            .project(1)
79            .tag_name("1.2.3")
80            .build()
81            .unwrap();
82    }
83
84    #[test]
85    fn endpoint() {
86        let endpoint = ExpectedUrl::builder()
87            .method(Method::GET)
88            .endpoint("projects/1337/releases/1.2.3%2001/assets/links")
89            .build()
90            .unwrap();
91        let client = SingleTestClient::new_raw(endpoint, "");
92
93        let endpoint = ListReleaseLinks::builder()
94            .project(1337)
95            .tag_name("1.2.3 01")
96            .build()
97            .unwrap();
98        api::ignore(endpoint).query(&client).unwrap();
99    }
100}