jinxapi_github/v1_1_4/request/
issues_create.rs

1//! Create an issue
2//! 
3//! Any user with pull access to a repository can create an issue. If [issues are disabled in the repository](https://docs.github.com/articles/disabling-issues/), the API returns a `410 Gone` status.
4//! 
5//! This endpoint triggers [notifications](https://docs.github.com/github/managing-subscriptions-and-notifications-on-github/about-notifications). Creating content too quickly using this endpoint may result in secondary rate limiting. See "[Secondary rate limits](https://docs.github.com/rest/overview/resources-in-the-rest-api#secondary-rate-limits)" and "[Dealing with secondary rate limits](https://docs.github.com/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits)" for details.
6//! 
7//! [API method documentation](https://docs.github.com/rest/reference/issues#create-an-issue)
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_owner: &str,
38    p_repo: &str,
39) -> Result<String, crate::v1_1_4::ApiError> {
40    let trimmed = if base_url.is_empty() {
41        "https://api.github.com"
42    } else {
43        base_url.trim_end_matches('/')
44    };
45    let mut url = String::with_capacity(trimmed.len() + 33);
46    url.push_str(trimmed);
47    url.push_str("/repos/");
48    ::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
49    url.push('/');
50    ::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
51    url.push_str("/issues");
52    Ok(url)
53}
54
55#[cfg(feature = "hyper")]
56pub fn http_builder(
57    base_url: &str,
58    p_owner: &str,
59    p_repo: &str,
60    h_user_agent: &str,
61    h_accept: ::std::option::Option<&str>,
62) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
63    let url = url_string(
64        base_url,
65        p_owner,
66        p_repo,
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_owner: &str,
105    p_repo: &str,
106    h_user_agent: &str,
107    h_accept: ::std::option::Option<&str>,
108) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
109    let url = url_string(
110        base_url,
111        p_owner,
112        p_repo,
113    )?;
114    let reqwest_url = ::reqwest::Url::parse(&url)?;
115    let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
116    let headers = request.headers_mut();
117    headers.append(
118        "User-Agent",
119        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
120    );
121    if let Some(value) = &h_accept {
122        headers.append(
123            "Accept",
124            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
125        );
126    }
127    Ok(request)
128}
129
130#[cfg(feature = "reqwest")]
131pub fn reqwest_request(
132    mut builder: ::reqwest::Request,
133    content: Content<::reqwest::Body>,
134) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
135    if let Some(content_type) = content.content_type() {
136        builder.headers_mut().append(
137            ::reqwest::header::HeaderName::from_static("content-type"),
138            ::reqwest::header::HeaderValue::try_from(content_type)?,
139        );
140    }
141    *builder.body_mut() = Some(content.into_body());
142    Ok(builder)
143}
144
145#[cfg(feature = "reqwest")]
146impl From<::reqwest::Body> for Content<::reqwest::Body> {
147    fn from(body: ::reqwest::Body) -> Self {
148        Self::new(body)
149    }
150}
151
152#[cfg(feature = "reqwest-blocking")]
153pub fn reqwest_blocking_builder(
154    base_url: &str,
155    p_owner: &str,
156    p_repo: &str,
157    h_user_agent: &str,
158    h_accept: ::std::option::Option<&str>,
159) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
160    let url = url_string(
161        base_url,
162        p_owner,
163        p_repo,
164    )?;
165    let reqwest_url = ::reqwest::Url::parse(&url)?;
166    let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
167    let headers = request.headers_mut();
168    headers.append(
169        "User-Agent",
170        ::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
171    );
172    if let Some(value) = &h_accept {
173        headers.append(
174            "Accept",
175            ::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
176        );
177    }
178    Ok(request)
179}
180
181#[cfg(feature = "reqwest-blocking")]
182pub fn reqwest_blocking_request(
183    mut builder: ::reqwest::blocking::Request,
184    content: Content<::reqwest::blocking::Body>,
185) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
186    if let Some(content_type) = content.content_type() {
187        builder.headers_mut().append(
188            ::reqwest::header::HeaderName::from_static("content-type"),
189            ::reqwest::header::HeaderValue::try_from(content_type)?,
190        );
191    }
192    *builder.body_mut() = Some(content.into_body());
193    Ok(builder)
194}
195
196#[cfg(feature = "reqwest-blocking")]
197impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
198    fn from(body: ::reqwest::blocking::Body) -> Self {
199        Self::new(body)
200    }
201}
202
203/// Types for body parameter in [`super::issues_create`]
204pub mod body {
205    #[allow(non_snake_case)]
206    #[derive(Clone, Eq, PartialEq, Debug, ::serde::Serialize, ::serde::Deserialize)]
207    pub struct Json<'a> {
208        /// The title of the issue.
209        pub title: ::serde_json::value::Value,
210
211        /// The contents of the issue.
212        #[serde(skip_serializing_if = "Option::is_none", default)]
213        pub body: ::std::option::Option<::std::borrow::Cow<'a, str>>,
214
215        /// Login for the user that this issue should be assigned to. _NOTE: Only users with push access can set the assignee for new issues. The assignee is silently dropped otherwise. **This field is deprecated.**_
216        #[serde(skip_serializing_if = "Option::is_none", default, deserialize_with = "crate::v1_1_4::support::deserialize_some")]
217        pub assignee: ::std::option::Option<::std::option::Option<::std::borrow::Cow<'a, str>>>,
218
219        #[serde(skip_serializing_if = "Option::is_none", default, deserialize_with = "crate::v1_1_4::support::deserialize_some")]
220        pub milestone: ::std::option::Option<::std::option::Option<::serde_json::value::Value>>,
221
222        /// Labels to associate with this issue. _NOTE: Only users with push access can set labels for new issues. Labels are silently dropped otherwise._
223        #[serde(skip_serializing_if = "Option::is_none", default)]
224        pub labels: ::std::option::Option<::std::borrow::Cow<'a, [::serde_json::value::Value]>>,
225
226        /// Logins for Users to assign to this issue. _NOTE: Only users with push access can set assignees for new issues. Assignees are silently dropped otherwise._
227        #[serde(skip_serializing_if = "Option::is_none", default)]
228        pub assignees: ::std::option::Option<::std::borrow::Cow<'a, [::std::borrow::Cow<'a, str>]>>,
229
230        #[serde(flatten)]
231        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
232    }
233
234    #[cfg(feature = "hyper")]
235    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
236        type Error = crate::v1_1_4::ApiError;
237
238        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
239            Ok(
240                Self::new(::serde_json::to_vec(value)?.into())
241                .with_content_type(&b"application/json"[..])
242            )
243        }
244    }
245
246    #[cfg(feature = "reqwest")]
247    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
248        type Error = crate::v1_1_4::ApiError;
249
250        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
251            Ok(
252                Self::new(::serde_json::to_vec(value)?.into())
253                .with_content_type(&b"application/json"[..])
254            )
255        }
256    }
257
258    #[cfg(feature = "reqwest-blocking")]
259    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
260        type Error = crate::v1_1_4::ApiError;
261
262        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
263            Ok(
264                Self::new(::serde_json::to_vec(value)?.into())
265                .with_content_type(&b"application/json"[..])
266            )
267        }
268    }
269}