//! Create a release
//!
//! Users with push access to the repository can create a release.
//!
//! This endpoint triggers [notifications](https://docs.github.com/en/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.
//!
//! [API method documentation](https://docs.github.com/rest/reference/repos#create-a-release)
pub struct Content<Body>
{
body: Body,
content_type_value: Option<::std::borrow::Cow<'static, [u8]>>,
}
impl<Body> Content<Body> {
pub fn new(body: Body) -> Self {
Self { body, content_type_value: None }
}
#[must_use]
pub fn with_content_type(mut self, content_type: impl Into<::std::borrow::Cow<'static, [u8]>>) -> Self {
self.content_type_value = Some(content_type.into());
self
}
fn content_type(&self) -> Option<&[u8]> {
self.content_type_value.as_deref()
}
fn into_body(self) -> Body {
self.body
}
}
fn url_string(
base_url: &str,
p_owner: &str,
p_repo: &str,
) -> Result<String, crate::v1_1_4::ApiError> {
let trimmed = if base_url.is_empty() {
"https://api.github.com"
} else {
base_url.trim_end_matches('/')
};
let mut url = String::with_capacity(trimmed.len() + 35);
url.push_str(trimmed);
url.push_str("/repos/");
::querylizer::Simple::extend(&mut url, &p_owner, false, &::querylizer::encode_path)?;
url.push('/');
::querylizer::Simple::extend(&mut url, &p_repo, false, &::querylizer::encode_path)?;
url.push_str("/releases");
Ok(url)
}
#[cfg(feature = "hyper")]
pub fn http_builder(
base_url: &str,
p_owner: &str,
p_repo: &str,
h_user_agent: &str,
h_accept: ::std::option::Option<&str>,
) -> Result<::http::request::Builder, crate::v1_1_4::ApiError> {
let url = url_string(
base_url,
p_owner,
p_repo,
)?;
let mut builder = ::http::request::Request::post(url);
builder = builder.header(
"User-Agent",
&::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?
);
if let Some(value) = &h_accept {
builder = builder.header(
"Accept",
&::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?
);
}
Ok(builder)
}
#[cfg(feature = "hyper")]
pub fn hyper_request(
mut builder: ::http::request::Builder,
content: Content<::hyper::Body>,
) -> Result<::http::request::Request<::hyper::Body>, crate::v1_1_4::ApiError>
{
if let Some(content_type) = content.content_type() {
builder = builder.header(::http::header::CONTENT_TYPE, content_type);
}
Ok(builder.body(content.into_body())?)
}
#[cfg(feature = "hyper")]
impl From<::hyper::Body> for Content<::hyper::Body> {
fn from(body: ::hyper::Body) -> Self {
Self::new(body)
}
}
#[cfg(feature = "reqwest")]
pub fn reqwest_builder(
base_url: &str,
p_owner: &str,
p_repo: &str,
h_user_agent: &str,
h_accept: ::std::option::Option<&str>,
) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
let url = url_string(
base_url,
p_owner,
p_repo,
)?;
let reqwest_url = ::reqwest::Url::parse(&url)?;
let mut request = ::reqwest::Request::new(::reqwest::Method::POST, reqwest_url);
let headers = request.headers_mut();
headers.append(
"User-Agent",
::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
);
if let Some(value) = &h_accept {
headers.append(
"Accept",
::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
);
}
Ok(request)
}
#[cfg(feature = "reqwest")]
pub fn reqwest_request(
mut builder: ::reqwest::Request,
content: Content<::reqwest::Body>,
) -> Result<::reqwest::Request, crate::v1_1_4::ApiError> {
if let Some(content_type) = content.content_type() {
builder.headers_mut().append(
::reqwest::header::HeaderName::from_static("content-type"),
::reqwest::header::HeaderValue::try_from(content_type)?,
);
}
*builder.body_mut() = Some(content.into_body());
Ok(builder)
}
#[cfg(feature = "reqwest")]
impl From<::reqwest::Body> for Content<::reqwest::Body> {
fn from(body: ::reqwest::Body) -> Self {
Self::new(body)
}
}
#[cfg(feature = "reqwest-blocking")]
pub fn reqwest_blocking_builder(
base_url: &str,
p_owner: &str,
p_repo: &str,
h_user_agent: &str,
h_accept: ::std::option::Option<&str>,
) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
let url = url_string(
base_url,
p_owner,
p_repo,
)?;
let reqwest_url = ::reqwest::Url::parse(&url)?;
let mut request = ::reqwest::blocking::Request::new(::reqwest::Method::POST, reqwest_url);
let headers = request.headers_mut();
headers.append(
"User-Agent",
::querylizer::Simple::to_string(&h_user_agent, false, &::querylizer::passthrough)?.try_into()?
);
if let Some(value) = &h_accept {
headers.append(
"Accept",
::querylizer::Simple::to_string(value, false, &::querylizer::passthrough)?.try_into()?
);
}
Ok(request)
}
#[cfg(feature = "reqwest-blocking")]
pub fn reqwest_blocking_request(
mut builder: ::reqwest::blocking::Request,
content: Content<::reqwest::blocking::Body>,
) -> Result<::reqwest::blocking::Request, crate::v1_1_4::ApiError> {
if let Some(content_type) = content.content_type() {
builder.headers_mut().append(
::reqwest::header::HeaderName::from_static("content-type"),
::reqwest::header::HeaderValue::try_from(content_type)?,
);
}
*builder.body_mut() = Some(content.into_body());
Ok(builder)
}
#[cfg(feature = "reqwest-blocking")]
impl From<::reqwest::blocking::Body> for Content<::reqwest::blocking::Body> {
fn from(body: ::reqwest::blocking::Body) -> Self {
Self::new(body)
}
}
/// Types for body parameter in [`super::repos_create_release`]
pub mod body {
#[allow(non_snake_case)]
#[derive(Clone, Eq, PartialEq, Debug, Default, ::serde::Serialize, ::serde::Deserialize)]
pub struct Json<'a> {
/// The name of the tag.
pub tag_name: ::std::borrow::Cow<'a, str>,
/// Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository's default branch (usually `master`).
#[serde(skip_serializing_if = "Option::is_none", default)]
pub target_commitish: ::std::option::Option<::std::borrow::Cow<'a, str>>,
/// The name of the release.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
/// Text describing the contents of the tag.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub body: ::std::option::Option<::std::borrow::Cow<'a, str>>,
/// `true` to create a draft (unpublished) release, `false` to create a published one.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub draft: ::std::option::Option<bool>,
/// `true` to identify the release as a prerelease. `false` to identify the release as a full release.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub prerelease: ::std::option::Option<bool>,
/// If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. For more information, see "[Managing categories for discussions in your repository](https://docs.github.com/discussions/managing-discussions-for-your-community/managing-categories-for-discussions-in-your-repository)."
#[serde(skip_serializing_if = "Option::is_none", default)]
pub discussion_category_name: ::std::option::Option<::std::borrow::Cow<'a, str>>,
/// Whether to automatically generate the name and body for this release. If `name` is specified, the specified name will be used; otherwise, a name will be automatically generated. If `body` is specified, the body will be pre-pended to the automatically generated notes.
#[serde(skip_serializing_if = "Option::is_none", default)]
pub generate_release_notes: ::std::option::Option<bool>,
#[serde(flatten)]
pub additionalProperties: ::std::collections::HashMap<::std::borrow::Cow<'a, str>, ::serde_json::value::Value>
}
#[cfg(feature = "hyper")]
impl<'a> TryFrom<&Json<'a>> for super::Content<::hyper::Body> {
type Error = crate::v1_1_4::ApiError;
fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
Ok(
Self::new(::serde_json::to_vec(value)?.into())
.with_content_type(&b"application/json"[..])
)
}
}
#[cfg(feature = "reqwest")]
impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::Body> {
type Error = crate::v1_1_4::ApiError;
fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
Ok(
Self::new(::serde_json::to_vec(value)?.into())
.with_content_type(&b"application/json"[..])
)
}
}
#[cfg(feature = "reqwest-blocking")]
impl<'a> TryFrom<&Json<'a>> for super::Content<::reqwest::blocking::Body> {
type Error = crate::v1_1_4::ApiError;
fn try_from(value: &Json<'a>) -> Result<Self, Self::Error> {
Ok(
Self::new(::serde_json::to_vec(value)?.into())
.with_content_type(&b"application/json"[..])
)
}
}
}