1- use std:: process:: Command ;
21use log:: debug;
2+ use std:: process:: Command ;
33
44pub enum VersionType {
55 Stable ,
@@ -25,15 +25,18 @@ pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Writ
2525 }
2626}
2727
28- pub fn determine_nex_tag ( next_tag_request : NextTagRequest ) -> Result < String , Box < dyn std:: error:: Error > > {
28+ pub fn determine_nex_tag (
29+ next_tag_request : NextTagRequest ,
30+ ) -> Result < String , Box < dyn std:: error:: Error > > {
2931 let completed_base_tag = format ! ( "{}.*" , next_tag_request. base_tag) ;
3032
3133 match next_tag_request. version_type {
3234 VersionType :: Stable => {
33- let tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) ) . expect ( "Could not list git tags" ) ;
35+ let tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) )
36+ . expect ( "Could not list git tags" ) ;
3437 if tags. is_empty ( ) {
3538 debug ! ( "Could not find tags, returning .0" ) ;
36- return Ok ( format ! ( "{}.0" , next_tag_request. base_tag) )
39+ return Ok ( format ! ( "{}.0" , next_tag_request. base_tag) ) ;
3740 }
3841 let last_tag = tags. last ( ) . unwrap ( ) ;
3942 let incremented_tag_result = increment_tag ( last_tag) ;
@@ -42,19 +45,21 @@ pub fn determine_nex_tag(next_tag_request: NextTagRequest) -> Result<String, Box
4245 }
4346 let incremented_tag = incremented_tag_result?;
4447 return Ok ( incremented_tag) ;
45- } ,
48+ }
4649 VersionType :: PreRelease => {
4750 let suffix = next_tag_request. suffix . unwrap ( ) ;
4851 let completed_base_tag = format ! ( "{}.*-{}-*" , next_tag_request. base_tag, suffix) ;
49- let mut tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) ) . expect ( "Could not list git tags" ) ;
52+ let mut tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) )
53+ . expect ( "Could not list git tags" ) ;
5054 let mut found_suffix_tag = false ;
5155 // if no tags are found for base tag + suffix, find the latest tag for base tag
5256 if tags. is_empty ( ) {
5357 let completed_base_tag = format ! ( "{}.*" , next_tag_request. base_tag) ;
54- tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) ) . expect ( "Could not list git tags" ) ;
58+ tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) )
59+ . expect ( "Could not list git tags" ) ;
5560 if tags. is_empty ( ) {
5661 debug ! ( "Could not find tags, returning .0" ) ;
57- return Ok ( format ! ( "{}.0-{}-0" , next_tag_request. base_tag, suffix) )
62+ return Ok ( format ! ( "{}.0-{}-0" , next_tag_request. base_tag, suffix) ) ;
5863 }
5964 } else {
6065 found_suffix_tag = true ;
@@ -79,26 +84,27 @@ pub fn determine_nex_tag(next_tag_request: NextTagRequest) -> Result<String, Box
7984 let incremented_tag = incremented_tag_result?;
8085 return Ok ( format ! ( "{}-{}-0" , incremented_tag, suffix) ) ;
8186 }
82- } ,
87+ }
8388 VersionType :: PreReleaseCommit => {
84- let tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) ) . expect ( "Could not list git tags" ) ;
89+ let tags = query_git_tags ( & completed_base_tag, next_tag_request. path . as_str ( ) )
90+ . expect ( "Could not list git tags" ) ;
8591 if tags. is_empty ( ) {
8692 debug ! ( "Could not find tags, returning .0" ) ;
87- return Ok ( format ! ( "{}.0" , next_tag_request. base_tag) )
93+ return Ok ( format ! ( "{}.0" , next_tag_request. base_tag) ) ;
8894 }
8995 let last_tag = tags. last ( ) . unwrap ( ) ;
9096 let incremented_tag_result = increment_tag ( last_tag) ;
9197 if incremented_tag_result. is_err ( ) {
9298 return Err ( incremented_tag_result. err ( ) . unwrap ( ) ) ;
9399 }
94100 let incremented_tag = incremented_tag_result?;
95- let commit_sha = get_current_commit_sha ( next_tag_request. path . as_str ( ) ) . expect ( "Could not get commit sha" ) ;
101+ let commit_sha = get_current_commit_sha ( next_tag_request. path . as_str ( ) )
102+ . expect ( "Could not get commit sha" ) ;
96103 return Ok ( format ! ( "{}-{}" , incremented_tag, commit_sha) ) ;
97104 }
98105 }
99106}
100107
101-
102108fn get_current_commit_sha ( path : & str ) -> Result < String , Box < dyn std:: error:: Error > > {
103109 let output = Command :: new ( "git" )
104110 . arg ( "rev-parse" )
@@ -112,7 +118,7 @@ fn get_current_commit_sha(path: &str) -> Result<String, Box<dyn std::error::Erro
112118 Ok ( stdout. trim ( ) . to_string ( ) )
113119}
114120
115- fn increment_tag ( latest_found_tag : & String ) -> Result < String , Box < dyn std:: error:: Error > > {
121+ fn increment_tag ( latest_found_tag : & String ) -> Result < String , Box < dyn std:: error:: Error > > {
116122 debug ! ( "Incrementing found tag: {}" , latest_found_tag) ;
117123 let mut p1 = latest_found_tag. split ( '.' ) ;
118124 let major = p1. next ( ) . unwrap ( ) ;
@@ -126,7 +132,10 @@ fn increment_tag(latest_found_tag: &String) -> Result<String, Box<dyn std::erro
126132 Ok ( format ! ( "{}.{}.{}" , major, minor, patch) )
127133}
128134
129- pub fn query_git_tags ( base_tag : & str , path : & str ) -> Result < Vec < String > , Box < dyn std:: error:: Error > > {
135+ pub fn query_git_tags (
136+ base_tag : & str ,
137+ path : & str ,
138+ ) -> Result < Vec < String > , Box < dyn std:: error:: Error > > {
130139 let output = Command :: new ( "git" )
131140 . arg ( "--no-pager" )
132141 . arg ( "tag" )
0 commit comments