jinxapi_github/v1_1_4/request/
repos_generate_release_notes.rs

1//! Generate release notes content for a release
2//! 
3//! Generate a name and body describing a [release](https://docs.github.com/rest/reference/repos#releases). The body content will be markdown formatted and contain information like the changes since last release and users who contributed. The generated release notes are not saved anywhere. They are intended to be generated and used when creating a new release.
4//! 
5//! [API method documentation](https://docs.github.com/rest/reference/repos#generate-release-notes)
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() + 50);
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("/releases/generate-notes");
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::post(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::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_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::POST, 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::repos_generate_release_notes`]
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 tag name for the release. This can be an existing tag or a new one.
207        pub tag_name: ::std::borrow::Cow<'a, str>,
208
209        /// Specifies the commitish value that will be the target for the release's tag. Required if the supplied tag_name does not reference an existing tag. Ignored if the tag_name already exists.
210        #[serde(skip_serializing_if = "Option::is_none", default)]
211        pub target_commitish: ::std::option::Option<::std::borrow::Cow<'a, str>>,
212
213        /// The name of the previous tag to use as the starting point for the release notes. Use to manually specify the range for the set of changes considered as part this release.
214        #[serde(skip_serializing_if = "Option::is_none", default)]
215        pub previous_tag_name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
216
217        /// Specifies a path to a file in the repository containing configuration settings used for generating the release notes. If unspecified, the configuration file located in the repository at '.github/release.yml' or '.github/release.yaml' will be used. If that is not present, the default configuration will be used.
218        #[serde(skip_serializing_if = "Option::is_none", default)]
219        pub configuration_file_path: ::std::option::Option<::std::borrow::Cow<'a, str>>,
220
221        #[serde(flatten)]
222        pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
223    }
224
225    #[cfg(feature = "hyper")]
226    impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
227        type Error = crate::v1_1_4::ApiError;
228
229        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
230            Ok(
231                Self::new(::serde_json::to_vec(value)?.into())
232                .with_content_type(&b"application/json"[..])
233            )
234        }
235    }
236
237    #[cfg(feature = "reqwest")]
238    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
239        type Error = crate::v1_1_4::ApiError;
240
241        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
242            Ok(
243                Self::new(::serde_json::to_vec(value)?.into())
244                .with_content_type(&b"application/json"[..])
245            )
246        }
247    }
248
249    #[cfg(feature = "reqwest-blocking")]
250    impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
251        type Error = crate::v1_1_4::ApiError;
252
253        fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
254            Ok(
255                Self::new(::serde_json::to_vec(value)?.into())
256                .with_content_type(&b"application/json"[..])
257            )
258        }
259    }
260}