Skip to content

Commit aeb01af

Browse files
committed
refactor: improve code readability and efficiency - replace deprecated methods with idiomatic alternatives in Git provider and update variable naming for clarity
1 parent 21f965f commit aeb01af

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn is_git_repository() -> bool {
1010
.stdout(Stdio::null())
1111
.stderr(Stdio::null())
1212
.status()
13-
.map_or(false, |status| status.success())
13+
.is_ok_and(|status| status.success())
1414
}
1515

1616
/// Gets the diff of staged files.

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::Parser;
22
use colored::*;
33
use question::{Answer, Question};
4-
use rustyline::{DefaultEditor, Result as RustyResult};
4+
use rustyline::DefaultEditor;
55
use spinners::{Spinner, Spinners};
66
use std::process::Command;
77

src/providers/anthropic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Analyze the git diff carefully and generate an appropriate conventional commit m
9494

9595
let text = anthropic_response
9696
.content
97-
.get(0)
97+
.first()
9898
.map(|c| &c.text)
9999
.ok_or("Invalid response structure from Anthropic".to_string())?;
100100

src/providers/gemini.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ Analyze the git diff carefully and generate an appropriate conventional commit m
107107

108108
let text = gemini_response
109109
.candidates
110-
.get(0)
111-
.and_then(|c| c.content.parts.get(0))
110+
.first()
111+
.and_then(|c| c.content.parts.first())
112112
.map(|p| &p.text)
113113
.ok_or("Invalid response structure from Gemini".to_string())?;
114114

src/providers/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl GeneratedCommit {
6565
}
6666

6767
/// Gets a summary of the commit for display
68+
#[allow(dead_code)]
6869
pub fn summary(&self) -> String {
6970
format!(
7071
"Type: {}, Files: {}",
@@ -74,6 +75,7 @@ impl GeneratedCommit {
7475
}
7576

7677
/// Extracts the commit type from the title
78+
#[allow(dead_code)]
7779
pub fn get_type(&self) -> String {
7880
if let Some(colon_pos) = self.title.find(':') {
7981
let prefix = &self.title[..colon_pos];
@@ -88,9 +90,9 @@ impl GeneratedCommit {
8890
}
8991
}
9092

91-
impl ToString for GeneratedCommit {
92-
fn to_string(&self) -> String {
93-
format!("{}\n\n{}", self.title, self.description)
93+
impl std::fmt::Display for GeneratedCommit {
94+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95+
write!(f, "{}\n\n{}", self.title, self.description)
9496
}
9597
}
9698

src/providers/openai.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl OpenAIProvider {
4444
#[async_trait]
4545
impl AIProvider for OpenAIProvider {
4646
async fn generate_commit_message(&self, diff: &str) -> Result<GeneratedCommit, String> {
47-
let parameters_schema = serde_json::to_value(schemars::schema_for!(Commit))
47+
let _parameters_schema = serde_json::to_value(schemars::schema_for!(Commit))
4848
.map_err(|e| format!("Failed to create schema: {}", e))?;
4949

5050
let system_prompt = "You are an expert programmer who writes git commit messages following the Conventional Commits specification (https://www.conventionalcommits.org/en/v1.0.0/).
@@ -97,7 +97,7 @@ Analyze the git diff carefully and generate an appropriate conventional commit m
9797

9898
let choice = response
9999
.choices
100-
.get(0)
100+
.first()
101101
.ok_or("No response choice from OpenAI".to_string())?;
102102

103103
let function_details = &choice

0 commit comments

Comments
 (0)