|
- use serde::{Deserialize, Serialize};
- use reqwest::blocking;
-
- pub const GITEA_API_URL: &str = "https://git.exmods.org/api/v1";
-
- // API endpoints
- pub fn get_releases(owner: &str, repo: &str) -> Result<Vec<Release>, String> {
- let client = blocking::Client::new();
- let url = format!("{}/repos/{}/{}/releases", GITEA_API_URL, owner, repo);
- let result = client.get(&url).send();
- if let Ok(resp) = result {
- let status = resp.status();
- if !status.is_success() {
- return Err(format!("{} {}", status.as_str(), status.canonical_reason().unwrap_or("???")));
- }
- let result = resp.json::<Vec<Release>>();
- if let Ok(data) = result {
- return Ok(data);
- } else {
- return Err(format!("Invalid JSON payload {}", result.err().unwrap()));
- }
- }
- Err("Invalid Result".to_string())
- }
-
- pub fn get_issue_by_index(owner: &str, repo: &str, index: usize) -> Result<Issue, String> {
- let client = blocking::Client::new();
- let url = format!("{}/repos/{}/{}/issues/{}", GITEA_API_URL, owner, repo, index);
- let result = client.get(&url).send();
- if let Ok(resp) = result {
- let status = resp.status();
- if !status.is_success() {
- return Err(format!("{} {}", status.as_str(), status.canonical_reason().unwrap_or("???")));
- }
- let result = resp.json::<Issue>();
- if let Ok(data) = result {
- return Ok(data);
- } else {
- return Err(format!("Invalid JSON payload {}", result.err().unwrap()));
- }
- }
- Err("Invalid Result".to_string())
- }
-
- // API structures
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct Release {
- pub id: usize,
- pub tag_name: String,
- pub target_commitish: String,
- pub name: String,
- pub body: String,
- pub url: String,
- pub tarball_url: String,
- pub zipball_url: String,
- pub draft: bool,
- pub prerelease: bool,
- pub created_at: String,
- pub published_at: String,
- pub author: Author,
- pub assets: Option<Vec<Asset>>,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct Author {
- pub id: usize,
- pub login: String,
- pub full_name: String,
- pub email: String,
- pub avatar_url: String,
- pub language: String,
- pub is_admin: bool,
- pub last_login: String,
- pub created: String,
- pub username: String,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct Asset {
- pub id: usize,
- pub name: String,
- pub size: usize,
- pub download_count: usize,
- pub created_at: String,
- pub uuid: String,
- pub browser_download_url: String,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct Issue {
- pub id: usize,
- pub url: String,
- pub html_url: String,
- pub number: usize,
- pub user: Author,
- pub original_author: String,
- pub original_author_id: usize,
- pub title: String,
- pub body: String,
- pub labels: Vec<IssueTag>,
- //pub milestone: Option<???>,
- //pub assignee: Option<???>,
- //pub assignees: Option<???>,
- pub state: String,
- pub comments: usize,
- pub created_at: String,
- pub updated_at: String,
- pub closed_at: Option<String>,
- pub due_date: Option<String>,
- //pub pull_request: Option<???>,
- pub repository: IssueRespository,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct IssueTag {
- pub id: usize,
- pub name: String,
- pub color: String,
- pub description: String,
- pub url: Option<String>,
- }
-
- #[derive(Serialize, Deserialize, Clone)]
- pub struct IssueRespository {
- pub id: usize,
- pub name: String,
- pub full_name: String,
- }
|