jinxapi_github/v1_1_4/request/
git_create_commit.rs1pub struct Content<Body>
37{
38 body: Body,
39 content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
40}
41
42impl<Body> Content<Body> {
43 pub fn new(body: Body) -> Self {
44 Self { body, content_type_value: None }
45 }
46
47 #[must_use]
48 pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
49 self.content_type_value = Some(content_type.into());
50 self
51 }
52
53 fn content_type(&self) -> Option<&[u8]> {
54 self.content_type_value.as_deref()
55 }
56
57 fn into_body(self) -> Body {
58 self.body
59 }
60}
61
62fn url_string(
63 base_url: &str,
64 p_owner: &str,
65 p_repo: &str,
66) -> Result<String, crate::v1_1_4::ApiError> {
67 let trimmed = if base_url.is_empty() {
68 "https://api.github.com"
69 } else {
70 base_url.trim_end_matches('/')
71 };
72 let mut url = String::with_capacity(trimmed.len() + 38);
73 url.push_str(trimmed);
74 url.push_str("/repos/");
75 ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
76 url.push('/');
77 ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
78 url.push_str("/git/commits");
79 Ok(url)
80}
81
82#[cfg(feature = "hyper")]
83pub fn http_builder(
84 base_url: &str,
85 p_owner: &str,
86 p_repo: &str,
87 h_user_agent: &str,
88 h_accept: ::std::option::Option<&str>,
89) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
90 let url = url_string(
91 base_url,
92 p_owner,
93 p_repo,
94 )?;
95 let mut builder = ::http::request::Request::post(url);
96 builder = builder.header(
97 "User-Agent",
98 &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
99 );
100 if let Some(value) = &h_accept {
101 builder = builder.header(
102 "Accept",
103 &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
104 );
105 }
106 Ok(builder)
107}
108
109#[cfg(feature = "hyper")]
110pub fn hyper_request(
111 mut builder: ::http::request::Builder,
112 content: Content<::hyper::Body>,
113) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
114{
115 if let Some(content_type) = content.content_type() {
116 builder = builder.header(::http::header::CONTENT_TYPE, content_type);
117 }
118 Ok(builder.body(content.into_body())?)
119}
120
121#[cfg(feature = "hyper")]
122impl From<::hyper::Body> for Content<::hyper::Body> {
123 fn from(body: ::hyper::Body) -> Self {
124 Self::new(body)
125 }
126}
127
128#[cfg(feature = "reqwest")]
129pub fn reqwest_builder(
130 base_url: &str,
131 p_owner: &str,
132 p_repo: &str,
133 h_user_agent: &str,
134 h_accept: ::std::option::Option<&str>,
135) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
136 let url = url_string(
137 base_url,
138 p_owner,
139 p_repo,
140 )?;
141 let reqwest_url = ::reqwest::Url::parse(&url)?;
142 let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
143 let headers = request.headers_mut();
144 headers.append(
145 "User-Agent",
146 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
147 );
148 if let Some(value) = &h_accept {
149 headers.append(
150 "Accept",
151 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
152 );
153 }
154 Ok(request)
155}
156
157#[cfg(feature = "reqwest")]
158pub fn reqwest_request(
159 mut builder: ::reqwest::Request,
160 content: Content<::reqwest::Body>,
161) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
162 if let Some(content_type) = content.content_type() {
163 builder.headers_mut().append(
164 ::reqwest::header::HeaderName::from_static("content-type"),
165 ::reqwest::header::HeaderValue::try_from(content_type)?,
166 );
167 }
168 *builder.body_mut() = Some(content.into_body());
169 Ok(builder)
170}
171
172#[cfg(feature = "reqwest")]
173impl From<::reqwest::Body> for Content<::reqwest::Body> {
174 fn from(body: ::reqwest::Body) -> Self {
175 Self::new(body)
176 }
177}
178
179#[cfg(feature = "reqwest-blocking")]
180pub fn reqwest_blocking_builder(
181 base_url: &str,
182 p_owner: &str,
183 p_repo: &str,
184 h_user_agent: &str,
185 h_accept: ::std::option::Option<&str>,
186) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
187 let url = url_string(
188 base_url,
189 p_owner,
190 p_repo,
191 )?;
192 let reqwest_url = ::reqwest::Url::parse(&url)?;
193 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
194 let headers = request.headers_mut();
195 headers.append(
196 "User-Agent",
197 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
198 );
199 if let Some(value) = &h_accept {
200 headers.append(
201 "Accept",
202 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
203 );
204 }
205 Ok(request)
206}
207
208#[cfg(feature = "reqwest-blocking")]
209pub fn reqwest_blocking_request(
210 mut builder: ::reqwest::blocking::Request,
211 content: Content<::reqwest::blocking::Body>,
212) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
213 if let Some(content_type) = content.content_type() {
214 builder.headers_mut().append(
215 ::reqwest::header::HeaderName::from_static("content-type"),
216 ::reqwest::header::HeaderValue::try_from(content_type)?,
217 );
218 }
219 *builder.body_mut() = Some(content.into_body());
220 Ok(builder)
221}
222
223#[cfg(feature = "reqwest-blocking")]
224impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
225 fn from(body: ::reqwest::blocking::Body) -> Self {
226 Self::new(body)
227 }
228}
229
230pub mod body {
232 #[allow(non_snake_case)]
233 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
234 pub struct Json<'a> {
235 pub message: ::std::borrow::Cow<'a, str>,
237
238 pub tree: ::std::borrow::Cow<'a, str>,
240
241 #[serde(skip_serializing_if = "Option::is_none", default)]
243 pub parents: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
244
245 #[serde(skip_serializing_if = "Option::is_none", default)]
246 pub author: ::std::option::Option<crate::v1_1_4::request::git_create_commit::body::json::Author<'a>>,
247
248 #[serde(skip_serializing_if = "Option::is_none", default)]
249 pub committer: ::std::option::Option<crate::v1_1_4::request::git_create_commit::body::json::Committer<'a>>,
250
251 #[serde(skip_serializing_if = "Option::is_none", default)]
253 pub signature: ::std::option::Option<::std::borrow::Cow<'a, str>>,
254
255 #[serde(flatten)]
256 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
257 }
258
259 pub mod json {
261 #[allow(non_snake_case)]
263 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
264 pub struct Author<'a> {
265 pub name: ::std::borrow::Cow<'a, str>,
267
268 pub email: ::std::borrow::Cow<'a, str>,
270
271 #[serde(skip_serializing_if = "Option::is_none", default)]
273 pub date: ::std::option::Option<::std::borrow::Cow<'a, str>>,
274
275 #[serde(flatten)]
276 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
277 }
278
279 #[allow(non_snake_case)]
281 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
282 pub struct Committer<'a> {
283 #[serde(skip_serializing_if = "Option::is_none", default)]
285 pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
286
287 #[serde(skip_serializing_if = "Option::is_none", default)]
289 pub email: ::std::option::Option<::std::borrow::Cow<'a, str>>,
290
291 #[serde(skip_serializing_if = "Option::is_none", default)]
293 pub date: ::std::option::Option<::std::borrow::Cow<'a, str>>,
294
295 #[serde(flatten)]
296 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
297 }
298 }
299
300 #[cfg(feature = "hyper")]
301 impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
302 type Error = crate::v1_1_4::ApiError;
303
304 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
305 Ok(
306 Self::new(::serde_json::to_vec(value)?.into())
307 .with_content_type(&b"application/json"[..])
308 )
309 }
310 }
311
312 #[cfg(feature = "reqwest")]
313 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
314 type Error = crate::v1_1_4::ApiError;
315
316 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
317 Ok(
318 Self::new(::serde_json::to_vec(value)?.into())
319 .with_content_type(&b"application/json"[..])
320 )
321 }
322 }
323
324 #[cfg(feature = "reqwest-blocking")]
325 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
326 type Error = crate::v1_1_4::ApiError;
327
328 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
329 Ok(
330 Self::new(::serde_json::to_vec(value)?.into())
331 .with_content_type(&b"application/json"[..])
332 )
333 }
334 }
335}