diff --git a/src/lib.rs b/src/lib.rs index 3108cec..ece927e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,36 +4,6 @@ pub mod cli; pub mod api; pub mod structs; -/// A struct matching a Gitea "Release" entry -#[derive(Debug, Deserialize, Serialize)] -pub struct ReleaseInfo { - id: usize, - tag_name: String, - target_commitish: String, - name: String, - body: String, - url: String, - html_url: String, - tarball_url: String, - zipball_url: String, - upload_url: String, - draft: bool, - prerelease: bool, - created_at: String, - published_at: String, - author: Author, -} - -#[derive(Debug, Deserialize, Serialize)] -pub struct Author { - id: usize, - login: String, - login_name: String, - source_id: usize, - full_name: String, - email: String, -} - #[derive(Debug, Serialize)] pub struct CreateReleaseOption { pub body: String, @@ -53,7 +23,7 @@ pub struct ApiError { #[derive(Debug, Deserialize, Serialize)] #[serde(untagged)] pub enum CreateResult { - Success(ReleaseInfo), + Success(structs::release::Release), ErrWithMessage(ApiError), Empty, } diff --git a/src/main.rs b/src/main.rs index 13d0085..8bf8356 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use gt_tools::CreateReleaseOption; -use gt_tools::{ReleaseInfo, cli::Args}; +use gt_tools::{structs::release::Release, cli::Args}; use reqwest::multipart::Part; use std::collections::HashMap; @@ -76,7 +76,7 @@ async fn do_list_releases( client: &reqwest::Client, gitea_url: &str, repo: &str, -) -> Result, Error> { +) -> Result, Error> { let request_url = format!( "{gitea_url}{front}{repo}{back}", front = API_RELEASE_FRONT, @@ -91,7 +91,7 @@ async fn do_list_releases( // TODO: Handle case with no releases. // afaict: Serde tries to unpack an empty list, can't decide what struct it's unpacking, // and emits an error. Desired behavior: empty Vec. - let body_text: Vec = response.json().await?; + let body_text: Vec = response.json().await?; return Ok(body_text); } diff --git a/src/structs/release.rs b/src/structs/release.rs index bc256b8..fb02db7 100644 --- a/src/structs/release.rs +++ b/src/structs/release.rs @@ -1,5 +1,33 @@ +use serde::{Deserialize, Serialize}; -pub struct Release; +#[derive(Debug, Deserialize, Serialize)] +pub struct Release { + id: usize, + tag_name: String, + target_commitish: String, + name: String, + body: String, + url: String, + html_url: String, + tarball_url: String, + zipball_url: String, + upload_url: String, + draft: bool, + prerelease: bool, + created_at: String, + published_at: String, + author: Author, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct Author { + id: usize, + login: String, + login_name: String, + source_id: usize, + full_name: String, + email: String, +} pub struct CreateReleaseOption;