Skip to content

Commit

Permalink
Cargo Clippy; Add Workflow to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
umesh-timalsina committed Jul 13, 2024
1 parent 163bd60 commit 430d9e5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
pull_request:
branches:
- main
release:
types:
- published

env:
CARGO_TERM_COLOR: always
Expand All @@ -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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions src/srt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ pub fn srt(converter: &DeepgramConverter, line_length: Option<u8>) -> 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
Expand Down
13 changes: 6 additions & 7 deletions tests/test_dg_transcriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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::<Vec<&str>>();
let lines = caption.split('\n').collect::<Vec<&str>>();
assert!(
lines[0] == (index + 1).to_string(),
"Entry number is incorrect: {}",
Expand All @@ -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]
);
Expand All @@ -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
);
Expand All @@ -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",
]
Expand All @@ -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::<Vec<&str>>();
assert!(
Expand Down

0 comments on commit 430d9e5

Please sign in to comment.