jinxapi_github/v1_1_4/request/
migrations_start_import.rs

1//! Start an import
2//! 
3//! Start a source import to a GitHub repository using GitHub Importer.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/migrations#start-an-import)
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) -> Result<String, crate::v1_1_4::ApiError> {
38    let trimmed = if base_url.is_empty() {
39        "https://api.github.com"
40    } else {
41        base_url.trim_end_matches('/')
42    };
43    let mut url = String::with_capacity(trimmed.len() + 33);
44    url.push_str(trimmed);
45    url.push_str("/repos/");
46    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
47    url.push('/');
48    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
49    url.push_str("/import");
50    Ok(url)
51}
52
53#[cfg(feature = "hyper")]
54pub fn http_builder(
55    base_url: &str,
56    p_owner: &str,
57    p_repo: &str,
58    h_user_agent: &str,
59    h_accept: ::std::option::Option<&str>,
60) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
61    let url = url_string(
62        base_url,
63        p_owner,
64        p_repo,
65    )?;
66    let mut builder = ::http::request::Request::put(url);
67    builder = builder.header(
68        "User-Agent",
69        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
70    );
71    if let Some(value) = &h_accept {
72        builder = builder.header(
73            "Accept",
74            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
75        );
76    }
77    Ok(builder)
78}
79
80#[cfg(feature = "hyper")]
81pub fn hyper_request(
82    mut builder: ::http::request::Builder,
83    content: Content<::hyper::Body>,
84) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
85{
86    if let Some(content_type) = content.content_type() {
87        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
88    }
89    Ok(builder.body(content.into_body())?)
90}
91
92#[cfg(feature = "hyper")]
93impl From<::hyper::Body> for Content<::hyper::Body> {
94    fn from(body: ::hyper::Body) -> Self {
95        Self::new(body)
96    }
97}
98
99#[cfg(feature = "reqwest")]
100pub fn reqwest_builder(
101    base_url: &str,
102    p_owner: &str,
103    p_repo: &str,
104    h_user_agent: &str,
105    h_accept: ::std::option::Option<&str>,
106) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
107    let url = url_string(
108        base_url,
109        p_owner,
110        p_repo,
111    )?;
112    let reqwest_url = ::reqwest::Url::parse(&url)?;
113    let mut request = ::reqwest::Request::new(::reqwest::Method::PUT, reqwest_url);
114    let headers = request.headers_mut();
115    headers.append(
116        "User-Agent",
117        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
118    );
119    if let Some(value) = &h_accept {
120        headers.append(
121            "Accept",
122            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
123        );
124    }
125    Ok(request)
126}
127
128#[cfg(feature = "reqwest")]
129pub fn reqwest_request(
130    mut builder: ::reqwest::Request,
131    content: Content<::reqwest::Body>,
132) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
133    if let Some(content_type) = content.content_type() {
134        builder.headers_mut().append(
135            ::reqwest::header::HeaderName::from_static("content-type"),
136            ::reqwest::header::HeaderValue::try_from(content_type)?,
137        );
138    }
139    *builder.body_mut() = Some(content.into_body());
140    Ok(builder)
141}
142
143#[cfg(feature = "reqwest")]
144impl From<::reqwest::Body> for Content<::reqwest::Body> {
145    fn from(body: ::reqwest::Body) -> Self {
146        Self::new(body)
147    }
148}
149
150#[cfg(feature = "reqwest-blocking")]
151pub fn reqwest_blocking_builder(
152    base_url: &str,
153    p_owner: &str,
154    p_repo: &str,
155    h_user_agent: &str,
156    h_accept: ::std::option::Option<&str>,
157) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
158    let url = url_string(
159        base_url,
160        p_owner,
161        p_repo,
162    )?;
163    let reqwest_url = ::reqwest::Url::parse(&url)?;
164    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PUT, reqwest_url);
165    let headers = request.headers_mut();
166    headers.append(
167        "User-Agent",
168        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
169    );
170    if let Some(value) = &h_accept {
171        headers.append(
172            "Accept",
173            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
174        );
175    }
176    Ok(request)
177}
178
179#[cfg(feature = "reqwest-blocking")]
180pub fn reqwest_blocking_request(
181    mut builder: ::reqwest::blocking::Request,
182    content: Content<::reqwest::blocking::Body>,
183) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
184    if let Some(content_type) = content.content_type() {
185        builder.headers_mut().append(
186            ::reqwest::header::HeaderName::from_static("content-type"),
187            ::reqwest::header::HeaderValue::try_from(content_type)?,
188        );
189    }
190    *builder.body_mut() = Some(content.into_body());
191    Ok(builder)
192}
193
194#[cfg(feature = "reqwest-blocking")]
195impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
196    fn from(body: ::reqwest::blocking::Body) -> Self {
197        Self::new(body)
198    }
199}
200
201/// Types for body parameter in [`super::migrations_start_import`]
202pub mod body {
203    #[allow(non_snake_case)]
204    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
205    pub struct Json<'a> {
206        /// The URL of the originating repository.
207        pub vcs_url: ::std::borrow::Cow<'a, str>,
208
209        /// The originating VCS type. Can be one of `subversion`, `git`, `mercurial`, or `tfvc`. Please be aware that without this parameter, the import job will take additional time to detect the VCS type before beginning the import. This detection step will be reflected in the response.
210        #[serde(skip_serializing_if = "Option::is_none", default)]
211        pub vcs: ::std::option::Option<::std::borrow::Cow<'a, str>>,
212
213        /// If authentication is required, the username to provide to `vcs_url`.
214        #[serde(skip_serializing_if = "Option::is_none", default)]
215        pub vcs_username: ::std::option::Option<::std::borrow::Cow<'a, str>>,
216
217        /// If authentication is required, the password to provide to `vcs_url`.
218        #[serde(skip_serializing_if = "Option::is_none", default)]
219        pub vcs_password: ::std::option::Option<::std::borrow::Cow<'a, str>>,
220
221        /// For a tfvc import, the name of the project that is being imported.
222        #[serde(skip_serializing_if = "Option::is_none", default)]
223        pub tfvc_project: ::std::option::Option<::std::borrow::Cow<'a, str>>,
224
225        #[serde(flatten)]
226        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
227    }
228
229    #[cfg(feature = "hyper")]
230    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
231        type Error = crate::v1_1_4::ApiError;
232
233        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
234            Ok(
235                Self::new(::serde_json::to_vec(value)?.into())
236                .with_content_type(&b"application/json"[..])
237            )
238        }
239    }
240
241    #[cfg(feature = "reqwest")]
242    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
243        type Error = crate::v1_1_4::ApiError;
244
245        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
246            Ok(
247                Self::new(::serde_json::to_vec(value)?.into())
248                .with_content_type(&b"application/json"[..])
249            )
250        }
251    }
252
253    #[cfg(feature = "reqwest-blocking")]
254    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
255        type Error = crate::v1_1_4::ApiError;
256
257        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
258            Ok(
259                Self::new(::serde_json::to_vec(value)?.into())
260                .with_content_type(&b"application/json"[..])
261            )
262        }
263    }
264}