jinxapi_github/v1_1_4/request/
orgs_update.rs

1//! Update an organization
2//! 
3//! **Parameter Deprecation Notice:** GitHub will replace and discontinue `members_allowed_repository_creation_type` in favor of more granular permissions. The new input parameters are `members_can_create_public_repositories`, `members_can_create_private_repositories` for all organizations and `members_can_create_internal_repositories` for organizations associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. For more information, see the [blog post](https://developer.github.com/changes/2019-12-03-internal-visibility-changes).
4//! 
5//! Enables an authenticated organization owner with the `admin:org` scope to update the organization's profile and member privileges.
6//! 
7//! [API method documentation](https://docs.github.com/rest/reference/orgs/#update-an-organization)
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_org: &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() + 23);
45    url.push_str(trimmed);
46    url.push_str("/orgs/");
47    ::querylizer::Simple::extend(&mut url, &p_org, false, &::querylizer::encode_path)?;
48    Ok(url)
49}
50
51#[cfg(feature = "hyper")]
52pub fn http_builder(
53    base_url: &str,
54    p_org: &str,
55    h_user_agent: &str,
56    h_accept: ::std::option::Option<&str>,
57) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
58    let url = url_string(
59        base_url,
60        p_org,
61    )?;
62    let mut builder = ::http::request::Request::patch(url);
63    builder = builder.header(
64        "User-Agent",
65        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
66    );
67    if let Some(value) = &h_accept {
68        builder = builder.header(
69            "Accept",
70            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
71        );
72    }
73    Ok(builder)
74}
75
76#[cfg(feature = "hyper")]
77pub fn hyper_request(
78    mut builder: ::http::request::Builder,
79    content: Content<::hyper::Body>,
80) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
81{
82    if let Some(content_type) = content.content_type() {
83        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
84    }
85    Ok(builder.body(content.into_body())?)
86}
87
88#[cfg(feature = "hyper")]
89impl From<::hyper::Body> for Content<::hyper::Body> {
90    fn from(body: ::hyper::Body) -> Self {
91        Self::new(body)
92    }
93}
94
95#[cfg(feature = "reqwest")]
96pub fn reqwest_builder(
97    base_url: &str,
98    p_org: &str,
99    h_user_agent: &str,
100    h_accept: ::std::option::Option<&str>,
101) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
102    let url = url_string(
103        base_url,
104        p_org,
105    )?;
106    let reqwest_url = ::reqwest::Url::parse(&url)?;
107    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
108    let headers = request.headers_mut();
109    headers.append(
110        "User-Agent",
111        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
112    );
113    if let Some(value) = &h_accept {
114        headers.append(
115            "Accept",
116            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
117        );
118    }
119    Ok(request)
120}
121
122#[cfg(feature = "reqwest")]
123pub fn reqwest_request(
124    mut builder: ::reqwest::Request,
125    content: Content<::reqwest::Body>,
126) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
127    if let Some(content_type) = content.content_type() {
128        builder.headers_mut().append(
129            ::reqwest::header::HeaderName::from_static("content-type"),
130            ::reqwest::header::HeaderValue::try_from(content_type)?,
131        );
132    }
133    *builder.body_mut() = Some(content.into_body());
134    Ok(builder)
135}
136
137#[cfg(feature = "reqwest")]
138impl From<::reqwest::Body> for Content<::reqwest::Body> {
139    fn from(body: ::reqwest::Body) -> Self {
140        Self::new(body)
141    }
142}
143
144#[cfg(feature = "reqwest-blocking")]
145pub fn reqwest_blocking_builder(
146    base_url: &str,
147    p_org: &str,
148    h_user_agent: &str,
149    h_accept: ::std::option::Option<&str>,
150) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
151    let url = url_string(
152        base_url,
153        p_org,
154    )?;
155    let reqwest_url = ::reqwest::Url::parse(&url)?;
156    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
157    let headers = request.headers_mut();
158    headers.append(
159        "User-Agent",
160        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
161    );
162    if let Some(value) = &h_accept {
163        headers.append(
164            "Accept",
165            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
166        );
167    }
168    Ok(request)
169}
170
171#[cfg(feature = "reqwest-blocking")]
172pub fn reqwest_blocking_request(
173    mut builder: ::reqwest::blocking::Request,
174    content: Content<::reqwest::blocking::Body>,
175) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
176    if let Some(content_type) = content.content_type() {
177        builder.headers_mut().append(
178            ::reqwest::header::HeaderName::from_static("content-type"),
179            ::reqwest::header::HeaderValue::try_from(content_type)?,
180        );
181    }
182    *builder.body_mut() = Some(content.into_body());
183    Ok(builder)
184}
185
186#[cfg(feature = "reqwest-blocking")]
187impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
188    fn from(body: ::reqwest::blocking::Body) -> Self {
189        Self::new(body)
190    }
191}
192
193/// Types for body parameter in [`super::orgs_update`]
194pub mod body {
195    #[allow(non_snake_case)]
196    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
197    pub struct Json<'a> {
198        /// Billing email address. This address is not publicized.
199        #[serde(skip_serializing_if = "Option::is_none", default)]
200        pub billing_email: ::std::option::Option<::std::borrow::Cow<'a, str>>,
201
202        /// The company name.
203        #[serde(skip_serializing_if = "Option::is_none", default)]
204        pub company: ::std::option::Option<::std::borrow::Cow<'a, str>>,
205
206        /// The publicly visible email address.
207        #[serde(skip_serializing_if = "Option::is_none", default)]
208        pub email: ::std::option::Option<::std::borrow::Cow<'a, str>>,
209
210        /// The Twitter username of the company.
211        #[serde(skip_serializing_if = "Option::is_none", default)]
212        pub twitter_username: ::std::option::Option<::std::borrow::Cow<'a, str>>,
213
214        /// The location.
215        #[serde(skip_serializing_if = "Option::is_none", default)]
216        pub location: ::std::option::Option<::std::borrow::Cow<'a, str>>,
217
218        /// The shorthand name of the company.
219        #[serde(skip_serializing_if = "Option::is_none", default)]
220        pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
221
222        /// The description of the company.
223        #[serde(skip_serializing_if = "Option::is_none", default)]
224        pub description: ::std::option::Option<::std::borrow::Cow<'a, str>>,
225
226        /// Toggles whether an organization can use organization projects.
227        #[serde(skip_serializing_if = "Option::is_none", default)]
228        pub has_organization_projects: ::std::option::Option<bool>,
229
230        /// Toggles whether repositories that belong to the organization can use repository projects.
231        #[serde(skip_serializing_if = "Option::is_none", default)]
232        pub has_repository_projects: ::std::option::Option<bool>,
233
234        /// Default permission level members have for organization repositories:  
235        /// \* `read` - can pull, but not push to or administer this repository.  
236        /// \* `write` - can pull and push, but not administer this repository.  
237        /// \* `admin` - can pull, push, and administer this repository.  
238        /// \* `none` - no permissions granted by default.
239        #[serde(skip_serializing_if = "Option::is_none", default)]
240        pub default_repository_permission: ::std::option::Option<::std::borrow::Cow<'a, str>>,
241
242        /// Toggles the ability of non-admin organization members to create repositories. Can be one of:  
243        /// \* `true` - all organization members can create repositories.  
244        /// \* `false` - only organization owners can create repositories.  
245        /// Default: `true`  
246        /// **Note:** A parameter can override this parameter. See `members_allowed_repository_creation_type` in this table for details. **Note:** A parameter can override this parameter. See `members_allowed_repository_creation_type` in this table for details.
247        #[serde(skip_serializing_if = "Option::is_none", default)]
248        pub members_can_create_repositories: ::std::option::Option<bool>,
249
250        /// Toggles whether organization members can create internal repositories, which are visible to all enterprise members. You can only allow members to create internal repositories if your organization is associated with an enterprise account using GitHub Enterprise Cloud or GitHub Enterprise Server 2.20+. Can be one of:  
251        /// \* `true` - all organization members can create internal repositories.  
252        /// \* `false` - only organization owners can create internal repositories.  
253        /// Default: `true`. For more information, see "[Restricting repository creation in your organization](https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/restricting-repository-creation-in-your-organization)" in the GitHub Help documentation.
254        #[serde(skip_serializing_if = "Option::is_none", default)]
255        pub members_can_create_internal_repositories: ::std::option::Option<bool>,
256
257        /// Toggles whether organization members can create private repositories, which are visible to organization members with permission. Can be one of:  
258        /// \* `true` - all organization members can create private repositories.  
259        /// \* `false` - only organization owners can create private repositories.  
260        /// Default: `true`. For more information, see "[Restricting repository creation in your organization](https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/restricting-repository-creation-in-your-organization)" in the GitHub Help documentation.
261        #[serde(skip_serializing_if = "Option::is_none", default)]
262        pub members_can_create_private_repositories: ::std::option::Option<bool>,
263
264        /// Toggles whether organization members can create public repositories, which are visible to anyone. Can be one of:  
265        /// \* `true` - all organization members can create public repositories.  
266        /// \* `false` - only organization owners can create public repositories.  
267        /// Default: `true`. For more information, see "[Restricting repository creation in your organization](https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/restricting-repository-creation-in-your-organization)" in the GitHub Help documentation.
268        #[serde(skip_serializing_if = "Option::is_none", default)]
269        pub members_can_create_public_repositories: ::std::option::Option<bool>,
270
271        /// Specifies which types of repositories non-admin organization members can create. Can be one of:  
272        /// \* `all` - all organization members can create public and private repositories.  
273        /// \* `private` - members can create private repositories. This option is only available to repositories that are part of an organization on GitHub Enterprise Cloud.  
274        /// \* `none` - only admin members can create repositories.  
275        /// **Note:** This parameter is deprecated and will be removed in the future. Its return value ignores internal repositories. Using this parameter overrides values set in `members_can_create_repositories`. See the parameter deprecation notice in the operation description for details.
276        #[serde(skip_serializing_if = "Option::is_none", default)]
277        pub members_allowed_repository_creation_type: ::std::option::Option<::std::borrow::Cow<'a, str>>,
278
279        /// Toggles whether organization members can create GitHub Pages sites. Can be one of:  
280        /// \* `true` - all organization members can create GitHub Pages sites.  
281        /// \* `false` - no organization members can create GitHub Pages sites. Existing published sites will not be impacted.
282        #[serde(skip_serializing_if = "Option::is_none", default)]
283        pub members_can_create_pages: ::std::option::Option<bool>,
284
285        /// Toggles whether organization members can create public GitHub Pages sites. Can be one of:  
286        /// \* `true` - all organization members can create public GitHub Pages sites.  
287        /// \* `false` - no organization members can create public GitHub Pages sites. Existing published sites will not be impacted.
288        #[serde(skip_serializing_if = "Option::is_none", default)]
289        pub members_can_create_public_pages: ::std::option::Option<bool>,
290
291        /// Toggles whether organization members can create private GitHub Pages sites. Can be one of:  
292        /// \* `true` - all organization members can create private GitHub Pages sites.  
293        /// \* `false` - no organization members can create private GitHub Pages sites. Existing published sites will not be impacted.
294        #[serde(skip_serializing_if = "Option::is_none", default)]
295        pub members_can_create_private_pages: ::std::option::Option<bool>,
296
297        /// Toggles whether organization members can fork private organization repositories. Can be one of:  
298        /// \* `true` - all organization members can fork private repositories within the organization.  
299        /// \* `false` - no organization members can fork private repositories within the organization.
300        #[serde(skip_serializing_if = "Option::is_none", default)]
301        pub members_can_fork_private_repositories: ::std::option::Option<bool>,
302
303        /// # Example
304        /// 
305        /// ```json
306        /// "\"http://github.blog\""
307        /// ```
308        #[serde(skip_serializing_if = "Option::is_none", default)]
309        pub blog: ::std::option::Option<::std::borrow::Cow<'a, str>>,
310
311        #[serde(flatten)]
312        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
313    }
314
315    #[cfg(feature = "hyper")]
316    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
317        type Error = crate::v1_1_4::ApiError;
318
319        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
320            Ok(
321                Self::new(::serde_json::to_vec(value)?.into())
322                .with_content_type(&b"application/json"[..])
323            )
324        }
325    }
326
327    #[cfg(feature = "reqwest")]
328    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
329        type Error = crate::v1_1_4::ApiError;
330
331        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
332            Ok(
333                Self::new(::serde_json::to_vec(value)?.into())
334                .with_content_type(&b"application/json"[..])
335            )
336        }
337    }
338
339    #[cfg(feature = "reqwest-blocking")]
340    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
341        type Error = crate::v1_1_4::ApiError;
342
343        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
344            Ok(
345                Self::new(::serde_json::to_vec(value)?.into())
346                .with_content_type(&b"application/json"[..])
347            )
348        }
349    }
350}