gitea-sdk-rs 0.1.0

Rust SDK for the Gitea API
Documentation

gitea-sdk-rs

Crates.io docs.rs CI License: MIT MSRV

中文文档

An async Rust SDK for the Gitea REST API, with full coverage of repositories, issues, pull requests, organizations, users, admin operations, and more.

Installation

Add this to your Cargo.toml:

[dependencies]
gitea-sdk-rs = "0.1.0"

Feature Flags

Feature Description
rustls-tls Use rustls for TLS (default)
native-tls Use the system native TLS backend
stream Enable streaming response support

Quick Start

use gitea_sdk_rs::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::builder("https://gitea.example.com")
        .token("your-token-here")
        .build()?;

    let (user, _) = client.users().get_my_info().await?;
    println!("Logged in as: {}", user.user_name);

    Ok(())
}

More examples are in the examples/ directory:

cargo run --example basic_usage
cargo run --example authentication

API Overview

Repository Management

ReposApi — Full repository lifecycle and contents management.

  • CRUDcreate_repo, get_repo, edit_repo, delete_repo, search_repos
  • Brancheslist_branches, create_branch, delete_branch, list_branch_protections
  • Tagslist_tags, create_tag, delete_tag, list_tag_protections
  • Filesget_contents, create_file, update_file, delete_file, get_raw_file
  • Collaboratorslist_collaborators, add_collaborator, get_collaborator_permission
  • Commitslist_commits, get_single_commit, compare_commits
  • Actionslist_action_secrets, list_action_variables, create_action_secret
  • Wikicreate_wiki_page, get_wiki_page, edit_wiki_page, list_wiki_pages
  • Misclist_forks, create_fork, mirror_sync, transfer_repo, get_archive

ReleasesApi — Releases and attachments.

  • list, create, edit, delete, get_by_tag, list_attachments, create_attachment

Issues & Pull Requests

IssuesApi — Full issue tracking with rich metadata.

  • CRUDlist_repo_issues, create_issue, edit_issue, delete_issue
  • Commentslist_issue_comments, create_issue_comment, edit_issue_comment
  • Labelsget_issue_labels, add_issue_labels, replace_issue_labels
  • Milestoneslist_repo_milestones, create_milestone, edit_milestone
  • Reactionspost_issue_reaction, post_issue_comment_reaction
  • Dependencieslist_issue_dependencies, create_issue_dependency
  • Time Trackingadd_time, list_issue_tracked_times, list_my_tracked_times
  • Subscriptionslist_issue_subscribers, add_issue_subscription
  • Pinslist_repo_pinned_issues, pin_issue, unpin_issue

PullsApi — Pull request workflow.

  • CRUDlist, get, create, edit
  • Mergemerge, is_merged, patch, diff
  • Reviewslist_reviews, create_review, submit_review, dismiss_review
  • Fileslist_commits, list_files

Users & Organizations

UsersApi — User profiles, keys, and social features.

  • Profileget, get_my_info, search, get_settings, update_settings
  • Keyslist_public_keys, create_public_key, list_gpg_keys, create_gpg_key
  • Socialfollow, unfollow, list_followers, block_user, unblock_user
  • Emaillist_emails, add_email, delete_email
  • Tokenslist_access_tokens, create_access_token, delete_access_token

OrgsApi — Organization and team management.

  • CRUDlist_orgs, create_org, edit_org, delete_org
  • Teamslist_org_teams, create_team, add_team_member, add_team_repo
  • Memberslist_org_membership, set_public_org_membership
  • Labelslist_org_labels, create_org_label
  • Actionslist_org_action_secrets, list_org_action_variables
  • Blockslist_org_blocks, block_org_user, unblock_org_user

System & Administration

AdminApi — Server administration (requires admin privileges).

  • Userslist_users, create_user, edit_user, delete_user
  • Orgslist_orgs, create_org_for_user
  • Cronlist_cron_tasks, run_cron_task
  • Hookslist_hooks, create_hook, edit_hook
  • Reposlist_unadopted_repos, adopt_unadopted_repo
  • Badgeslist_user_badges, add_user_badges

SettingsApiget_api_settings, get_repo_settings, get_ui_settings

MiscApiget_version, render_markdown, list_gitignore_templates, list_license_templates, get_signing_key_gpg

Other Modules

Module Description
HooksApi Webhook management for repos, orgs, and users
NotificationsApi Notification inbox and read status
ActionsApi Gitea Actions workflow runs and jobs
PackagesApi Package registry management
Oauth2Api OAuth2 application management
StatusApi Commit status (CI/CD integration)
ActivityPubApi ActivityPub federation endpoints

Authentication

use gitea_sdk_rs::Client;

// Personal access token
let client = Client::builder("https://gitea.example.com")
    .token("your-token-here")
    .build()?;

// Username and password
let client = Client::builder("https://gitea.example.com")
    .basic_auth("username", "password")
    .build()?;

// Token with two-factor OTP
let client = Client::builder("https://gitea.example.com")
    .token("your-token-here")
    .otp("123456")
    .build()?;

// Act as another user (sudo)
let client = Client::builder("https://gitea.example.com")
    .token("your-token-here")
    .sudo("target-username")
    .build()?;

The client is thread-safe and supports swapping credentials at runtime via set_token(), set_basic_auth(), set_otp(), and set_sudo().

Pagination

List endpoints accept option structs that embed pagination parameters:

use gitea_sdk_rs::ListOptions;
use gitea_sdk_rs::options::repo::ListReposOptions;

let opts = ListReposOptions {
    list_options: ListOptions {
        page: Some(1),
        page_size: Some(50),
    },
};
let (repos, _) = client.repos().list_my_repos(opts).await?;

Set page to Some(0) to disable pagination and fetch all results at once.

Error Handling

All API methods return Result<(T, Response)> where T is the deserialized response body and Response contains HTTP status, headers, and pagination links.

use gitea_sdk_rs::{Client, Error};

async fn example(client: &Client) {
    match client.repos().get_repo("owner", "repo").await {
        Ok((repo, response)) => {
            println!("Repo: {}", repo.name);
            println!("Status: {}", response.status);
        }
        Err(Error::Http(status, msg)) => {
            eprintln!("HTTP {status}: {msg}");
        }
        Err(e) => {
            eprintln!("Error: {e}");
        }
    }
}

Minimum Rust Version

Requires Rust 1.88 or later (edition 2024).

License

Licensed under the MIT License.

Links