Skip to content

Commit f778597

Browse files
committed
fix formatting
1 parent 90b1001 commit f778597

File tree

3 files changed

+55
-38
lines changed

3 files changed

+55
-38
lines changed

src/lib.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::process::Command;
21
use log::debug;
2+
use std::process::Command;
33

44
pub 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-
102108
fn 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")

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use std::io::Write;
21
use clap::Parser;
3-
use clap_verbosity_flag::{Verbosity};
4-
use log::{info};
2+
use clap_verbosity_flag::Verbosity;
53
use env_logger::{Builder, Target};
4+
use log::info;
5+
use std::io::Write;
66

77
#[macro_use]
88
extern crate log;
99

1010
/// Search for a pattern in a file and display the lines that contain it.
11-
#[derive(Debug,Parser)]
11+
#[derive(Debug, Parser)]
1212
struct Cli {
1313
#[command(flatten)]
1414
verbose: Verbosity,
@@ -38,11 +38,12 @@ struct Cli {
3838
commit: bool,
3939
}
4040

41-
fn main() {
41+
fn main() {
4242
let args = Cli::parse();
4343

4444
let mut builder = Builder::from_default_env();
45-
builder.target(Target::Stdout)
45+
builder
46+
.target(Target::Stdout)
4647
.filter_level(args.verbose.log_level_filter())
4748
.init();
4849
debug!("Starting up");
@@ -77,5 +78,4 @@ fn main() {
7778
let mut file = std::fs::File::create(output_path).unwrap();
7879
file.write_all(next_tag.as_bytes()).unwrap();
7980
}
80-
8181
}

src/tests/integration_test.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ fn return_next_tag() -> Result<(), Box<dyn std::error::Error>> {
3838
.arg(project_root_dir)
3939
.arg("-vvv");
4040

41-
cmd.assert().success().stdout(predicate::str::contains("v0.1.1"));
41+
cmd.assert()
42+
.success()
43+
.stdout(predicate::str::contains("v0.1.1"));
4244
Ok(())
4345
}
4446

@@ -51,21 +53,27 @@ fn return_next_tag_zero_if_none() -> Result<(), Box<dyn std::error::Error>> {
5153
.arg(".")
5254
.arg("-vvv");
5355

54-
cmd.assert().success().stdout(predicate::str::contains("100.0.0"));
56+
cmd.assert()
57+
.success()
58+
.stdout(predicate::str::contains("100.0.0"));
5559
Ok(())
5660
}
5761

5862
#[test]
5963
fn fail_on_missing_base_tag() -> Result<(), Box<dyn std::error::Error>> {
6064
let mut cmd = Command::cargo_bin("git-next-tag")?;
61-
cmd.assert().failure().stderr(predicate::str::contains("the following required arguments were not provided"));
65+
cmd.assert().failure().stderr(predicate::str::contains(
66+
"the following required arguments were not provided",
67+
));
6268
Ok(())
6369
}
6470

6571
#[test]
6672
fn fail_with_no_arguments() -> Result<(), Box<dyn std::error::Error>> {
6773
let mut cmd = Command::cargo_bin("git-next-tag")?;
68-
cmd.assert().failure().stderr(predicate::str::contains("Usage"));
74+
cmd.assert()
75+
.failure()
76+
.stderr(predicate::str::contains("Usage"));
6977
Ok(())
7078
}
7179

@@ -84,15 +92,15 @@ fn verify_prerelease_commit_suffix() -> Result<(), Box<dyn std::error::Error>> {
8492

8593
cmd.assert()
8694
.success()
87-
.stdout(predicate::str::contains("v0.1.1-")
88-
.and(predicate::function(|output: &str| {
95+
.stdout(
96+
predicate::str::contains("v0.1.1-").and(predicate::function(|output: &str| {
8997
// Check if the output contains a 7-character alphanumeric suffix after the version
90-
output.lines()
91-
.any(|line| {
92-
let parts: Vec<&str> = line.split('-').collect();
93-
parts.len() >= 2 && parts.last().unwrap().trim().len() == 7
94-
})
95-
})));
98+
output.lines().any(|line| {
99+
let parts: Vec<&str> = line.split('-').collect();
100+
parts.len() >= 2 && parts.last().unwrap().trim().len() == 7
101+
})
102+
})),
103+
);
96104
Ok(())
97105
}
98106

@@ -103,7 +111,7 @@ fn verify_prerelease_rc_suffix_scenarios() -> Result<(), Box<dyn std::error::Err
103111
// Scenario 1: New base tag, should get .0-rc-0
104112
let mut cmd = Command::cargo_bin("git-next-tag")?;
105113
cmd.arg("--baseTag")
106-
.arg("v0.3") // v0.1.0, and various v0.2.*-rc-* exist, but no v0.3.*-rc-* exists
114+
.arg("v0.3") // v0.1.0, and various v0.2.*-rc-* exist, but no v0.3.*-rc-* exists
107115
.arg("--path")
108116
.arg(&project_root_dir)
109117
.arg("--preRelease")
@@ -118,7 +126,7 @@ fn verify_prerelease_rc_suffix_scenarios() -> Result<(), Box<dyn std::error::Err
118126
// Scenario 2: Existing base tag without rc, should get .z+1-rc-0
119127
let mut cmd = Command::cargo_bin("git-next-tag")?;
120128
cmd.arg("--baseTag")
121-
.arg("v0.1") // v0.1.0, and various v0.2.*-rc-* exist
129+
.arg("v0.1") // v0.1.0, and various v0.2.*-rc-* exist
122130
.arg("--path")
123131
.arg(&project_root_dir)
124132
.arg("--preRelease")
@@ -133,7 +141,7 @@ fn verify_prerelease_rc_suffix_scenarios() -> Result<(), Box<dyn std::error::Err
133141
// Scenario 3: Existing tag with rc, should increment rc number
134142
let mut cmd = Command::cargo_bin("git-next-tag")?;
135143
cmd.arg("--baseTag")
136-
.arg("v0.2") // v0.2.0-rc-0, v0.2.0-rc-1, v0.2.1-rc-0 exist
144+
.arg("v0.2") // v0.2.0-rc-0, v0.2.0-rc-1, v0.2.1-rc-0 exist
137145
.arg("--path")
138146
.arg(&project_root_dir)
139147
.arg("--preRelease")
@@ -146,4 +154,4 @@ fn verify_prerelease_rc_suffix_scenarios() -> Result<(), Box<dyn std::error::Err
146154
.stdout(predicate::str::contains("v0.2.1-rc-1")); // Should increment only the rc number
147155

148156
Ok(())
149-
}
157+
}

0 commit comments

Comments
 (0)