jinxapi_github/v1_1_4/request/
checks_create_suite.rs

1//! Create a check suite
2//! 
3//! **Note:** The Checks API only looks for pushes in the repository where the check suite or check run were created. Pushes to a branch in a forked repository are not detected and return an empty `pull_requests` array and a `null` value for `head_branch`.
4//! 
5//! By default, check suites are automatically created when you create a [check run](https://docs.github.com/rest/reference/checks#check-runs). You only need to use this endpoint for manually creating check suites when you've disabled automatic creation using "[Update repository preferences for check suites](https://docs.github.com/rest/reference/checks#update-repository-preferences-for-check-suites)". Your GitHub App must have the `checks:write` permission to create check suites.
6//! 
7//! [API method documentation](https://docs.github.com/rest/reference/checks#create-a-check-suite)
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) -> 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() + 39);
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("/check-suites");
52    Ok(url)
53}
54
55#[cfg(feature = "hyper")]
56pub fn http_builder(
57    base_url: &str,
58    p_owner: &str,
59    p_repo: &str,
60    h_user_agent: &str,
61    h_accept: ::std::option::Option<&str>,
62) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
63    let url = url_string(
64        base_url,
65        p_owner,
66        p_repo,
67    )?;
68    let mut builder = ::http::request::Request::post(url);
69    builder = builder.header(
70        "User-Agent",
71        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
72    );
73    if let Some(value) = &h_accept {
74        builder = builder.header(
75            "Accept",
76            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
77        );
78    }
79    Ok(builder)
80}
81
82#[cfg(feature = "hyper")]
83pub fn hyper_request(
84    mut builder: ::http::request::Builder,
85    content: Content<::hyper::Body>,
86) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
87{
88    if let Some(content_type) = content.content_type() {
89        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
90    }
91    Ok(builder.body(content.into_body())?)
92}
93
94#[cfg(feature = "hyper")]
95impl From<::hyper::Body> for Content<::hyper::Body> {
96    fn from(body: ::hyper::Body) -> Self {
97        Self::new(body)
98    }
99}
100
101#[cfg(feature = "reqwest")]
102pub fn reqwest_builder(
103    base_url: &str,
104    p_owner: &str,
105    p_repo: &str,
106    h_user_agent: &str,
107    h_accept: ::std::option::Option<&str>,
108) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
109    let url = url_string(
110        base_url,
111        p_owner,
112        p_repo,
113    )?;
114    let reqwest_url = ::reqwest::Url::parse(&url)?;
115    let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
116    let headers = request.headers_mut();
117    headers.append(
118        "User-Agent",
119        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
120    );
121    if let Some(value) = &h_accept {
122        headers.append(
123            "Accept",
124            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
125        );
126    }
127    Ok(request)
128}
129
130#[cfg(feature = "reqwest")]
131pub fn reqwest_request(
132    mut builder: ::reqwest::Request,
133    content: Content<::reqwest::Body>,
134) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
135    if let Some(content_type) = content.content_type() {
136        builder.headers_mut().append(
137            ::reqwest::header::HeaderName::from_static("content-type"),
138            ::reqwest::header::HeaderValue::try_from(content_type)?,
139        );
140    }
141    *builder.body_mut() = Some(content.into_body());
142    Ok(builder)
143}
144
145#[cfg(feature = "reqwest")]
146impl From<::reqwest::Body> for Content<::reqwest::Body> {
147    fn from(body: ::reqwest::Body) -> Self {
148        Self::new(body)
149    }
150}
151
152#[cfg(feature = "reqwest-blocking")]
153pub fn reqwest_blocking_builder(
154    base_url: &str,
155    p_owner: &str,
156    p_repo: &str,
157    h_user_agent: &str,
158    h_accept: ::std::option::Option<&str>,
159) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
160    let url = url_string(
161        base_url,
162        p_owner,
163        p_repo,
164    )?;
165    let reqwest_url = ::reqwest::Url::parse(&url)?;
166    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
167    let headers = request.headers_mut();
168    headers.append(
169        "User-Agent",
170        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
171    );
172    if let Some(value) = &h_accept {
173        headers.append(
174            "Accept",
175            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
176        );
177    }
178    Ok(request)
179}
180
181#[cfg(feature = "reqwest-blocking")]
182pub fn reqwest_blocking_request(
183    mut builder: ::reqwest::blocking::Request,
184    content: Content<::reqwest::blocking::Body>,
185) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
186    if let Some(content_type) = content.content_type() {
187        builder.headers_mut().append(
188            ::reqwest::header::HeaderName::from_static("content-type"),
189            ::reqwest::header::HeaderValue::try_from(content_type)?,
190        );
191    }
192    *builder.body_mut() = Some(content.into_body());
193    Ok(builder)
194}
195
196#[cfg(feature = "reqwest-blocking")]
197impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
198    fn from(body: ::reqwest::blocking::Body) -> Self {
199        Self::new(body)
200    }
201}
202
203/// Types for body parameter in [`super::checks_create_suite`]
204pub mod body {
205    #[allow(non_snake_case)]
206    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
207    pub struct Json<'a> {
208        /// The sha of the head commit.
209        pub head_sha: ::std::borrow::Cow<'a, str>,
210
211        #[serde(flatten)]
212        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
213    }
214
215    #[cfg(feature = "hyper")]
216    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
217        type Error = crate::v1_1_4::ApiError;
218
219        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
220            Ok(
221                Self::new(::serde_json::to_vec(value)?.into())
222                .with_content_type(&b"application/json"[..])
223            )
224        }
225    }
226
227    #[cfg(feature = "reqwest")]
228    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
229        type Error = crate::v1_1_4::ApiError;
230
231        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
232            Ok(
233                Self::new(::serde_json::to_vec(value)?.into())
234                .with_content_type(&b"application/json"[..])
235            )
236        }
237    }
238
239    #[cfg(feature = "reqwest-blocking")]
240    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
241        type Error = crate::v1_1_4::ApiError;
242
243        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
244            Ok(
245                Self::new(::serde_json::to_vec(value)?.into())
246                .with_content_type(&b"application/json"[..])
247            )
248        }
249    }
250}