-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rework check command output and commit parsing
- Loading branch information
Showing
6 changed files
with
324 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use anyhow::Result; | ||
use colored::*; | ||
use std::process::{Command, Stdio}; | ||
|
||
#[derive(Debug, Deserialize, Serialize, Clone)] | ||
pub struct Hook { | ||
pub command: String, | ||
} | ||
|
||
impl Hook { | ||
pub(crate) fn run(&self) -> Result<()> { | ||
let command_display = format!("`{}`", &self.command.green()); | ||
println!("Running pre-version hook : {}", command_display); | ||
|
||
Command::new(self.command.clone()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.stdin(Stdio::inherit()) | ||
.output() | ||
.map_err(|err| anyhow!(err)) | ||
.map(|_| ()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::hook::Hook; | ||
|
||
#[test] | ||
fn should_run_command() { | ||
// Arrange | ||
let hook = Hook { | ||
command: "echo hello world".to_string(), | ||
}; | ||
|
||
// Act | ||
let result = hook.run(); | ||
|
||
// Assert | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[test] | ||
fn should_fail_to_run_invalid_command() { | ||
// Arrange | ||
let hook = Hook { | ||
command: "azmroih".to_string(), | ||
}; | ||
|
||
// Act | ||
let result = hook.run(); | ||
|
||
// Assert | ||
assert!(result.is_err()); | ||
} | ||
} |
Oops, something went wrong.