From fb22e94a9268b879a496de3101e8f85a37b5bde6 Mon Sep 17 00:00:00 2001 From: tornikegomareli Date: Mon, 18 Sep 2023 15:14:15 +0400 Subject: [PATCH 1/2] reformat with rustfmt --- src/argparser/arg_parser.rs | 17 +++++++++++----- src/argparser/mod.rs | 2 +- src/filereader/file_reader.rs | 2 +- src/filereader/mod.rs | 2 +- src/gitrunner/git_runner.rs | 6 +++--- src/gitrunner/git_runner_error.rs | 2 +- src/gitrunner/mod.rs | 4 ++-- src/gptrunner/gpt_runner.rs | 33 ++++++++++++++++++------------- src/gptrunner/mod.rs | 2 +- src/main.rs | 22 ++++++--------------- src/output_file_format.rs | 5 +++++ 11 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 src/output_file_format.rs diff --git a/src/argparser/arg_parser.rs b/src/argparser/arg_parser.rs index 115e864..e9a9a43 100644 --- a/src/argparser/arg_parser.rs +++ b/src/argparser/arg_parser.rs @@ -1,9 +1,16 @@ -use clap::{App, Arg}; -use chat_gpt_lib_rs::{Model}; use crate::git_log_format::GitLogFormat; +use chat_gpt_lib_rs::Model; +use clap::{App, Arg}; pub struct ArgParser {} impl ArgParser { - pub fn parse_args() -> (GitLogFormat, Option, Option, Option, Model, Option) { + pub fn parse_args() -> ( + GitLogFormat, + Option, + Option, + Option, + Model, + Option, + ) { let matches = App::new("releasecraftsman") .version("0.1.1") .arg( @@ -47,7 +54,7 @@ impl ArgParser { .short("v") .long("version") .takes_value(true) - .help("Version of the release") + .help("Version of the release"), ) .get_matches(); @@ -71,4 +78,4 @@ impl ArgParser { (log_format, start_tag, end_tag, api_key, model, version) } -} \ No newline at end of file +} diff --git a/src/argparser/mod.rs b/src/argparser/mod.rs index c85b2cf..b16e66d 100644 --- a/src/argparser/mod.rs +++ b/src/argparser/mod.rs @@ -1 +1 @@ -pub mod arg_parser; \ No newline at end of file +pub mod arg_parser; diff --git a/src/filereader/file_reader.rs b/src/filereader/file_reader.rs index fe6f7de..e31d4ed 100644 --- a/src/filereader/file_reader.rs +++ b/src/filereader/file_reader.rs @@ -1,8 +1,8 @@ +use include_dir::{include_dir, Dir}; use std::env; use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::Path; -use include_dir::{include_dir, Dir}; pub enum PromptType { GeneralMarkdown, GeneralJSON, diff --git a/src/filereader/mod.rs b/src/filereader/mod.rs index 4ca8f12..5470308 100644 --- a/src/filereader/mod.rs +++ b/src/filereader/mod.rs @@ -1 +1 @@ -pub mod file_reader; \ No newline at end of file +pub mod file_reader; diff --git a/src/gitrunner/git_runner.rs b/src/gitrunner/git_runner.rs index 45e1a0d..f440f61 100644 --- a/src/gitrunner/git_runner.rs +++ b/src/gitrunner/git_runner.rs @@ -1,7 +1,7 @@ -use std::env; -use std::process::Command; use crate::git_log_format::GitLogFormat; use crate::gitrunner::git_runner_error::GitRunnerError; +use std::env; +use std::process::Command; pub struct GitRunner {} @@ -51,4 +51,4 @@ impl GitRunner { Ok(output_str) } -} \ No newline at end of file +} diff --git a/src/gitrunner/git_runner_error.rs b/src/gitrunner/git_runner_error.rs index e28bf00..ba4731b 100644 --- a/src/gitrunner/git_runner_error.rs +++ b/src/gitrunner/git_runner_error.rs @@ -28,4 +28,4 @@ impl From for GitRunnerError { fn from(err: std::string::FromUtf8Error) -> GitRunnerError { GitRunnerError::Utf8Error(err) } -} \ No newline at end of file +} diff --git a/src/gitrunner/mod.rs b/src/gitrunner/mod.rs index 07fb883..6ce3e51 100644 --- a/src/gitrunner/mod.rs +++ b/src/gitrunner/mod.rs @@ -1,2 +1,2 @@ -pub mod git_runner; -pub mod git_runner_error; \ No newline at end of file +pub mod git_runner; +pub mod git_runner_error; diff --git a/src/gptrunner/gpt_runner.rs b/src/gptrunner/gpt_runner.rs index a37bc2f..4d63dfa 100644 --- a/src/gptrunner/gpt_runner.rs +++ b/src/gptrunner/gpt_runner.rs @@ -1,5 +1,5 @@ use chat_gpt_lib_rs::{ChatGPTClient, ChatInput, Message, Model, Role}; -use spinoff::{Spinner, spinners, Color, Streams}; +use spinoff::{spinners, Color, Spinner, Streams}; use std::io::Result; pub struct ChatGptRunner {} @@ -10,23 +10,28 @@ impl ChatGptRunner { let client = ChatGPTClient::new(api_key, base_url); - let chat_input = ChatInput { model, messages: vec![ - Message { - role: Role::System, - content: "You are a helpful assistant.".to_string(), - }, - Message { - role: Role::User, - content: message.to_string(), - }, - ], + let chat_input = ChatInput { + model, + messages: vec![ + Message { + role: Role::System, + content: "You are a helpful assistant.".to_string(), + }, + Message { + role: Role::User, + content: message.to_string(), + }, + ], ..Default::default() }; - - let mut spinner = Spinner::new(spinners::Moon, "Generating release notes... Please wait a while", Color::Red); + let mut spinner = Spinner::new( + spinners::Moon, + "Generating release notes... Please wait a while", + Color::Red, + ); let response = client.chat(chat_input).await.unwrap(); spinner.success("Release notes generated successfully"); Ok(response.choices[0].message.content.clone()) } -} \ No newline at end of file +} diff --git a/src/gptrunner/mod.rs b/src/gptrunner/mod.rs index 4610f03..4997ef4 100644 --- a/src/gptrunner/mod.rs +++ b/src/gptrunner/mod.rs @@ -1 +1 @@ -pub mod gpt_runner; \ No newline at end of file +pub mod gpt_runner; diff --git a/src/main.rs b/src/main.rs index 9f16841..64136b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,18 @@ -mod filereader; mod argparser; -mod gitrunner; +mod filereader; mod git_log_format; +mod gitrunner; mod gptrunner; -use filereader::file_reader::{FileReader, PromptType}; use argparser::arg_parser::ArgParser; -use std::str; +use filereader::file_reader::{FileReader, PromptType}; use gitrunner::git_runner::GitRunner; use gptrunner::gpt_runner::ChatGptRunner; use std::process; +use std::str; use crate::gitrunner::git_runner_error::GitRunnerError; - fn print_commits(commits: Vec<&str>) { for (_i, commit) in commits.iter().enumerate() { println!("{}", commit); @@ -33,37 +32,28 @@ async fn main() -> Result<(), GitRunnerError> { // Fetching git logs output_str = GitRunner::execute_git_log(&log_format, &repo_path, &start_tag, &end_tag)?; - }, + } Err(err) => { eprintln!("👷🏻‍ An error occurred ❌: {}", err); process::exit(1); } } - let commits: Vec<&str> = output_str.lines().collect(); - // Print commit logs (For debugging) print_commits(commits.clone()); let fr = FileReader::new(); let version_str = version.unwrap_or_else(|| "1.0.0".to_string()); - - // Convert commit logs Vec<&str> to a single String let commit_logs = commits.join("\n"); - // Choose a prompt type based on some criteria (here we're using GeneralMarkdown for demonstration) - // dynamically select this based on user input or other conditions let prompt_type = PromptType::GeneralMarkdown; - // Generate the final prompt string let final_prompt = fr.read_and_replace(prompt_type, &version_str, &commit_logs)?; - // Output the final prompt println!("Final Prompt: {}", final_prompt); - if let Some(api_key) = api_key { let base_url = "https://api.openai.com"; let gpt_response = ChatGptRunner::run_chat_gpt(&api_key, model, &final_prompt).await?; @@ -71,4 +61,4 @@ async fn main() -> Result<(), GitRunnerError> { } Ok(()) -} \ No newline at end of file +} diff --git a/src/output_file_format.rs b/src/output_file_format.rs new file mode 100644 index 0000000..0c949fb --- /dev/null +++ b/src/output_file_format.rs @@ -0,0 +1,5 @@ +pub struct OutputFileFormat {} + +impl OutputFileFormat { + +} \ No newline at end of file From c6d5298ea1be63fa679419e12216f98fc6973675 Mon Sep 17 00:00:00 2001 From: tornikegomareli Date: Mon, 18 Sep 2023 15:59:22 +0400 Subject: [PATCH 2/2] cleanup --- .rustfmt.toml | 1 + Cargo.toml | 2 +- src/main.rs | 3 --- 3 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..36c419b --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1 @@ +edition = "2021" \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 03ab929..be8831f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "releasecraftsman" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 64136b8..f032fa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,10 +26,7 @@ async fn main() -> Result<(), GitRunnerError> { let mut output_str: String = String::new(); match GitRunner::get_repo_path() { Ok(repo_path) => { - let repo_path = GitRunner::get_repo_path()?; - println!("Executing git log command in directory: {}", repo_path); - // Fetching git logs output_str = GitRunner::execute_git_log(&log_format, &repo_path, &start_tag, &end_tag)?; }