feat: with tags command

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-07-30 14:09:51 +02:00
parent 120865f72c
commit 62cafa4a9e
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 37 additions and 10 deletions

View File

@ -14,6 +14,7 @@ use crate::{
git_client::VcsClient,
gitea_client::GiteaClient,
ui::{ConsoleUi, DynUi},
versioning::semver::get_most_significant_version,
};
#[derive(Parser)]
@ -180,14 +181,32 @@ impl Command {
client.connect(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("connected succesfully go gitea");
}
GiteaCommand::Tags {} => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("got tags from gitea");
for tag in tags {
self.ui.write_str_ln(&format!("- {}", tag.name))
GiteaCommand::Tags { command } => match command {
Some(GiteaTagsCommand::MostSignificant {}) => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
match get_most_significant_version(tags.iter().collect()) {
Some(tag) => {
self.ui.write_str_ln(&format!(
"found most significant tags: {}",
tag.name
));
}
None => {
self.ui.write_str_ln("found no tags with versioning schema");
}
}
}
}
None => {
let tags = client
.get_tags(self.global.owner.unwrap(), self.global.repo.unwrap())?;
self.ui.write_str_ln("got tags from gitea");
for tag in tags {
self.ui.write_str_ln(&format!("- {}", tag.name))
}
}
},
GiteaCommand::SinceCommit { sha, branch } => {
let commits = client.get_commits_since(
self.global.owner.unwrap(),
@ -269,7 +288,10 @@ enum ConfigCommand {
#[derive(Subcommand, Debug, Clone)]
enum GiteaCommand {
Connect {},
Tags {},
Tags {
#[command(subcommand)]
command: Option<GiteaTagsCommand>,
},
SinceCommit {
#[arg(long)]
sha: String,
@ -279,6 +301,11 @@ enum GiteaCommand {
},
}
#[derive(Subcommand, Debug, Clone)]
enum GiteaTagsCommand {
MostSignificant {},
}
fn get_current_path(
optional_current_dir: Option<&Path>,
optional_source_path: Option<PathBuf>,

View File

@ -3,8 +3,8 @@ use std::cmp::Reverse;
use crate::gitea_client::{Commit, Tag};
use semver::Version;
pub fn get_most_significant_version<'a>(commits: Vec<&'a Tag>) -> Option<&'a Tag> {
let mut versions: Vec<(&'a Tag, Version)> = commits
pub fn get_most_significant_version<'a>(tags: Vec<&'a Tag>) -> Option<&'a Tag> {
let mut versions: Vec<(&'a Tag, Version)> = tags
.into_iter()
.filter_map(|c| {
if let Some(version) = c.name.trim_start_matches("v").parse::<Version>().ok() {