jinxapi_github/v1_1_4/request/
pulls_remove_requested_reviewers.rs

1//! Remove requested reviewers from a pull request
2//! 
3//! [API method documentation](https://docs.github.com/rest/reference/pulls#remove-requested-reviewers-from-a-pull-request)
4
5pub struct Content<Body>
6{
7    body: Body,
8    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
9}
10
11impl<Body> Content<Body> {
12    pub fn new(body: Body) -> Self {
13        Self { body, content_type_value: None }
14    }
15
16    #[must_use]
17    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
18        self.content_type_value = Some(content_type.into());
19        self
20    }
21
22    fn content_type(&self) -> Option<&[u8]> {
23        self.content_type_value.as_deref()
24    }
25
26    fn into_body(self) -> Body {
27        self.body
28    }
29}
30
31fn url_string(
32    base_url: &str,
33    p_owner: &str,
34    p_repo: &str,
35    p_pull_number: i64,
36) -> Result<String, crate::v1_1_4::ApiError> {
37    let trimmed = if base_url.is_empty() {
38        "https://api.github.com"
39    } else {
40        base_url.trim_end_matches('/')
41    };
42    let mut url = String::with_capacity(trimmed.len() + 54);
43    url.push_str(trimmed);
44    url.push_str("/repos/");
45    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
46    url.push('/');
47    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
48    url.push_str("/pulls/");
49    ::querylizer::Simple::extend(&mut url, &p_pull_number, false, &::querylizer::encode_path)?;
50    url.push_str("/requested_reviewers");
51    Ok(url)
52}
53
54#[cfg(feature = "hyper")]
55pub fn http_builder(
56    base_url: &str,
57    p_owner: &str,
58    p_repo: &str,
59    p_pull_number: i64,
60    h_user_agent: &str,
61    h_accept: ::std::option::Option<&str>,
62) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
63    let url = url_string(
64        base_url,
65        p_owner,
66        p_repo,
67        p_pull_number,
68    )?;
69    let mut builder = ::http::request::Request::delete(url);
70    builder = builder.header(
71        "User-Agent",
72        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
73    );
74    if let Some(value) = &h_accept {
75        builder = builder.header(
76            "Accept",
77            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
78        );
79    }
80    Ok(builder)
81}
82
83#[cfg(feature = "hyper")]
84pub fn hyper_request(
85    mut builder: ::http::request::Builder,
86    content: Content<::hyper::Body>,
87) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
88{
89    if let Some(content_type) = content.content_type() {
90        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
91    }
92    Ok(builder.body(content.into_body())?)
93}
94
95#[cfg(feature = "hyper")]
96impl From<::hyper::Body> for Content<::hyper::Body> {
97    fn from(body: ::hyper::Body) -> Self {
98        Self::new(body)
99    }
100}
101
102#[cfg(feature = "reqwest")]
103pub fn reqwest_builder(
104    base_url: &str,
105    p_owner: &str,
106    p_repo: &str,
107    p_pull_number: i64,
108    h_user_agent: &str,
109    h_accept: ::std::option::Option<&str>,
110) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
111    let url = url_string(
112        base_url,
113        p_owner,
114        p_repo,
115        p_pull_number,
116    )?;
117    let reqwest_url = ::reqwest::Url::parse(&url)?;
118    let mut request = ::reqwest::Request::new(::reqwest::Method::DELETE, reqwest_url);
119    let headers = request.headers_mut();
120    headers.append(
121        "User-Agent",
122        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
123    );
124    if let Some(value) = &h_accept {
125        headers.append(
126            "Accept",
127            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
128        );
129    }
130    Ok(request)
131}
132
133#[cfg(feature = "reqwest")]
134pub fn reqwest_request(
135    mut builder: ::reqwest::Request,
136    content: Content<::reqwest::Body>,
137) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
138    if let Some(content_type) = content.content_type() {
139        builder.headers_mut().append(
140            ::reqwest::header::HeaderName::from_static("content-type"),
141            ::reqwest::header::HeaderValue::try_from(content_type)?,
142        );
143    }
144    *builder.body_mut() = Some(content.into_body());
145    Ok(builder)
146}
147
148#[cfg(feature = "reqwest")]
149impl From<::reqwest::Body> for Content<::reqwest::Body> {
150    fn from(body: ::reqwest::Body) -> Self {
151        Self::new(body)
152    }
153}
154
155#[cfg(feature = "reqwest-blocking")]
156pub fn reqwest_blocking_builder(
157    base_url: &str,
158    p_owner: &str,
159    p_repo: &str,
160    p_pull_number: i64,
161    h_user_agent: &str,
162    h_accept: ::std::option::Option<&str>,
163) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
164    let url = url_string(
165        base_url,
166        p_owner,
167        p_repo,
168        p_pull_number,
169    )?;
170    let reqwest_url = ::reqwest::Url::parse(&url)?;
171    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::DELETE, reqwest_url);
172    let headers = request.headers_mut();
173    headers.append(
174        "User-Agent",
175        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
176    );
177    if let Some(value) = &h_accept {
178        headers.append(
179            "Accept",
180            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
181        );
182    }
183    Ok(request)
184}
185
186#[cfg(feature = "reqwest-blocking")]
187pub fn reqwest_blocking_request(
188    mut builder: ::reqwest::blocking::Request,
189    content: Content<::reqwest::blocking::Body>,
190) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
191    if let Some(content_type) = content.content_type() {
192        builder.headers_mut().append(
193            ::reqwest::header::HeaderName::from_static("content-type"),
194            ::reqwest::header::HeaderValue::try_from(content_type)?,
195        );
196    }
197    *builder.body_mut() = Some(content.into_body());
198    Ok(builder)
199}
200
201#[cfg(feature = "reqwest-blocking")]
202impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
203    fn from(body: ::reqwest::blocking::Body) -> Self {
204        Self::new(body)
205    }
206}
207
208/// Types for body parameter in [`super::pulls_remove_requested_reviewers`]
209pub mod body {
210    #[allow(non_snake_case)]
211    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
212    pub struct Json<'a> {
213        /// An array of user `login`s that will be removed.
214        pub reviewers: ::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>,
215
216        /// An array of team `slug`s that will be removed.
217        #[serde(skip_serializing_if = "Option::is_none", default)]
218        pub team_reviewers: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
219
220        #[serde(flatten)]
221        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
222    }
223
224    #[cfg(feature = "hyper")]
225    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
226        type Error = crate::v1_1_4::ApiError;
227
228        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
229            Ok(
230                Self::new(::serde_json::to_vec(value)?.into())
231                .with_content_type(&b"application/json"[..])
232            )
233        }
234    }
235
236    #[cfg(feature = "reqwest")]
237    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
238        type Error = crate::v1_1_4::ApiError;
239
240        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
241            Ok(
242                Self::new(::serde_json::to_vec(value)?.into())
243                .with_content_type(&b"application/json"[..])
244            )
245        }
246    }
247
248    #[cfg(feature = "reqwest-blocking")]
249    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
250        type Error = crate::v1_1_4::ApiError;
251
252        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
253            Ok(
254                Self::new(::serde_json::to_vec(value)?.into())
255                .with_content_type(&b"application/json"[..])
256            )
257        }
258    }
259}