jinxapi_github/v1_1_4/request/
issues_lock.rs

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