jinxapi_github/v1_1_4/request/
pulls_create.rs1pub struct Content<Body>
14{
15 body: Body,
16 content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
17}
18
19impl<Body> Content<Body> {
20 pub fn new(body: Body) -> Self {
21 Self { body, content_type_value: None }
22 }
23
24 #[must_use]
25 pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
26 self.content_type_value = Some(content_type.into());
27 self
28 }
29
30 fn content_type(&self) -> Option<&[u8]> {
31 self.content_type_value.as_deref()
32 }
33
34 fn into_body(self) -> Body {
35 self.body
36 }
37}
38
39fn url_string(
40 base_url: &str,
41 p_owner: &str,
42 p_repo: &str,
43) -> Result<String, crate::v1_1_4::ApiError> {
44 let trimmed = if base_url.is_empty() {
45 "https://api.github.com"
46 } else {
47 base_url.trim_end_matches('/')
48 };
49 let mut url = String::with_capacity(trimmed.len() + 32);
50 url.push_str(trimmed);
51 url.push_str("/repos/");
52 ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
53 url.push('/');
54 ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
55 url.push_str("/pulls");
56 Ok(url)
57}
58
59#[cfg(feature = "hyper")]
60pub fn http_builder(
61 base_url: &str,
62 p_owner: &str,
63 p_repo: &str,
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 )?;
72 let mut builder = ::http::request::Request::post(url);
73 builder = builder.header(
74 "User-Agent",
75 &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
76 );
77 if let Some(value) = &h_accept {
78 builder = builder.header(
79 "Accept",
80 &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
81 );
82 }
83 Ok(builder)
84}
85
86#[cfg(feature = "hyper")]
87pub fn hyper_request(
88 mut builder: ::http::request::Builder,
89 content: Content<::hyper::Body>,
90) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
91{
92 if let Some(content_type) = content.content_type() {
93 builder = builder.header(::http::header::CONTENT_TYPE, content_type);
94 }
95 Ok(builder.body(content.into_body())?)
96}
97
98#[cfg(feature = "hyper")]
99impl From<::hyper::Body> for Content<::hyper::Body> {
100 fn from(body: ::hyper::Body) -> Self {
101 Self::new(body)
102 }
103}
104
105#[cfg(feature = "reqwest")]
106pub fn reqwest_builder(
107 base_url: &str,
108 p_owner: &str,
109 p_repo: &str,
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 )?;
118 let reqwest_url = ::reqwest::Url::parse(&url)?;
119 let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
120 let headers = request.headers_mut();
121 headers.append(
122 "User-Agent",
123 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
124 );
125 if let Some(value) = &h_accept {
126 headers.append(
127 "Accept",
128 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
129 );
130 }
131 Ok(request)
132}
133
134#[cfg(feature = "reqwest")]
135pub fn reqwest_request(
136 mut builder: ::reqwest::Request,
137 content: Content<::reqwest::Body>,
138) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
139 if let Some(content_type) = content.content_type() {
140 builder.headers_mut().append(
141 ::reqwest::header::HeaderName::from_static("content-type"),
142 ::reqwest::header::HeaderValue::try_from(content_type)?,
143 );
144 }
145 *builder.body_mut() = Some(content.into_body());
146 Ok(builder)
147}
148
149#[cfg(feature = "reqwest")]
150impl From<::reqwest::Body> for Content<::reqwest::Body> {
151 fn from(body: ::reqwest::Body) -> Self {
152 Self::new(body)
153 }
154}
155
156#[cfg(feature = "reqwest-blocking")]
157pub fn reqwest_blocking_builder(
158 base_url: &str,
159 p_owner: &str,
160 p_repo: &str,
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 )?;
169 let reqwest_url = ::reqwest::Url::parse(&url)?;
170 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
171 let headers = request.headers_mut();
172 headers.append(
173 "User-Agent",
174 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
175 );
176 if let Some(value) = &h_accept {
177 headers.append(
178 "Accept",
179 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
180 );
181 }
182 Ok(request)
183}
184
185#[cfg(feature = "reqwest-blocking")]
186pub fn reqwest_blocking_request(
187 mut builder: ::reqwest::blocking::Request,
188 content: Content<::reqwest::blocking::Body>,
189) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
190 if let Some(content_type) = content.content_type() {
191 builder.headers_mut().append(
192 ::reqwest::header::HeaderName::from_static("content-type"),
193 ::reqwest::header::HeaderValue::try_from(content_type)?,
194 );
195 }
196 *builder.body_mut() = Some(content.into_body());
197 Ok(builder)
198}
199
200#[cfg(feature = "reqwest-blocking")]
201impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
202 fn from(body: ::reqwest::blocking::Body) -> Self {
203 Self::new(body)
204 }
205}
206
207pub mod body {
209 #[allow(non_snake_case)]
210 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
211 pub struct Json<'a> {
212 #[serde(skip_serializing_if = "Option::is_none", default)]
214 pub title: ::std::option::Option<::std::borrow::Cow<'a, str>>,
215
216 pub head: ::std::borrow::Cow<'a, str>,
218
219 pub base: ::std::borrow::Cow<'a, str>,
221
222 #[serde(skip_serializing_if = "Option::is_none", default)]
224 pub body: ::std::option::Option<::std::borrow::Cow<'a, str>>,
225
226 #[serde(skip_serializing_if = "Option::is_none", default)]
228 pub maintainer_can_modify: ::std::option::Option<bool>,
229
230 #[serde(skip_serializing_if = "Option::is_none", default)]
232 pub draft: ::std::option::Option<bool>,
233
234 #[serde(skip_serializing_if = "Option::is_none", default)]
240 pub issue: ::std::option::Option<i64>,
241
242 #[serde(flatten)]
243 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
244 }
245
246 #[cfg(feature = "hyper")]
247 impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
248 type Error = crate::v1_1_4::ApiError;
249
250 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
251 Ok(
252 Self::new(::serde_json::to_vec(value)?.into())
253 .with_content_type(&b"application/json"[..])
254 )
255 }
256 }
257
258 #[cfg(feature = "reqwest")]
259 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
260 type Error = crate::v1_1_4::ApiError;
261
262 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
263 Ok(
264 Self::new(::serde_json::to_vec(value)?.into())
265 .with_content_type(&b"application/json"[..])
266 )
267 }
268 }
269
270 #[cfg(feature = "reqwest-blocking")]
271 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
272 type Error = crate::v1_1_4::ApiError;
273
274 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
275 Ok(
276 Self::new(::serde_json::to_vec(value)?.into())
277 .with_content_type(&b"application/json"[..])
278 )
279 }
280 }
281}