/
basuev
/
gverse
Обзор
Документация
Войти
/
basuev
/
gverse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/api/orgs.rs
103 строки
3 KB
basuev
initial commit: gverse v0.1.0
27 май 2026, 08:52
27 май 2026, 08:52
98b24dd
Код
Авторство
О чём код?
use crate::api::split_repo; use crate::client::Client; use crate::config::Config; use crate::error::Result; use crate::output::{Format, print_value}; use clap::Subcommand; use reqwest::Method; #[derive(Subcommand, Debug)] pub enum OrgsCmd { MemberCheck { org: String, username: String, }, #[command(subcommand)] Teams(TeamsCmd), } #[derive(Subcommand, Debug)] pub enum TeamsCmd { List { org: String, #[arg(long)] page: Option<u32>, #[arg(long)] limit: Option<u32>, }, Members { org: String, team: String, #[arg(long)] page: Option<u32>, #[arg(long)] limit: Option<u32>, }, AddRepo { org: String, team: String, repo: String, }, } pub async fn run(cmd: OrgsCmd, cfg: &Config, profile: Option<&str>, fmt: Format) -> Result<()> { let p = cfg.active_profile(profile)?; let client = Client::new(p)?; match cmd { OrgsCmd::MemberCheck { org, username } => { let v = client .get_value(&format!("/orgs/{org}/members/{username}"), &[]) .await?; print_value(fmt, &v); Ok(()) } OrgsCmd::Teams(t) => teams(&client, t, fmt).await, } } async fn teams(client: &Client, cmd: TeamsCmd, fmt: Format) -> Result<()> { match cmd { TeamsCmd::List { org, page, limit } => { let mut q: Vec<(&str, String)> = Vec::new(); if let Some(v) = page { q.push(("page", v.to_string())); } if let Some(v) = limit { q.push(("limit", v.to_string())); } let v = client.get_value(&format!("/orgs/{org}/teams"), &q).await?; print_value(fmt, &v); Ok(()) } TeamsCmd::Members { org, team, page, limit, } => { let mut q: Vec<(&str, String)> = Vec::new(); if let Some(v) = page { q.push(("page", v.to_string())); } if let Some(v) = limit { q.push(("limit", v.to_string())); } let v = client .get_value(&format!("/orgs/{org}/teams/{team}/members"), &q) .await?; print_value(fmt, &v); Ok(()) } TeamsCmd::AddRepo { org, team, repo } => { let (owner, name) = split_repo(&repo)?; client .send_empty( Method::PUT, &format!("/orgs/{org}/teams/{team}/repos/{owner}/{name}"), ) .await?; eprintln!("added `{owner}/{name}` to team `{team}` in org `{org}`"); Ok(()) } } }