jinxapi_github/v1_1_4/request/
repos_remove_status_check_contexts.rs

1//! Remove status check contexts
2//! 
3//! Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see [GitHub's products](https://docs.github.com/github/getting-started-with-github/githubs-products) in the GitHub Help documentation.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/repos#remove-status-check-contexts)
6
7pub struct Content<Body>
8{
9    body: Body,
10    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
11}
12
13impl<Body> Content<Body> {
14    pub fn new(body: Body) -> Self {
15        Self { body, content_type_value: None }
16    }
17
18    #[must_use]
19    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
20        self.content_type_value = Some(content_type.into());
21        self
22    }
23
24    fn content_type(&self) -> Option<&[u8]> {
25        self.content_type_value.as_deref()
26    }
27
28    fn into_body(self) -> Body {
29        self.body
30    }
31}
32
33fn url_string(
34    base_url: &str,
35    p_owner: &str,
36    p_repo: &str,
37    p_branch: &str,
38) -> Result<String, crate::v1_1_4::ApiError> {
39    let trimmed = if base_url.is_empty() {
40        "https://api.github.com"
41    } else {
42        base_url.trim_end_matches('/')
43    };
44    let mut url = String::with_capacity(trimmed.len() + 80);
45    url.push_str(trimmed);
46    url.push_str("/repos/");
47    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
48    url.push('/');
49    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
50    url.push_str("/branches/");
51    ::querylizer::Simple::extend(&mut url, &p_branch, false, &::querylizer::encode_path)?;
52    url.push_str("/protection/required_status_checks/contexts");
53    Ok(url)
54}
55
56#[cfg(feature = "hyper")]
57pub fn http_builder(
58    base_url: &str,
59    p_owner: &str,
60    p_repo: &str,
61    p_branch: &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        p_branch,
70    )?;
71    let mut builder = ::http::request::Request::delete(url);
72    builder = builder.header(
73        "User-Agent",
74        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
75    );
76    if let Some(value) = &h_accept {
77        builder = builder.header(
78            "Accept",
79            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
80        );
81    }
82    Ok(builder)
83}
84
85#[cfg(feature = "hyper")]
86pub fn hyper_request(
87    mut builder: ::http::request::Builder,
88    content: Content<::hyper::Body>,
89) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
90{
91    if let Some(content_type) = content.content_type() {
92        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
93    }
94    Ok(builder.body(content.into_body())?)
95}
96
97#[cfg(feature = "hyper")]
98impl From<::hyper::Body> for Content<::hyper::Body> {
99    fn from(body: ::hyper::Body) -> Self {
100        Self::new(body)
101    }
102}
103
104#[cfg(feature = "reqwest")]
105pub fn reqwest_builder(
106    base_url: &str,
107    p_owner: &str,
108    p_repo: &str,
109    p_branch: &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        p_branch,
118    )?;
119    let reqwest_url = ::reqwest::Url::parse(&url)?;
120    let mut request = ::reqwest::Request::new(::reqwest::Method::DELETE, reqwest_url);
121    let headers = request.headers_mut();
122    headers.append(
123        "User-Agent",
124        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
125    );
126    if let Some(value) = &h_accept {
127        headers.append(
128            "Accept",
129            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
130        );
131    }
132    Ok(request)
133}
134
135#[cfg(feature = "reqwest")]
136pub fn reqwest_request(
137    mut builder: ::reqwest::Request,
138    content: Content<::reqwest::Body>,
139) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
140    if let Some(content_type) = content.content_type() {
141        builder.headers_mut().append(
142            ::reqwest::header::HeaderName::from_static("content-type"),
143            ::reqwest::header::HeaderValue::try_from(content_type)?,
144        );
145    }
146    *builder.body_mut() = Some(content.into_body());
147    Ok(builder)
148}
149
150#[cfg(feature = "reqwest")]
151impl From<::reqwest::Body> for Content<::reqwest::Body> {
152    fn from(body: ::reqwest::Body) -> Self {
153        Self::new(body)
154    }
155}
156
157#[cfg(feature = "reqwest-blocking")]
158pub fn reqwest_blocking_builder(
159    base_url: &str,
160    p_owner: &str,
161    p_repo: &str,
162    p_branch: &str,
163    h_user_agent: &str,
164    h_accept: ::std::option::Option<&str>,
165) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
166    let url = url_string(
167        base_url,
168        p_owner,
169        p_repo,
170        p_branch,
171    )?;
172    let reqwest_url = ::reqwest::Url::parse(&url)?;
173    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::DELETE, reqwest_url);
174    let headers = request.headers_mut();
175    headers.append(
176        "User-Agent",
177        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
178    );
179    if let Some(value) = &h_accept {
180        headers.append(
181            "Accept",
182            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
183        );
184    }
185    Ok(request)
186}
187
188#[cfg(feature = "reqwest-blocking")]
189pub fn reqwest_blocking_request(
190    mut builder: ::reqwest::blocking::Request,
191    content: Content<::reqwest::blocking::Body>,
192) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
193    if let Some(content_type) = content.content_type() {
194        builder.headers_mut().append(
195            ::reqwest::header::HeaderName::from_static("content-type"),
196            ::reqwest::header::HeaderValue::try_from(content_type)?,
197        );
198    }
199    *builder.body_mut() = Some(content.into_body());
200    Ok(builder)
201}
202
203#[cfg(feature = "reqwest-blocking")]
204impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
205    fn from(body: ::reqwest::blocking::Body) -> Self {
206        Self::new(body)
207    }
208}
209
210/// Types for body parameter in [`super::repos_remove_status_check_contexts`]
211pub mod body {
212    #[cfg(feature = "hyper")]
213    impl<'a> TryFrom<&::serde_json::value::Value> for super::Content<::hyper::Body> {
214        type Error = crate::v1_1_4::ApiError;
215
216        fn try_from(value: &::serde_json::value::Value) -> Result<Self, Self::Error> {
217            Ok(
218                Self::new(::serde_json::to_vec(value)?.into())
219                .with_content_type(&b"application/json"[..])
220            )
221        }
222    }
223
224    #[cfg(feature = "reqwest")]
225    impl<'a> TryFrom<&::serde_json::value::Value> for super::Content<::reqwest::Body> {
226        type Error = crate::v1_1_4::ApiError;
227
228        fn try_from(value: &::serde_json::value::Value) -> Result<Self, Self::Error> {
229            Ok(
230                Self::new(::serde_json::to_vec(value)?.into())
231                .with_content_type(&b"application/json"[..])
232            )
233        }
234    }
235
236    #[cfg(feature = "reqwest-blocking")]
237    impl<'a> TryFrom<&::serde_json::value::Value> for super::Content<::reqwest::blocking::Body> {
238        type Error = crate::v1_1_4::ApiError;
239
240        fn try_from(value: &::serde_json::value::Value) -> Result<Self, Self::Error> {
241            Ok(
242                Self::new(::serde_json::to_vec(value)?.into())
243                .with_content_type(&b"application/json"[..])
244            )
245        }
246    }
247}