This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "aether-gitea"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "Gitea API client for Aether tools"
|
||||
|
||||
[[bin]]
|
||||
name = "aether-gitea"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
gitea = "0.2"
|
||||
tokio = "0.2"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
anyhow = "1"
|
||||
@@ -0,0 +1,102 @@
|
||||
use clap::Parser;
|
||||
|
||||
const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "aether-gitea")]
|
||||
#[command(about = "Gitea API client for Aether tools")]
|
||||
struct Cli {
|
||||
#[arg(long, default_value = "https://space.seodr.ovh")]
|
||||
url: String,
|
||||
|
||||
#[arg(long, short)]
|
||||
token: Option<String>,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
enum Commands {
|
||||
/// Show Gitea server version
|
||||
Version,
|
||||
/// Show current user info
|
||||
Whoami,
|
||||
/// List all user repositories
|
||||
List,
|
||||
/// Show repository details
|
||||
Repo {
|
||||
/// Repository owner
|
||||
owner: String,
|
||||
/// Repository name
|
||||
name: String,
|
||||
},
|
||||
/// Create a new repository
|
||||
CreateRepo {
|
||||
/// Repository name
|
||||
name: String,
|
||||
/// Description
|
||||
#[arg(long)]
|
||||
description: Option<String>,
|
||||
/// Private repo
|
||||
#[arg(long)]
|
||||
private: bool,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let token = cli.token.or_else(|| std::env::var("GITEA_TOKEN").ok());
|
||||
|
||||
let client = match &token {
|
||||
Some(tok) => gitea::Client::new(cli.url.clone(), tok.clone(), APP_USER_AGENT)?,
|
||||
None => {
|
||||
eprintln!("Error: GITEA_TOKEN is required.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let mut rt = tokio::runtime::Runtime::new()?;
|
||||
|
||||
match &cli.command {
|
||||
Commands::Version => {
|
||||
let version = rt.block_on(client.version())?;
|
||||
println!("{}", version.version);
|
||||
}
|
||||
Commands::Whoami => {
|
||||
let user = rt.block_on(client.whoami())?;
|
||||
println!("User: {} (id: {})", user.login, user.id);
|
||||
println!("Email: {}", user.email);
|
||||
println!("Full name: {}", user.full_name);
|
||||
}
|
||||
Commands::Repo { owner, name } => {
|
||||
let repo = rt.block_on(client.get_repo(owner.clone(), name.clone()))?;
|
||||
println!("Repository: {}", repo.full_name);
|
||||
println!("URL: {}", repo.html_url);
|
||||
println!("Description: {}", repo.description);
|
||||
println!("Visibility: {}", if repo.private { "private" } else { "public" });
|
||||
println!("Stars: {}", repo.stars_count);
|
||||
println!("Forks: {}", repo.forks_count);
|
||||
println!("Default branch: {}", repo.default_branch);
|
||||
println!("Clone: {}", repo.clone_url);
|
||||
println!("SSH: {}", repo.ssh_url);
|
||||
}
|
||||
Commands::CreateRepo { name, description, private } => {
|
||||
let input = gitea::CreateRepo {
|
||||
name: name.clone(),
|
||||
description: description.clone().unwrap_or_default(),
|
||||
private: *private,
|
||||
..Default::default()
|
||||
};
|
||||
let repo = rt.block_on(client.create_user_repo(input))?;
|
||||
println!("Created: {}", repo.full_name);
|
||||
println!("URL: {}", repo.html_url);
|
||||
}
|
||||
Commands::List => {
|
||||
eprintln!("list: not yet implemented via this crate");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user