jinxapi_github/v1_1_4/request/
pulls_request_reviewers.rs

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