1pub struct Content<Body>
12{
13 body: Body,
14 content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
15}
16
17impl<Body> Content<Body> {
18 pub fn new(body: Body) -> Self {
19 Self { body, content_type_value: None }
20 }
21
22 #[must_use]
23 pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
24 self.content_type_value = Some(content_type.into());
25 self
26 }
27
28 fn content_type(&self) -> Option<&[u8]> {
29 self.content_type_value.as_deref()
30 }
31
32 fn into_body(self) -> Body {
33 self.body
34 }
35}
36
37fn url_string(
38 base_url: &str,
39 p_owner: &str,
40 p_repo: &str,
41) -> Result<String, crate::v1_1_4::ApiError> {
42 let trimmed = if base_url.is_empty() {
43 "https://api.github.com"
44 } else {
45 base_url.trim_end_matches('/')
46 };
47 let mut url = String::with_capacity(trimmed.len() + 37);
48 url.push_str(trimmed);
49 url.push_str("/repos/");
50 ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
51 url.push('/');
52 ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
53 url.push_str("/check-runs");
54 Ok(url)
55}
56
57#[cfg(feature = "hyper")]
58pub fn http_builder(
59 base_url: &str,
60 p_owner: &str,
61 p_repo: &str,
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 )?;
70 let mut builder = ::http::request::Request::post(url);
71 builder = builder.header(
72 "User-Agent",
73 &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
74 );
75 if let Some(value) = &h_accept {
76 builder = builder.header(
77 "Accept",
78 &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
79 );
80 }
81 Ok(builder)
82}
83
84#[cfg(feature = "hyper")]
85pub fn hyper_request(
86 mut builder: ::http::request::Builder,
87 content: Content<::hyper::Body>,
88) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
89{
90 if let Some(content_type) = content.content_type() {
91 builder = builder.header(::http::header::CONTENT_TYPE, content_type);
92 }
93 Ok(builder.body(content.into_body())?)
94}
95
96#[cfg(feature = "hyper")]
97impl From<::hyper::Body> for Content<::hyper::Body> {
98 fn from(body: ::hyper::Body) -> Self {
99 Self::new(body)
100 }
101}
102
103#[cfg(feature = "reqwest")]
104pub fn reqwest_builder(
105 base_url: &str,
106 p_owner: &str,
107 p_repo: &str,
108 h_user_agent: &str,
109 h_accept: ::std::option::Option<&str>,
110) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
111 let url = url_string(
112 base_url,
113 p_owner,
114 p_repo,
115 )?;
116 let reqwest_url = ::reqwest::Url::parse(&url)?;
117 let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
118 let headers = request.headers_mut();
119 headers.append(
120 "User-Agent",
121 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
122 );
123 if let Some(value) = &h_accept {
124 headers.append(
125 "Accept",
126 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
127 );
128 }
129 Ok(request)
130}
131
132#[cfg(feature = "reqwest")]
133pub fn reqwest_request(
134 mut builder: ::reqwest::Request,
135 content: Content<::reqwest::Body>,
136) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
137 if let Some(content_type) = content.content_type() {
138 builder.headers_mut().append(
139 ::reqwest::header::HeaderName::from_static("content-type"),
140 ::reqwest::header::HeaderValue::try_from(content_type)?,
141 );
142 }
143 *builder.body_mut() = Some(content.into_body());
144 Ok(builder)
145}
146
147#[cfg(feature = "reqwest")]
148impl From<::reqwest::Body> for Content<::reqwest::Body> {
149 fn from(body: ::reqwest::Body) -> Self {
150 Self::new(body)
151 }
152}
153
154#[cfg(feature = "reqwest-blocking")]
155pub fn reqwest_blocking_builder(
156 base_url: &str,
157 p_owner: &str,
158 p_repo: &str,
159 h_user_agent: &str,
160 h_accept: ::std::option::Option<&str>,
161) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
162 let url = url_string(
163 base_url,
164 p_owner,
165 p_repo,
166 )?;
167 let reqwest_url = ::reqwest::Url::parse(&url)?;
168 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
169 let headers = request.headers_mut();
170 headers.append(
171 "User-Agent",
172 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
173 );
174 if let Some(value) = &h_accept {
175 headers.append(
176 "Accept",
177 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
178 );
179 }
180 Ok(request)
181}
182
183#[cfg(feature = "reqwest-blocking")]
184pub fn reqwest_blocking_request(
185 mut builder: ::reqwest::blocking::Request,
186 content: Content<::reqwest::blocking::Body>,
187) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
188 if let Some(content_type) = content.content_type() {
189 builder.headers_mut().append(
190 ::reqwest::header::HeaderName::from_static("content-type"),
191 ::reqwest::header::HeaderValue::try_from(content_type)?,
192 );
193 }
194 *builder.body_mut() = Some(content.into_body());
195 Ok(builder)
196}
197
198#[cfg(feature = "reqwest-blocking")]
199impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
200 fn from(body: ::reqwest::blocking::Body) -> Self {
201 Self::new(body)
202 }
203}
204
205pub mod body {
207 #[allow(non_snake_case)]
208 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
209 pub struct Json<'a> {
210 pub name: ::std::borrow::Cow<'a, str>,
212
213 pub head_sha: ::std::borrow::Cow<'a, str>,
215
216 #[serde(skip_serializing_if = "Option::is_none", default)]
218 pub details_url: ::std::option::Option<::std::borrow::Cow<'a, str>>,
219
220 #[serde(skip_serializing_if = "Option::is_none", default)]
222 pub external_id: ::std::option::Option<::std::borrow::Cow<'a, str>>,
223
224 #[serde(skip_serializing_if = "Option::is_none", default)]
226 pub status: ::std::option::Option<::std::borrow::Cow<'a, str>>,
227
228 #[serde(skip_serializing_if = "Option::is_none", default)]
230 pub started_at: ::std::option::Option<::std::borrow::Cow<'a, str>>,
231
232 #[serde(skip_serializing_if = "Option::is_none", default)]
235 pub conclusion: ::std::option::Option<::std::borrow::Cow<'a, str>>,
236
237 #[serde(skip_serializing_if = "Option::is_none", default)]
239 pub completed_at: ::std::option::Option<::std::borrow::Cow<'a, str>>,
240
241 #[serde(skip_serializing_if = "Option::is_none", default)]
242 pub output: ::std::option::Option<crate::v1_1_4::request::checks_create::body::json::Output<'a>>,
243
244 #[serde(skip_serializing_if = "Option::is_none", default)]
246 pub actions: ::std::option::Option<::std::borrow::Cow<'a, [crate::v1_1_4::request::checks_create::body::json::Actions<'a>]>>,
247
248 #[serde(flatten)]
249 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
250 }
251
252 pub mod json {
254 #[allow(non_snake_case)]
256 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
257 pub struct Output<'a> {
258 pub title: ::std::borrow::Cow<'a, str>,
260
261 pub summary: ::std::borrow::Cow<'a, str>,
263
264 #[serde(skip_serializing_if = "Option::is_none", default)]
266 pub text: ::std::option::Option<::std::borrow::Cow<'a, str>>,
267
268 #[serde(skip_serializing_if = "Option::is_none", default)]
270 pub annotations: ::std::option::Option<::std::borrow::Cow<'a, [crate::v1_1_4::request::checks_create::body::json::output::Annotations<'a>]>>,
271
272 #[serde(skip_serializing_if = "Option::is_none", default)]
274 pub images: ::std::option::Option<::std::borrow::Cow<'a, [crate::v1_1_4::request::checks_create::body::json::output::Images<'a>]>>,
275
276 #[serde(flatten)]
277 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
278 }
279
280 pub mod output {
282 #[allow(non_snake_case)]
283 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
284 pub struct Annotations<'a> {
285 pub path: ::std::borrow::Cow<'a, str>,
287
288 pub start_line: i64,
290
291 pub end_line: i64,
293
294 #[serde(skip_serializing_if = "Option::is_none", default)]
296 pub start_column: ::std::option::Option<i64>,
297
298 #[serde(skip_serializing_if = "Option::is_none", default)]
300 pub end_column: ::std::option::Option<i64>,
301
302 pub annotation_level: ::std::borrow::Cow<'a, str>,
304
305 pub message: ::std::borrow::Cow<'a, str>,
307
308 #[serde(skip_serializing_if = "Option::is_none", default)]
310 pub title: ::std::option::Option<::std::borrow::Cow<'a, str>>,
311
312 #[serde(skip_serializing_if = "Option::is_none", default)]
314 pub raw_details: ::std::option::Option<::std::borrow::Cow<'a, str>>,
315
316 #[serde(flatten)]
317 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
318 }
319
320 #[allow(non_snake_case)]
321 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
322 pub struct Images<'a> {
323 pub alt: ::std::borrow::Cow<'a, str>,
325
326 pub image_url: ::std::borrow::Cow<'a, str>,
328
329 #[serde(skip_serializing_if = "Option::is_none", default)]
331 pub caption: ::std::option::Option<::std::borrow::Cow<'a, str>>,
332
333 #[serde(flatten)]
334 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
335 }
336 }
337
338 #[allow(non_snake_case)]
339 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
340 pub struct Actions<'a> {
341 pub label: ::std::borrow::Cow<'a, str>,
343
344 pub description: ::std::borrow::Cow<'a, str>,
346
347 pub identifier: ::std::borrow::Cow<'a, str>,
349
350 #[serde(flatten)]
351 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
352 }
353 }
354
355 #[cfg(feature = "hyper")]
356 impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
357 type Error = crate::v1_1_4::ApiError;
358
359 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
360 Ok(
361 Self::new(::serde_json::to_vec(value)?.into())
362 .with_content_type(&b"application/json"[..])
363 )
364 }
365 }
366
367 #[cfg(feature = "reqwest")]
368 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
369 type Error = crate::v1_1_4::ApiError;
370
371 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
372 Ok(
373 Self::new(::serde_json::to_vec(value)?.into())
374 .with_content_type(&b"application/json"[..])
375 )
376 }
377 }
378
379 #[cfg(feature = "reqwest-blocking")]
380 impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
381 type Error = crate::v1_1_4::ApiError;
382
383 fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
384 Ok(
385 Self::new(::serde_json::to_vec(value)?.into())
386 .with_content_type(&b"application/json"[..])
387 )
388 }
389 }
390}