jinxapi_github/v1_1_4/request/
migrations_update_import.rs1pub struct Content<Body>
13{
14 body: Body,
15 content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
16}
17
18impl<Body> Content<Body> {
19 pub fn new(body: Body) -> Self {
20 Self { body, content_type_value: None }
21 }
22
23 #[must_use]
24 pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
25 self.content_type_value = Some(content_type.into());
26 self
27 }
28
29 fn content_type(&self) -> Option<&[u8]> {
30 self.content_type_value.as_deref()
31 }
32
33 fn into_body(self) -> Body {
34 self.body
35 }
36}
37
38fn url_string(
39 base_url: &str,
40 p_owner: &str,
41 p_repo: &str,
42) -> Result<String, crate::v1_1_4::ApiError> {
43 let trimmed = if base_url.is_empty() {
44 "https://api.github.com"
45 } else {
46 base_url.trim_end_matches('/')
47 };
48 let mut url = String::with_capacity(trimmed.len() + 33);
49 url.push_str(trimmed);
50 url.push_str("/repos/");
51 ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
52 url.push('/');
53 ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
54 url.push_str("/import");
55 Ok(url)
56}
57
58#[cfg(feature = "hyper")]
59pub fn http_builder(
60 base_url: &str,
61 p_owner: &str,
62 p_repo: &str,
63 h_user_agent: &str,
64 h_accept: ::std::option::Option<&str>,
65) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
66 let url = url_string(
67 base_url,
68 p_owner,
69 p_repo,
70 )?;
71 let mut builder = ::http::request::Request::patch(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 h_user_agent: &str,
110 h_accept: ::std::option::Option<&str>,
111) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
112 let url = url_string(
113 base_url,
114 p_owner,
115 p_repo,
116 )?;
117 let reqwest_url = ::reqwest::Url::parse(&url)?;
118 let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
119 let headers = request.headers_mut();
120 headers.append(
121 "User-Agent",
122 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
123 );
124 if let Some(value) = &h_accept {
125 headers.append(
126 "Accept",
127 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
128 );
129 }
130 Ok(request)
131}
132
133#[cfg(feature = "reqwest")]
134pub fn reqwest_request(
135 mut builder: ::reqwest::Request,
136 content: Content<::reqwest::Body>,
137) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
138 if let Some(content_type) = content.content_type() {
139 builder.headers_mut().append(
140 ::reqwest::header::HeaderName::from_static("content-type"),
141 ::reqwest::header::HeaderValue::try_from(content_type)?,
142 );
143 }
144 *builder.body_mut() = Some(content.into_body());
145 Ok(builder)
146}
147
148#[cfg(feature = "reqwest")]
149impl From<::reqwest::Body> for Content<::reqwest::Body> {
150 fn from(body: ::reqwest::Body) -> Self {
151 Self::new(body)
152 }
153}
154
155#[cfg(feature = "reqwest-blocking")]
156pub fn reqwest_blocking_builder(
157 base_url: &str,
158 p_owner: &str,
159 p_repo: &str,
160 h_user_agent: &str,
161 h_accept: ::std::option::Option<&str>,
162) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
163 let url = url_string(
164 base_url,
165 p_owner,
166 p_repo,
167 )?;
168 let reqwest_url = ::reqwest::Url::parse(&url)?;
169 let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
170 let headers = request.headers_mut();
171 headers.append(
172 "User-Agent",
173 ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
174 );
175 if let Some(value) = &h_accept {
176 headers.append(
177 "Accept",
178 ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
179 );
180 }
181 Ok(request)
182}
183
184#[cfg(feature = "reqwest-blocking")]
185pub fn reqwest_blocking_request(
186 mut builder: ::reqwest::blocking::Request,
187 content: Content<::reqwest::blocking::Body>,
188) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
189 if let Some(content_type) = content.content_type() {
190 builder.headers_mut().append(
191 ::reqwest::header::HeaderName::from_static("content-type"),
192 ::reqwest::header::HeaderValue::try_from(content_type)?,
193 );
194 }
195 *builder.body_mut() = Some(content.into_body());
196 Ok(builder)
197}
198
199#[cfg(feature = "reqwest-blocking")]
200impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
201 fn from(body: ::reqwest::blocking::Body) -> Self {
202 Self::new(body)
203 }
204}
205
206pub mod body {
208 #[allow(non_snake_case)]
209 #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
210 pub struct Json<'a> {
211 #[serde(skip_serializing_if = "Option::is_none", default)]
213 pub vcs_username: ::std::option::Option<::std::borrow::Cow<'a, str>>,
214
215 #[serde(skip_serializing_if = "Option::is_none", default)]
217 pub vcs_password: ::std::option::Option<::std::borrow::Cow<'a, str>>,
218
219 #[serde(skip_serializing_if = "Option::is_none", default)]
227 pub vcs: ::std::option::Option<::std::borrow::Cow<'a, str>>,
228
229 #[serde(skip_serializing_if = "Option::is_none", default)]
237 pub tfvc_project: ::std::option::Option<::std::borrow::Cow<'a, str>>,
238
239 #[serde(flatten)]
240 pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
241 }
242
243 #[cfg(feature = "hyper")]
244 impl<'a> TryFrom<&::std::option::Option<crate::v1_1_4::request::migrations_update_import::body::Json<'a>>> for super::Content<::hyper::Body> {
245 type Error = crate::v1_1_4::ApiError;
246
247 fn try_from(value: &::std::option::Option<crate::v1_1_4::request::migrations_update_import::body::Json<'a>>) -> Result<Self, Self::Error> {
248 Ok(
249 Self::new(::serde_json::to_vec(value)?.into())
250 .with_content_type(&b"application/json"[..])
251 )
252 }
253 }
254
255 #[cfg(feature = "reqwest")]
256 impl<'a> TryFrom<&::std::option::Option<crate::v1_1_4::request::migrations_update_import::body::Json<'a>>> for super::Content<::reqwest::Body> {
257 type Error = crate::v1_1_4::ApiError;
258
259 fn try_from(value: &::std::option::Option<crate::v1_1_4::request::migrations_update_import::body::Json<'a>>) -> Result<Self, Self::Error> {
260 Ok(
261 Self::new(::serde_json::to_vec(value)?.into())
262 .with_content_type(&b"application/json"[..])
263 )
264 }
265 }
266
267 #[cfg(feature = "reqwest-blocking")]
268 impl<'a> TryFrom<&::std::option::Option<crate::v1_1_4::request::migrations_update_import::body::Json<'a>>> for super::Content<::reqwest::blocking::Body> {
269 type Error = crate::v1_1_4::ApiError;
270
271 fn try_from(value: &::std::option::Option<crate::v1_1_4::request::migrations_update_import::body::Json<'a>>) -> Result<Self, Self::Error> {
272 Ok(
273 Self::new(::serde_json::to_vec(value)?.into())
274 .with_content_type(&b"application/json"[..])
275 )
276 }
277 }
278}