jinxapi_github/v1_1_4/request/
repos_update.rs

1//! Update a repository
2//! 
3//! **Note**: To edit a repository's topics, use the [Replace all repository topics](https://docs.github.com/rest/reference/repos#replace-all-repository-topics) endpoint.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/repos/#update-a-repository)
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() + 26);
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    Ok(url)
50}
51
52#[cfg(feature = "hyper")]
53pub fn http_builder(
54    base_url: &str,
55    p_owner: &str,
56    p_repo: &str,
57    h_user_agent: &str,
58    h_accept: ::std::option::Option<&str>,
59) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
60    let url = url_string(
61        base_url,
62        p_owner,
63        p_repo,
64    )?;
65    let mut builder = ::http::request::Request::patch(url);
66    builder = builder.header(
67        "User-Agent",
68        &::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
69    );
70    if let Some(value) = &h_accept {
71        builder = builder.header(
72            "Accept",
73            &::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
74        );
75    }
76    Ok(builder)
77}
78
79#[cfg(feature = "hyper")]
80pub fn hyper_request(
81    mut builder: ::http::request::Builder,
82    content: Content<::hyper::Body>,
83) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
84{
85    if let Some(content_type) = content.content_type() {
86        builder = builder.header(::http::header::CONTENT_TYPE, content_type);
87    }
88    Ok(builder.body(content.into_body())?)
89}
90
91#[cfg(feature = "hyper")]
92impl From<::hyper::Body> for Content<::hyper::Body> {
93    fn from(body: ::hyper::Body) -> Self {
94        Self::new(body)
95    }
96}
97
98#[cfg(feature = "reqwest")]
99pub fn reqwest_builder(
100    base_url: &str,
101    p_owner: &str,
102    p_repo: &str,
103    h_user_agent: &str,
104    h_accept: ::std::option::Option<&str>,
105) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
106    let url = url_string(
107        base_url,
108        p_owner,
109        p_repo,
110    )?;
111    let reqwest_url = ::reqwest::Url::parse(&url)?;
112    let mut request = ::reqwest::Request::new(::reqwest::Method::PATCH, reqwest_url);
113    let headers = request.headers_mut();
114    headers.append(
115        "User-Agent",
116        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
117    );
118    if let Some(value) = &h_accept {
119        headers.append(
120            "Accept",
121            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
122        );
123    }
124    Ok(request)
125}
126
127#[cfg(feature = "reqwest")]
128pub fn reqwest_request(
129    mut builder: ::reqwest::Request,
130    content: Content<::reqwest::Body>,
131) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
132    if let Some(content_type) = content.content_type() {
133        builder.headers_mut().append(
134            ::reqwest::header::HeaderName::from_static("content-type"),
135            ::reqwest::header::HeaderValue::try_from(content_type)?,
136        );
137    }
138    *builder.body_mut() = Some(content.into_body());
139    Ok(builder)
140}
141
142#[cfg(feature = "reqwest")]
143impl From<::reqwest::Body> for Content<::reqwest::Body> {
144    fn from(body: ::reqwest::Body) -> Self {
145        Self::new(body)
146    }
147}
148
149#[cfg(feature = "reqwest-blocking")]
150pub fn reqwest_blocking_builder(
151    base_url: &str,
152    p_owner: &str,
153    p_repo: &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_owner,
160        p_repo,
161    )?;
162    let reqwest_url = ::reqwest::Url::parse(&url)?;
163    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::PATCH, reqwest_url);
164    let headers = request.headers_mut();
165    headers.append(
166        "User-Agent",
167        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
168    );
169    if let Some(value) = &h_accept {
170        headers.append(
171            "Accept",
172            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
173        );
174    }
175    Ok(request)
176}
177
178#[cfg(feature = "reqwest-blocking")]
179pub fn reqwest_blocking_request(
180    mut builder: ::reqwest::blocking::Request,
181    content: Content<::reqwest::blocking::Body>,
182) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
183    if let Some(content_type) = content.content_type() {
184        builder.headers_mut().append(
185            ::reqwest::header::HeaderName::from_static("content-type"),
186            ::reqwest::header::HeaderValue::try_from(content_type)?,
187        );
188    }
189    *builder.body_mut() = Some(content.into_body());
190    Ok(builder)
191}
192
193#[cfg(feature = "reqwest-blocking")]
194impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
195    fn from(body: ::reqwest::blocking::Body) -> Self {
196        Self::new(body)
197    }
198}
199
200/// Types for body parameter in [`super::repos_update`]
201pub mod body {
202    #[allow(non_snake_case)]
203    #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
204    pub struct Json<'a> {
205        /// The name of the repository.
206        #[serde(skip_serializing_if = "Option::is_none", default)]
207        pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
208
209        /// A short description of the repository.
210        #[serde(skip_serializing_if = "Option::is_none", default)]
211        pub description: ::std::option::Option<::std::borrow::Cow<'a, str>>,
212
213        /// A URL with more information about the repository.
214        #[serde(skip_serializing_if = "Option::is_none", default)]
215        pub homepage: ::std::option::Option<::std::borrow::Cow<'a, str>>,
216
217        /// Either `true` to make the repository private or `false` to make it public. Default: `false`.  
218        /// **Note**: You will get a `422` error if the organization restricts [changing repository visibility](https://docs.github.com/articles/repository-permission-levels-for-an-organization#changing-the-visibility-of-repositories) to organization owners and a non-owner tries to change the value of private. **Note**: You will get a `422` error if the organization restricts [changing repository visibility](https://docs.github.com/articles/repository-permission-levels-for-an-organization#changing-the-visibility-of-repositories) to organization owners and a non-owner tries to change the value of private.
219        #[serde(skip_serializing_if = "Option::is_none", default)]
220        pub private: ::std::option::Option<bool>,
221
222        /// 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`."
223        #[serde(skip_serializing_if = "Option::is_none", default)]
224        pub visibility: ::std::option::Option<::std::borrow::Cow<'a, str>>,
225
226        #[serde(skip_serializing_if = "Option::is_none", default, deserialize_with = "crate::v1_1_4::support::deserialize_some")]
227        pub security_and_analysis: ::std::option::Option<::std::option::Option<crate::v1_1_4::request::repos_update::body::json::SecurityAndAnalysis<'a>>>,
228
229        /// Either `true` to enable issues for this repository or `false` to disable them.
230        #[serde(skip_serializing_if = "Option::is_none", default)]
231        pub has_issues: ::std::option::Option<bool>,
232
233        /// 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.
234        #[serde(skip_serializing_if = "Option::is_none", default)]
235        pub has_projects: ::std::option::Option<bool>,
236
237        /// Either `true` to enable the wiki for this repository or `false` to disable it.
238        #[serde(skip_serializing_if = "Option::is_none", default)]
239        pub has_wiki: ::std::option::Option<bool>,
240
241        /// Either `true` to make this repo available as a template repository or `false` to prevent it.
242        #[serde(skip_serializing_if = "Option::is_none", default)]
243        pub is_template: ::std::option::Option<bool>,
244
245        /// Updates the default branch for this repository.
246        #[serde(skip_serializing_if = "Option::is_none", default)]
247        pub default_branch: ::std::option::Option<::std::borrow::Cow<'a, str>>,
248
249        /// Either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
250        #[serde(skip_serializing_if = "Option::is_none", default)]
251        pub allow_squash_merge: ::std::option::Option<bool>,
252
253        /// Either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
254        #[serde(skip_serializing_if = "Option::is_none", default)]
255        pub allow_merge_commit: ::std::option::Option<bool>,
256
257        /// Either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
258        #[serde(skip_serializing_if = "Option::is_none", default)]
259        pub allow_rebase_merge: ::std::option::Option<bool>,
260
261        /// Either `true` to allow auto-merge on pull requests, or `false` to disallow auto-merge.
262        #[serde(skip_serializing_if = "Option::is_none", default)]
263        pub allow_auto_merge: ::std::option::Option<bool>,
264
265        /// Either `true` to allow automatically deleting head branches when pull requests are merged, or `false` to prevent automatic deletion.
266        #[serde(skip_serializing_if = "Option::is_none", default)]
267        pub delete_branch_on_merge: ::std::option::Option<bool>,
268
269        /// `true` to archive this repository. **Note**: You cannot unarchive repositories through the API.
270        #[serde(skip_serializing_if = "Option::is_none", default)]
271        pub archived: ::std::option::Option<bool>,
272
273        /// Either `true` to allow private forks, or `false` to prevent private forks.
274        #[serde(skip_serializing_if = "Option::is_none", default)]
275        pub allow_forking: ::std::option::Option<bool>,
276
277        #[serde(flatten)]
278        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
279    }
280
281    /// Types for fields in [`Json`]
282    pub mod json {
283        /// Specify which security and analysis features to enable or disable. For example, to enable GitHub Advanced Security, use this data in the body of the PATCH request: `{"security_and_analysis": {"advanced_security": {"status": "enabled"}}}`. If you have admin permissions for a private repository covered by an Advanced Security license, you can check which security and analysis features are currently enabled by using a `GET /repos/{owner}/{repo}` request.
284        #[allow(non_snake_case)]
285        #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
286        pub struct SecurityAndAnalysis<'a> {
287            #[serde(skip_serializing_if = "Option::is_none", default)]
288            pub advanced_security: ::std::option::Option<crate::v1_1_4::request::repos_update::body::json::security_and_analysis::AdvancedSecurity<'a>>,
289
290            #[serde(skip_serializing_if = "Option::is_none", default)]
291            pub secret_scanning: ::std::option::Option<crate::v1_1_4::request::repos_update::body::json::security_and_analysis::SecretScanning<'a>>,
292
293            #[serde(skip_serializing_if = "Option::is_none", default)]
294            pub secret_scanning_push_protection: ::std::option::Option<crate::v1_1_4::request::repos_update::body::json::security_and_analysis::SecretScanningPushProtection<'a>>,
295
296            #[serde(flatten)]
297            pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
298        }
299
300        /// Types for fields in [`SecurityAndAnalysis`]
301        pub mod security_and_analysis {
302            /// Use the `status` property to enable or disable GitHub Advanced Security for this repository. For more information, see "[About GitHub Advanced Security](/github/getting-started-with-github/learning-about-github/about-github-advanced-security)."
303            #[allow(non_snake_case)]
304            #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
305            pub struct AdvancedSecurity<'a> {
306                /// Can be `enabled` or `disabled`.
307                #[serde(skip_serializing_if = "Option::is_none", default)]
308                pub status: ::std::option::Option<::std::borrow::Cow<'a, str>>,
309
310                #[serde(flatten)]
311                pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
312            }
313
314            /// Use the `status` property to enable or disable secret scanning for this repository. For more information, see "[About secret scanning](/code-security/secret-security/about-secret-scanning)."
315            #[allow(non_snake_case)]
316            #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
317            pub struct SecretScanning<'a> {
318                /// Can be `enabled` or `disabled`.
319                #[serde(skip_serializing_if = "Option::is_none", default)]
320                pub status: ::std::option::Option<::std::borrow::Cow<'a, str>>,
321
322                #[serde(flatten)]
323                pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
324            }
325
326            /// Use the `status` property to enable or disable secret scanning push protection for this repository. For more information, see "[Protecting pushes with secret scanning](/code-security/secret-scanning/protecting-pushes-with-secret-scanning)."
327            #[allow(non_snake_case)]
328            #[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
329            pub struct SecretScanningPushProtection<'a> {
330                /// Can be `enabled` or `disabled`.
331                #[serde(skip_serializing_if = "Option::is_none", default)]
332                pub status: ::std::option::Option<::std::borrow::Cow<'a, str>>,
333
334                #[serde(flatten)]
335                pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
336            }
337        }
338    }
339
340    #[cfg(feature = "hyper")]
341    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
342        type Error = crate::v1_1_4::ApiError;
343
344        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
345            Ok(
346                Self::new(::serde_json::to_vec(value)?.into())
347                .with_content_type(&b"application/json"[..])
348            )
349        }
350    }
351
352    #[cfg(feature = "reqwest")]
353    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
354        type Error = crate::v1_1_4::ApiError;
355
356        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
357            Ok(
358                Self::new(::serde_json::to_vec(value)?.into())
359                .with_content_type(&b"application/json"[..])
360            )
361        }
362    }
363
364    #[cfg(feature = "reqwest-blocking")]
365    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
366        type Error = crate::v1_1_4::ApiError;
367
368        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
369            Ok(
370                Self::new(::serde_json::to_vec(value)?.into())
371                .with_content_type(&b"application/json"[..])
372            )
373        }
374    }
375}