From 430d9e512b40453fb1ba024dbdf57cf637a88126 Mon Sep 17 00:00:00 2001 From: Umesh Timalsina Date: Sat, 13 Jul 2024 14:44:10 -0500 Subject: [PATCH] Cargo Clippy; Add Workflow to publish --- .github/workflows/CI.yaml | 14 ++++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/converters.rs | 2 +- src/srt.rs | 10 +++++----- tests/test_dg_transcriptions.rs | 13 ++++++------- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 191f321..bb7f372 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -7,6 +7,9 @@ on: pull_request: branches: - main + release: + types: + - published env: CARGO_TERM_COLOR: always @@ -22,3 +25,14 @@ jobs: - name: Run Tests run: | cargo test --verbose + + - name: Run Clippy + run: | + cargo clippy --all-targets --all-features -- -D warnings + + - name: Publish to Crates.io + if: github.event_name == 'release' + run: | + cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }} + cargo publish + diff --git a/Cargo.lock b/Cargo.lock index ed68c30..3eee139 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -199,7 +199,7 @@ dependencies = [ [[package]] name = "deepgram-rust-captions" -version = "0.1.0" +version = "0.0.0" dependencies = [ "chrono", "deepgram", diff --git a/Cargo.toml b/Cargo.toml index b901365..5f48170 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "deepgram-rust-captions" -version = "0.1.0" +version = "0.0.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/converters.rs b/src/converters.rs index f58c982..0c1d1fe 100644 --- a/src/converters.rs +++ b/src/converters.rs @@ -17,7 +17,7 @@ impl DeepgramConverter { } /// Create a new DeepgramConverter from a JSON string. - pub fn from_str(json_response: &str) -> Self { + pub fn from_json_response(json_response: &str) -> Self { let dg_response: DeepgramResponse = serde_json::from_str(json_response).unwrap(); Self::new(&dg_response) } diff --git a/src/srt.rs b/src/srt.rs index d95c875..acb0737 100644 --- a/src/srt.rs +++ b/src/srt.rs @@ -24,11 +24,11 @@ pub fn srt(converter: &DeepgramConverter, line_length: Option) -> String { output.push(format!("{} --> {}", start_time, end_time)); - if first_word.speaker.is_some() { - if current_speaker.is_none() || current_speaker != first_word.speaker { - current_speaker = first_word.speaker; - output.push(format!("[speaker {}]", current_speaker.unwrap())); - } + if first_word.speaker.is_some() + && (current_speaker.is_none() || current_speaker != first_word.speaker) + { + current_speaker = first_word.speaker; + output.push(format!("[speaker {}]", current_speaker.unwrap())); } let punctuated_words = words diff --git a/tests/test_dg_transcriptions.rs b/tests/test_dg_transcriptions.rs index 609e1f4..5785e00 100644 --- a/tests/test_dg_transcriptions.rs +++ b/tests/test_dg_transcriptions.rs @@ -3,7 +3,7 @@ mod tests { use deepgram_rust_captions::{converters::DeepgramConverter, srt::srt}; use regex::Regex; - const FILE_PATHS_ALL: &'static [&'static str] = &[ + const FILE_PATHS_ALL: &[&str] = &[ "tests/files/dg_speakers.json", "tests/files/dg_speakers_no_utterances.json", "tests/files/dg_transcription.json", @@ -16,11 +16,10 @@ mod tests { result .split("\n\n") - .into_iter() .enumerate() .for_each(|(index, caption)| { if !caption.trim().is_empty() { - let lines = caption.split("\n").collect::>(); + let lines = caption.split('\n').collect::>(); assert!( lines[0] == (index + 1).to_string(), "Entry number is incorrect: {}", @@ -31,7 +30,7 @@ mod tests { let re = Regex::new(timestamp_pattern).expect("Failed to create regex pattern"); assert!( - re.is_match(&lines[1]), + re.is_match(lines[1]), "Timestamp format is incorrect: {}", &lines[1] ); @@ -58,7 +57,7 @@ mod tests { let result = srt(&dg_response, None); let first_caption = result.split("\n\n").next().unwrap(); assert!( - first_caption.starts_with("1"), + first_caption.starts_with('1'), "First caption does not start with 1: {}", first_caption ); @@ -67,7 +66,7 @@ mod tests { #[test] fn test_srt_speaker_format() { - vec![ + [ "tests/files/dg_speakers.json", "tests/files/dg_speakers_no_utterances.json", ] @@ -76,7 +75,7 @@ mod tests { .for_each(|dg_response| { let result = srt(&dg_response, None); let speaker_lines = result - .split("\n") + .split('\n') .filter(|line| line.starts_with("[speaker")) .collect::>(); assert!(