#![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 GitClient {
inner: HttpInner,
}
impl GitClient {
pub fn new(inner: HttpInner) -> Self {
Self { inner }
}
pub async fn create_blob(
&self,
repo: String,
body: &crate::models::PostBlobForm,
) -> Result<crate::models::Blob> {
let path = format!("/{}/-/git/blobs", repo);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<crate::models::Blob, _>(Method::POST, url, body)
.await
}
pub async fn create_branch(
&self,
repo: String,
body: &crate::models::CreateBranchForm,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/branches", repo);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<serde_json::Value, _>(Method::POST, url, body)
.await
}
pub async fn create_branch_lock(
&self,
repo: String,
branch: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/branch-locks/{}", repo, branch);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::POST, url)
.await
}
pub async fn create_tag(
&self,
repo: String,
body: &crate::models::PostTagFrom,
) -> Result<crate::models::Tag> {
let path = format!("/{}/-/git/tags", repo);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<crate::models::Tag, _>(Method::POST, url, body)
.await
}
pub async fn delete_branch(&self, repo: String, branch: String) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/branches/{}", repo, branch);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn delete_branch_lock(
&self,
repo: String,
branch: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/branch-locks/{}", repo, branch);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn delete_commit_annotation(
&self,
repo: String,
sha: String,
key: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/commit-annotations/{}/{}", repo, sha, key);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn delete_commit_asset(
&self,
repo: String,
sha1: String,
asset_id: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/commit-assets/{}/{}", repo, sha1, asset_id);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn delete_tag(&self, repo: String, tag: String) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/tags/{}", repo, tag);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn delete_tag_annotation(
&self,
repo: String,
tag_with_key: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/tag-annotations/{}", repo, tag_with_key);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::DELETE, url)
.await
}
pub async fn get_archive(
&self,
repo: String,
ref_with_path: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/archive/{}", repo, ref_with_path);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::GET, url)
.await
}
pub async fn get_archive_commit_changed_files(
&self,
repo: String,
sha1: String,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/archive-commit-changed-files/{}", repo, sha1);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::GET, url)
.await
}
pub async fn get_archive_compare_changed_files(
&self,
repo: String,
base_head: String,
) -> Result<serde_json::Value> {
let path = format!(
"/{}/-/git/archive-compare-changed-files/{}",
repo, base_head
);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<serde_json::Value>(Method::GET, url)
.await
}
pub async fn get_branch(
&self,
repo: String,
branch: String,
) -> Result<crate::models::BranchDetail> {
let path = format!("/{}/-/git/branches/{}", repo, branch);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<crate::models::BranchDetail>(Method::GET, url)
.await
}
pub async fn get_commit(&self, repo: String, ref_: String) -> Result<crate::models::Commit> {
let path = format!("/{}/-/git/commits/{}", repo, ref_);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<crate::models::Commit>(Method::GET, url)
.await
}
pub async fn get_commit_annotations(
&self,
repo: String,
sha: String,
) -> Result<Vec<crate::models::CommitAnnotation>> {
let path = format!("/{}/-/git/commit-annotations/{}", repo, sha);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<Vec<crate::models::CommitAnnotation>>(Method::GET, url)
.await
}
pub async fn get_commit_annotations_in_batch(
&self,
repo: String,
body: &crate::models::GetCommitAnnotationsInBatchForm,
) -> Result<Vec<crate::models::CommitAnnotationInBatch>> {
let path = format!("/{}/-/git/commit-annotations-in-batch", repo);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<Vec<crate::models::CommitAnnotationInBatch>, _>(
Method::POST,
url,
body,
)
.await
}
pub async fn get_commit_assets(
&self,
repo: String,
commit_id: String,
filename: String,
query: &GetCommitAssetsQuery,
) -> Result<serde_json::Value> {
let path = format!(
"/{}/-/commit-assets/download/{}/{}",
repo, commit_id, filename
);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(v) = query.share {
pairs.append_pair("share", &v.to_string());
}
drop(pairs);
}
self.inner
.execute::<serde_json::Value>(Method::GET, url)
.await
}
pub async fn get_commit_assets_by_sha(
&self,
repo: String,
sha1: String,
) -> Result<Vec<crate::models::CommitAsset>> {
let path = format!("/{}/-/git/commit-assets/{}", repo, sha1);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<Vec<crate::models::CommitAsset>>(Method::GET, url)
.await
}
pub async fn get_commit_statuses(
&self,
repo: String,
commitish: String,
) -> Result<Vec<crate::models::CommitStatus>> {
let path = format!("/{}/-/git/commit-statuses/{}", repo, commitish);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<Vec<crate::models::CommitStatus>>(Method::GET, url)
.await
}
pub async fn get_compare_commits(
&self,
repo: String,
base_head: String,
) -> Result<crate::models::CompareResponse> {
let path = format!("/{}/-/git/compare/{}", repo, base_head);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<crate::models::CompareResponse>(Method::GET, url)
.await
}
pub async fn get_content(
&self,
repo: String,
file_path: String,
query: &GetContentQuery,
) -> Result<crate::models::Content> {
let path = format!("/{}/-/git/contents/{}", repo, file_path);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(ref v) = query.ref_ {
pairs.append_pair("ref", v);
}
drop(pairs);
}
self.inner
.execute::<crate::models::Content>(Method::GET, url)
.await
}
pub async fn get_content_without_path(
&self,
repo: String,
query: &GetContentWithoutPathQuery,
) -> Result<crate::models::Content> {
let path = format!("/{}/-/git/contents", repo);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(ref v) = query.ref_ {
pairs.append_pair("ref", v);
}
drop(pairs);
}
self.inner
.execute::<crate::models::Content>(Method::GET, url)
.await
}
pub async fn get_head(&self, repo: String) -> Result<crate::models::HeadRef> {
let path = format!("/{}/-/git/head", repo);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<crate::models::HeadRef>(Method::GET, url)
.await
}
pub async fn get_presigned_lfs_download_link(
&self,
slug: String,
oid: String,
query: &GetPresignedLFSDownloadLinkQuery,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/lfs/{}", slug, oid);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(ref v) = query.name {
pairs.append_pair("name", v);
}
drop(pairs);
}
self.inner
.execute::<serde_json::Value>(Method::GET, url)
.await
}
pub async fn get_raw(
&self,
repo: String,
ref_with_path: String,
query: &GetRawQuery,
) -> Result<String> {
let path = format!("/{}/-/git/raw/{}", repo, ref_with_path);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(v) = query.max_in_byte {
pairs.append_pair("max_in_byte", &v.to_string());
}
drop(pairs);
}
self.inner.execute::<String>(Method::GET, url).await
}
pub async fn get_tag(&self, repo: String, tag: String) -> Result<crate::models::Tag> {
let path = format!("/{}/-/git/tags/{}", repo, tag);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<crate::models::Tag>(Method::GET, url)
.await
}
pub async fn get_tag_annotations(
&self,
repo: String,
tag: String,
) -> Result<Vec<crate::models::TagAnnotation>> {
let path = format!("/{}/-/git/tag-annotations/{}", repo, tag);
let mut url = self.inner.url(&path)?;
self.inner
.execute::<Vec<crate::models::TagAnnotation>>(Method::GET, url)
.await
}
pub async fn list_branches(
&self,
repo: String,
query: &ListBranchesQuery,
) -> Result<Vec<crate::models::Branch>> {
let path = format!("/{}/-/git/branches", 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());
}
drop(pairs);
}
self.inner
.execute::<Vec<crate::models::Branch>>(Method::GET, url)
.await
}
pub async fn list_commits(
&self,
repo: String,
query: &ListCommitsQuery,
) -> Result<Vec<crate::models::Commit>> {
let path = format!("/{}/-/git/commits", repo);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(ref v) = query.sha {
pairs.append_pair("sha", v);
}
if let Some(ref v) = query.author {
pairs.append_pair("author", v);
}
if let Some(ref v) = query.committer {
pairs.append_pair("committer", v);
}
if let Some(ref v) = query.since {
pairs.append_pair("since", v);
}
if let Some(ref v) = query.until {
pairs.append_pair("until", v);
}
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());
}
drop(pairs);
}
self.inner
.execute::<Vec<crate::models::Commit>>(Method::GET, url)
.await
}
pub async fn list_tags(
&self,
repo: String,
query: &ListTagsQuery,
) -> Result<Vec<crate::models::Tag>> {
let path = format!("/{}/-/git/tags", 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());
}
drop(pairs);
}
self.inner
.execute::<Vec<crate::models::Tag>>(Method::GET, url)
.await
}
pub async fn post_commit_asset_upload_confirmation(
&self,
repo: String,
sha1: String,
upload_token: String,
asset_path: String,
query: &PostCommitAssetUploadConfirmationQuery,
) -> Result<serde_json::Value> {
let path = format!(
"/{}/-/git/commit-assets/{}/asset-upload-confirmation/{}/{}",
repo, sha1, upload_token, asset_path
);
let mut url = self.inner.url(&path)?;
{
let mut pairs = url.query_pairs_mut();
if let Some(v) = query.ttl {
pairs.append_pair("ttl", &v.to_string());
}
drop(pairs);
}
self.inner
.execute::<serde_json::Value>(Method::POST, url)
.await
}
pub async fn post_commit_asset_upload_url(
&self,
repo: String,
sha1: String,
body: &crate::models::PostCommitAssetUploadUrlForm,
) -> Result<crate::models::CommitAssetUploadUrl> {
let path = format!("/{}/-/git/commit-assets/{}/asset-upload-url", repo, sha1);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<crate::models::CommitAssetUploadUrl, _>(Method::POST, url, body)
.await
}
pub async fn put_commit_annotations(
&self,
repo: String,
sha: String,
body: &crate::models::PutCommitAnnotationsForm,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/commit-annotations/{}", repo, sha);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
.await
}
pub async fn put_tag_annotations(
&self,
repo: String,
tag: String,
body: &crate::models::PutTagAnnotationsForm,
) -> Result<serde_json::Value> {
let path = format!("/{}/-/git/tag-annotations/{}", repo, tag);
let mut url = self.inner.url(&path)?;
self.inner
.execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
.await
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct GetCommitAssetsQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub share: Option<bool>,
}
impl GetCommitAssetsQuery {
pub fn new() -> Self {
Self::default()
}
pub fn share(mut self, v: impl Into<bool>) -> Self {
self.share = Some(v.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct GetContentQuery {
#[serde(rename = "ref", default, skip_serializing_if = "Option::is_none")]
pub ref_: Option<String>,
}
impl GetContentQuery {
pub fn new() -> Self {
Self::default()
}
pub fn ref_(mut self, v: impl Into<String>) -> Self {
self.ref_ = Some(v.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct GetContentWithoutPathQuery {
#[serde(rename = "ref", default, skip_serializing_if = "Option::is_none")]
pub ref_: Option<String>,
}
impl GetContentWithoutPathQuery {
pub fn new() -> Self {
Self::default()
}
pub fn ref_(mut self, v: impl Into<String>) -> Self {
self.ref_ = Some(v.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct GetPresignedLFSDownloadLinkQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}
impl GetPresignedLFSDownloadLinkQuery {
pub fn new() -> Self {
Self::default()
}
pub fn name(mut self, v: impl Into<String>) -> Self {
self.name = Some(v.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct GetRawQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_in_byte: Option<i64>,
}
impl GetRawQuery {
pub fn new() -> Self {
Self::default()
}
pub fn max_in_byte(mut self, v: impl Into<i64>) -> Self {
self.max_in_byte = Some(v.into());
self
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListBranchesQuery {
#[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>,
}
impl ListBranchesQuery {
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
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListCommitsQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sha: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub author: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub committer: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub since: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub until: Option<String>,
#[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>,
}
impl ListCommitsQuery {
pub fn new() -> Self {
Self::default()
}
pub fn sha(mut self, v: impl Into<String>) -> Self {
self.sha = Some(v.into());
self
}
pub fn author(mut self, v: impl Into<String>) -> Self {
self.author = Some(v.into());
self
}
pub fn committer(mut self, v: impl Into<String>) -> Self {
self.committer = Some(v.into());
self
}
pub fn since(mut self, v: impl Into<String>) -> Self {
self.since = Some(v.into());
self
}
pub fn until(mut self, v: impl Into<String>) -> Self {
self.until = Some(v.into());
self
}
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
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListTagsQuery {
#[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>,
}
impl ListTagsQuery {
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
}
}
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct PostCommitAssetUploadConfirmationQuery {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ttl: Option<i64>,
}
impl PostCommitAssetUploadConfirmationQuery {
pub fn new() -> Self {
Self::default()
}
pub fn ttl(mut self, v: impl Into<i64>) -> Self {
self.ttl = Some(v.into());
self
}
}