Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

The gitea client that all gitea calls will go through. This wraps reqwest::Client and operates asyncronously.

Implementations§

Source§

impl Client

Source

pub fn new<T>(base_url: String, token: String, user_agent: T) -> Result<Self>
where T: Into<String>,

Create a new API client with the given base URL, token and user agent. If you need inspiration for a user agent, try this:

const APP_USER_AGENT: &'static str =
   concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), APP_USER_AGENT).unwrap();
Source

pub async fn version(&self) -> Result<Version>

Gets the current version of gitea.

use gitea::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let cli = gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), "test/test")?;
    println!("{:?}", cli.version().await?);
    Ok(())
}
Source

pub async fn get_release_by_tag( &self, owner: String, repo: String, tag: String, ) -> Result<Release>

Gets a release of a repo by its tag name.

use gitea::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let cli = gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), "test/test")?;
    let release = cli.get_release_by_tag("cadey".into(), "gitea-release".into(), "0.3.2".into()).await;
    Ok(())
}
Source

pub async fn create_user_repo(&self, cr: CreateRepo) -> Result<Repo>

Creates a new gitea repo for the currently authenticated user with given details.

Source

pub async fn create_org_repo(&self, org: String, cr: CreateRepo) -> Result<Repo>

Creates a new gitea repo for a given organization with given details.

Source

pub async fn delete_repo(&self, owner: String, repo: String) -> Result<()>

Deletes a gitea repo by owner and name.

Source

pub async fn get_repo(&self, owner: String, repo: String) -> Result<Repo>

Gets a gitea repo by name.

use gitea::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let cli = gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), "test/test")?;
    let repo = cli.get_repo("cadey".into(), "gitea-release".into()).await;
    Ok(())
}
Source

pub async fn get_releases( &self, owner: String, repo: String, ) -> Result<Vec<Release>>

Gets all of the releases for a given gitea repo.

use gitea::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let cli = gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), "test/test")?;
    let repo = cli.get_releases("cadey".into(), "gitea-release".into()).await;
    Ok(())
}
Source

pub async fn create_release( &self, owner: String, repo: String, cr: CreateRelease, ) -> Result<Release>

Creates a new gitea release.

use gitea::{CreateRelease, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let cli = gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), "test/test")?;
    let repo = cli.create_release(
        "cadey".into(),
        "gitea-release".into(),
        CreateRelease{
            body: "This is a cool release".into(),
            draft: false,
            name: "test".into(),
            prerelease: false,
            tag_name: "v4.2.0".into(),
            target_commitish: "HEAD".into(),
        },
    ).await;
    Ok(())
}
Source

pub async fn delete_release( &self, owner: String, repo: String, tag: String, ) -> Result<()>

Deletes a given release by tag name.

use gitea::Result;

#[tokio::main]
async fn main() -> Result<()> {
    let cli = gitea::Client::new("https://tulpa.dev".into(), "ayylmao".into(), "test/test")?;
    let _ = cli.delete_release("cadey".into(), "gitea-release".into(), "4.2.0".into()).await;
    Ok(())
}
Source

pub async fn whoami(&self) -> Result<User>

Returns information about the currently authenticated user.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,