69 lines
1.7 KiB
Rust
69 lines
1.7 KiB
Rust
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<PayloadUser>,
|
|
pub verified: bool,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct PayloadCommit {
|
|
pub added: Option<Vec<String>>,
|
|
pub author: PayloadUser,
|
|
pub committer: PayloadUser,
|
|
pub id: String,
|
|
pub message: String,
|
|
pub modified: Option<Vec<String>>,
|
|
pub removed: Option<Vec<String>>,
|
|
pub timestamp: DateTime<Utc>,
|
|
pub url: String,
|
|
pub verfification: Option<PayloadCommitVerification>,
|
|
}
|
|
|
|
#[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<String>,
|
|
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<Vec<Branch>>;
|
|
}
|
|
|
|
#[async_trait]
|
|
impl GriteaExt for Gritea {
|
|
async fn get_repo_branches(&self, owner: &str, repo: &str) -> Result<Vec<Branch>> {
|
|
let resp = self
|
|
.request(Method::GET, &format!("repos/{}/{}/branches", owner, repo))?
|
|
.send()
|
|
.await?;
|
|
|
|
resp_json(resp, "get repo branches failed").await
|
|
}
|
|
}
|