Basic impl Display for the Release struct

I'm not certain what info I want to present when listing the Releases.

The idea is that the release version is the most important, and that it
matches the git-tag associated with the release. I'll print that first.

Next, the name of the release followed by the body text. The list of
releases will become quite large for some projects, and the body text
may include a changelog. Both of these will cause the output to become
quite large. I will need to create a size limiter, but I'm ignoring that
for now.

Who created the release and when may be useful when searching for a
release, so I've included that as the final section.
This commit is contained in:
2025-07-02 12:56:17 -05:00
parent 136c051c82
commit 135acf09b7
2 changed files with 28 additions and 1 deletions

View File

@@ -34,7 +34,7 @@ async fn main() -> Result<(), gt_tool::Error> {
let releases =
gt_tool::api::release::list_releases(&client, &args.gitea_url, &args.repo).await?;
for release in releases {
println!("{:?}", release);
println!("{}", release);
}
}
gt_tool::cli::Commands::CreateRelease {

View File

@@ -1,3 +1,5 @@
use std::fmt::Display;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
@@ -19,6 +21,31 @@ pub struct Release {
author: Author,
}
impl Display for Release {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let body = if self.body.len() > 0 {
&self.body
} else {
&String::from("(empty body)")
};
write!(f,
"Tag: {}
Name: {}
{}
Published: {} (created: {})
Author: {} ({})
",
self.tag_name,
self.name,
body,
self.published_at,
self.created_at,
self.author.login,
self.author.email,
)
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct Author {
id: usize,