jinxapi_github/v1_1_4/request/
repos_create_in_org.rs

1//! Create an organization repository
2//! 
3//! Creates a new repository in the specified organization. The authenticated user must be a member of the organization.
4//! 
5//! **OAuth scope requirements**
6//! 
7//! When using [OAuth](https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/), authorizations must include:
8//! 
9//! *   `public_repo` scope or `repo` scope to create a public repository. Note: For GitHub AE, use `repo` scope to create an internal repository.
10//! *   `repo` scope to create a private repository
11//! 
12//! [API method documentation](https://docs.github.com/rest/reference/repos#create-an-organization-repository)
13
14pub struct Content<Body>
15{
16    body: Body,
17    content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
18}
19
20impl<Body> Content<Body> {
21    pub fn new(body: Body) -> Self {
22        Self { body, content_type_value: None }
23    }
24
25    #[must_use]
26    pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
27        self.content_type_value = Some(content_type.into());
28        self
29    }
30
31    fn content_type(&self) -> Option<&[u8]> {
32        self.content_type_value.as_deref()
33    }
34
35    fn into_body(self) -> Body {
36        self.body
37    }
38}
39
40fn url_string(
41    base_url: &str,
42    p_org: &str,
43) -> Result<String, crate::v1_1_4::ApiError> {
44    let trimmed = if base_url.is_empty() {
45        "https://api.github.com"
46    } else {
47        base_url.trim_end_matches('/')
48    };
49    let mut url = String::with_capacity(trimmed.len() + 29);
50    url.push_str(trimmed);
51    url.push_str("/orgs/");
52    ::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
53    url.push_str("/repos");
54    Ok(url)
55}
56
57#[cfg(feature = "hyper")]
58pub fn http_builder(
59    base_url: &str,
60    p_org: &str,
61    h_user_agent: &str,
62    h_accept: ::std::option::Option<&str>,
63) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
64    let url = url_string(
65        base_url,
66        p_org,
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_org: &str,
105    h_user_agent: &str,
106    h_accept: ::std::option::Option<&str>,
107) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
108    let url = url_string(
109        base_url,
110        p_org,
111    )?;
112    let reqwest_url = ::reqwest::Url::parse(&url)?;
113    let mut request = ::reqwest::Request::new(::reqwest::Method::POST, 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_org: &str,
154    h_user_agent: &str,
155    h_accept: ::std::option::Option<&str>,
156) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
157    let url = url_string(
158        base_url,
159        p_org,
160    )?;
161    let reqwest_url = ::reqwest::Url::parse(&url)?;
162    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
163    let headers = request.headers_mut();
164    headers.append(
165        "User-Agent",
166        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
167    );
168    if let Some(value) = &h_accept {
169        headers.append(
170            "Accept",
171            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
172        );
173    }
174    Ok(request)
175}
176
177#[cfg(feature = "reqwest-blocking")]
178pub fn reqwest_blocking_request(
179    mut builder: ::reqwest::blocking::Request,
180    content: Content<::reqwest::blocking::Body>,
181) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
182    if let Some(content_type) = content.content_type() {
183        builder.headers_mut().append(
184            ::reqwest::header::HeaderName::from_static("content-type"),
185            ::reqwest::header::HeaderValue::try_from(content_type)?,
186        );
187    }
188    *builder.body_mut() = Some(content.into_body());
189    Ok(builder)
190}
191
192#[cfg(feature = "reqwest-blocking")]
193impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
194    fn from(body: ::reqwest::blocking::Body) -> Self {
195        Self::new(body)
196    }
197}
198
199/// Types for body parameter in [`super::repos_create_in_org`]
200pub mod body {
201    #[allow(non_snake_case)]
202    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
203    pub struct Json<'a> {
204        /// The name of the repository.
205        pub name: ::std::borrow::Cow<'a, str>,
206
207        /// A short description of the repository.
208        #[serde(skip_serializing_if = "Option::is_none", default)]
209        pub description: ::std::option::Option<::std::borrow::Cow<'a, str>>,
210
211        /// A URL with more information about the repository.
212        #[serde(skip_serializing_if = "Option::is_none", default)]
213        pub homepage: ::std::option::Option<::std::borrow::Cow<'a, str>>,
214
215        /// Whether the repository is private.
216        #[serde(skip_serializing_if = "Option::is_none", default)]
217        pub private: ::std::option::Option<bool>,
218
219        /// Can be `public` or `private`. If your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+, `visibility` can also be `internal`. Note: For GitHub Enterprise Server and GitHub AE, this endpoint will only list repositories available to all users on the enterprise. For more information, see "[Creating an internal repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-repository-visibility#about-internal-repositories)" in the GitHub Help documentation.
220        #[serde(skip_serializing_if = "Option::is_none", default)]
221        pub visibility: ::std::option::Option<::std::borrow::Cow<'a, str>>,
222
223        /// Either `true` to enable issues for this repository or `false` to disable them.
224        #[serde(skip_serializing_if = "Option::is_none", default)]
225        pub has_issues: ::std::option::Option<bool>,
226
227        /// Either `true` to enable projects for this repository or `false` to disable them. **Note:** If you're creating a repository in an organization that has disabled repository projects, the default is `false`, and if you pass `true`, the API returns an error.
228        #[serde(skip_serializing_if = "Option::is_none", default)]
229        pub has_projects: ::std::option::Option<bool>,
230
231        /// Either `true` to enable the wiki for this repository or `false` to disable it.
232        #[serde(skip_serializing_if = "Option::is_none", default)]
233        pub has_wiki: ::std::option::Option<bool>,
234
235        /// Either `true` to make this repo available as a template repository or `false` to prevent it.
236        #[serde(skip_serializing_if = "Option::is_none", default)]
237        pub is_template: ::std::option::Option<bool>,
238
239        /// The id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization.
240        #[serde(skip_serializing_if = "Option::is_none", default)]
241        pub team_id: ::std::option::Option<i64>,
242
243        /// Pass `true` to create an initial commit with empty README.
244        #[serde(skip_serializing_if = "Option::is_none", default)]
245        pub auto_init: ::std::option::Option<bool>,
246
247        /// Desired language or platform [.gitignore template](https://github.com/github/gitignore) to apply. Use the name of the template without the extension. For example, "Haskell".
248        #[serde(skip_serializing_if = "Option::is_none", default)]
249        pub gitignore_template: ::std::option::Option<::std::borrow::Cow<'a, str>>,
250
251        /// Choose an [open source license template](https://choosealicense.com/) that best suits your needs, and then use the [license keyword](https://docs.github.com/articles/licensing-a-repository/#searching-github-by-license-type) as the `license_template` string. For example, "mit" or "mpl-2.0".
252        #[serde(skip_serializing_if = "Option::is_none", default)]
253        pub license_template: ::std::option::Option<::std::borrow::Cow<'a, str>>,
254
255        /// Either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
256        #[serde(skip_serializing_if = "Option::is_none", default)]
257        pub allow_squash_merge: ::std::option::Option<bool>,
258
259        /// Either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
260        #[serde(skip_serializing_if = "Option::is_none", default)]
261        pub allow_merge_commit: ::std::option::Option<bool>,
262
263        /// Either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
264        #[serde(skip_serializing_if = "Option::is_none", default)]
265        pub allow_rebase_merge: ::std::option::Option<bool>,
266
267        /// Either `true` to allow auto-merge on pull requests, or `false` to disallow auto-merge.
268        #[serde(skip_serializing_if = "Option::is_none", default)]
269        pub allow_auto_merge: ::std::option::Option<bool>,
270
271        /// Either `true` to allow automatically deleting head branches when pull requests are merged, or `false` to prevent automatic deletion.
272        #[serde(skip_serializing_if = "Option::is_none", default)]
273        pub delete_branch_on_merge: ::std::option::Option<bool>,
274
275        #[serde(flatten)]
276        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
277    }
278
279    #[cfg(feature = "hyper")]
280    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
281        type Error = crate::v1_1_4::ApiError;
282
283        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
284            Ok(
285                Self::new(::serde_json::to_vec(value)?.into())
286                .with_content_type(&b"application/json"[..])
287            )
288        }
289    }
290
291    #[cfg(feature = "reqwest")]
292    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
293        type Error = crate::v1_1_4::ApiError;
294
295        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
296            Ok(
297                Self::new(::serde_json::to_vec(value)?.into())
298                .with_content_type(&b"application/json"[..])
299            )
300        }
301    }
302
303    #[cfg(feature = "reqwest-blocking")]
304    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
305        type Error = crate::v1_1_4::ApiError;
306
307        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
308            Ok(
309                Self::new(::serde_json::to_vec(value)?.into())
310                .with_content_type(&b"application/json"[..])
311            )
312        }
313    }
314}