#![allow(clippy::all)]
#![allow(missing_docs)]
#![allow(unused_imports)]
#![allow(unused_mut)]
use reqwest::Method;
use serde::Serialize;
use crate::error::{ApiError, Result};
use crate::http::HttpInner;
use crate::models;
#[derive(Debug, Clone)]
pub struct RepoLabelsClient {
inner: HttpInner,
}
impl RepoLabelsClient {
pub fn new(inner: HttpInner) -> Self {
Self { inner }
}
pub async fn delete_label(&self, repo: String, name: String) -> Result<serde_json::Value> {
let path = format!("/{}/-/labels/{}", repo, name);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn list_labels(
&self,
repo: String,
query: &ListLabelsQuery,
) -> Result<Vec<crate::models::Label>> {
let path = format!("/{}/-/labels", repo);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(v) = query.page {
pairs.append_pair("page", &v.to_string());
}
if let Some(v) = query.page_size {
pairs.append_pair("page_size", &v.to_string());
}
if let Some(ref v) = query.keyword {
pairs.append_pair("keyword", v);
}
drop(pairs);
}
self.inner
.execute::<Vec<crate::models::Label>>(Method::GET, url)
.await
}
pub async fn patch_label(
&self,
repo: String,
name: String,
body: &crate::models::PatchLabelForm,
) -> Result<crate::models::Label> {
let path = format!("/{}/-/labels/{}", repo, name);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<crate::models::Label, _>(Method::PATCH, url, body)
.await
}
pub async fn post_label(
&self,
repo: String,
body: &crate::models::PostLabelForm,
) -> Result<crate::models::Label> {
let path = format!("/{}/-/labels", repo);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<crate::models::Label, _>(Method::POST, url, body)
.await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListLabelsQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub page_size: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub keyword: Option<String>,
}
impl ListLabelsQuery {
pub fn new() -> Self {
Self::default()
}
pub fn page(mut self, v: impl Into<i64>) -> Self {
self.page = Some(v.into());
self
}
pub fn page_size(mut self, v: impl Into<i64>) -> Self {
self.page_size = Some(v.into());
self
}
pub fn keyword(mut self, v: impl Into<String>) -> Self {
self.keyword = Some(v.into());
self
}
}