jinxapi_github/v1_1_4/request/
pulls_update_review.rs

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