diff --git a/src/main.rs b/src/main.rs index 8b4fd23..2693c93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,12 +29,16 @@ fn release(conf: &Config) -> Release { } } +fn is_tag(gitref: R) -> bool where R: AsRef { + gitref.as_ref().starts_with("refs/tags/") +} + fn run( conf: Config, releaser: &dyn Releaser, uploader: &dyn AssetUploader, ) -> Result<(), Box> { - if !conf.github_ref.starts_with("refs/tags/") { + if !is_tag(&conf.github_ref) { log::error!("GH Releases require a tag"); return Ok(()); } @@ -81,4 +85,14 @@ mod tests { } Ok(()) } + + #[test] + fn is_tag_checks_refs() { + for (gitref, expect) in &[ + ("refs/tags/foo", true), + ("refs/heads/master", false) + ] { + assert_eq!(is_tag(gitref), *expect) + } + } }