Struct User

Source
pub struct User;

Implementations§

Source§

impl User

Source

pub fn current(&self) -> GetAuthenticatedUserBuilder

Gets the currently authenticated user. This will return a User object representing the currently authenticated user. As long as the token is valid, this method will always return a user.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let user = client
    .user()
    .current()
    .send(&client)
    .await
    .unwrap();
Source

pub fn create_repo(&self, name: impl ToString) -> CreateRepoBuilder

Creates a new repository for the authenticated user.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let repo = client
    .user()
    .create_repo("my-new-repo")
    .private(true)
    .send(&client)
    .await
    .unwrap();

This will create a new private repository with the name “my-new-repo” for the authenticated user.

Source

pub fn list_repos(&self) -> ListReposBuilder

Lists all repositories for the authenticated user. This will return a list of all Repository objects owned by the authenticated user.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let repos = client
    .user()
    .list_repos()
    .limit(10)
    .page(2)
    .send(&client)
    .await
    .unwrap();
Source

pub fn orgs(&self) -> Orgs

List the current user’s organizations.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let orgs = client
    .user()
    .orgs()
    .page(2)
    .limit(10)
    .send(&client)
    .await
    .unwrap();
Source

pub fn create_access_token( &self, user: impl ToString, name: impl ToString, scopes: Vec<impl ToString>, ) -> CreateAccessTokenBuilder

Creates a new access token for a user. NOTE: This endpoint requires basic authentication and will fail otherwise.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Basic("username", "password")
);
let token = client
    .user()
    .create_access_token("username", "my-new-token", vec!["write:repository", "read:user"])
    .send(&client)
    .await
    .unwrap();
println!("Token {} created: {}", token.name, token.sha1);
let new_client = Client::new(
    "https://gitea.example.com",
    Auth::Token(token.sha1)
);

This will create a new token with the name “my-new-token”, which can read all user data and read and write to repositories.

If the token is successfully created, this method will return a [AccessToken] object. If the user is not authenticated correctly (e.g. not using basic auth), this method will return a 403 status code. In case of any client-side errors, this method will return a 400 status code.

Source

pub fn list_access_tokens( &self, username: impl ToString, ) -> ListAccessTokensBuilder

Lists all access tokens for a user. NOTE: This endpoint requires basic authentication and will fail otherwise.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Basic("username", "password")
);
let tokens = client
    .user()
    .list_access_tokens("username")
    .send(&client)
    .await
    .unwrap();

This will list all access tokens for the user “username”.

Source

pub fn delete_access_token( &self, user: impl ToString, token: impl ToString, ) -> DeleteAccessTokenBuilder

Deletes an access token by its username and token. This will delete the token and revoke all permissions associated with it. NOTE: This endpoint requires basic authentication and will fail otherwise.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Basic("username", "password")
);
client.
    user()
    .delete_access_token("username", "token")
    .send(&client)
    .await
    .unwrap();

This will delete the token with the name “token-name” for the user “username”.

If the token does not exist, this method will return a 404 status code. If the target user is not the authenticated user and the authenticated user is not an administrator, this method will return a 403 status code. For any client-side other errors, this method will return a 422 status code. If the token is successfully deleted, this method will return a 204 status code.

Source

pub fn get_settings(&self) -> GetSettingsBuilder

Gets the current user’s settings.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let settings = client
    .user()
    .get_settings()
    .send(&client)
    .await
    .unwrap();
println!("User settings: {:?}", settings);
Source

pub fn update_settings(&self) -> UpdateSettingsBuilder

Updates the current user’s settings.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let settings = client
    .user()
    .update_settings()
    .theme("dark")
    .send(&client)
    .await
    .unwrap();
println!("User settings: {:?}", settings);

This will update the user’s theme to “dark”.

Source

pub fn list_starred(&self) -> ListStarredBuilder

Lists all repositories starred by the authenticated user.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let repos = client
    .user()
    .list_starred()
    .send(&client)
    .await
    .unwrap();
Source

pub fn is_starred( &self, owner: impl ToString, repo: impl ToString, ) -> IsStarredBuilder

Checks if the authenticated user has starred a repository.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
let starred = client
    .user()
    .is_starred("owner", "repo")
    .send(&client)
    .await
    .unwrap();
if starred {
    println!("You have starred this repo!");
} else {
    println!("You have not starred this repo.");
}
Source

pub fn star_repo( &self, owner: impl ToString, repo: impl ToString, ) -> StarRepoBuilder

Stars a repository for the authenticated user. This will star the repository with the given owner and name.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
client
    .user()
    .star_repo("owner", "repo")
    .send(&client)
    .await
    .unwrap();

This will star the repository “repo” owned by “owner”.

Source

pub fn unstar_repo( &self, owner: impl ToString, repo: impl ToString, ) -> UnstarRepoBuilder

Unstars a repository for the authenticated user. This will unstar the repository with the given owner and name.

§Example
let client = Client::new(
    "https://gitea.example.com",
    Auth::Token("your-token")
);
client
    .user()
    .unstar_repo("owner", "repo")
    .send(&client)
    .await
    .unwrap();

Auto Trait Implementations§

§

impl Freeze for User

§

impl RefUnwindSafe for User

§

impl Send for User

§

impl Sync for User

§

impl Unpin for User

§

impl UnwindSafe for User

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, 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,

Source§

impl<T> MaybeSendSync for T