use std::fmt;
use serde::Serialize;
use radicle_surf::vcs::git::Browser;
use crate::error::Error;
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub struct Tag(pub(crate) String);
impl From<String> for Tag {
fn from(name: String) -> Self {
Self(name)
}
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
pub fn tags(browser: &Browser<'_>) -> Result<Vec<Tag>, Error> {
let tag_names = browser.list_tags()?;
let mut tags: Vec<Tag> = tag_names
.into_iter()
.map(|tag_name| Tag(tag_name.name().to_string()))
.collect();
tags.sort();
Ok(tags)
}