use async_trait::async_trait; use chrono::prelude::*; use gritea::{ client::{resp_json, Gritea}, Result, }; use http::Method; use serde::Deserialize; #[derive(Deserialize, Debug)] pub struct PayloadUser { pub email: String, pub name: String, pub username: String, } #[derive(Deserialize, Debug)] pub struct PayloadCommitVerification { pub payload: String, pub reason: String, pub signature: String, pub signer: Option, pub verified: bool, } #[derive(Deserialize, Debug)] pub struct PayloadCommit { pub added: Option>, pub author: PayloadUser, pub committer: PayloadUser, pub id: String, pub message: String, pub modified: Option>, pub removed: Option>, pub timestamp: DateTime, pub url: String, pub verfification: Option, } #[derive(Deserialize, Debug)] pub struct Branch { pub commit: PayloadCommit, pub effective_branch_protection_name: String, pub enable_status_check: bool, pub name: String, pub protected: bool, pub required_approvals: i64, pub status_check_contexts: Vec, pub user_can_merge: bool, pub user_can_push: bool, } #[async_trait] pub trait GriteaExt { async fn get_repo_branches(&self, owner: &str, repo: &str) -> Result>; } #[async_trait] impl GriteaExt for Gritea { async fn get_repo_branches(&self, owner: &str, repo: &str) -> Result> { let resp = self .request(Method::GET, &format!("repos/{}/{}/branches", owner, repo))? .send() .await?; resp_json(resp, "get repo branches failed").await } }