Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat with rustfmt #9

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
edition = "2021"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/argparser/arg_parser.rs
Original file line number Diff line number Diff line change
@@ -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<String>, Option<String>, Option<String>, Model, Option<String>) {
pub fn parse_args() -> (
GitLogFormat,
Option<String>,
Option<String>,
Option<String>,
Model,
Option<String>,
) {
let matches = App::new("releasecraftsman")
.version("0.1.1")
.arg(
Expand Down Expand Up @@ -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();

Expand All @@ -71,4 +78,4 @@ impl ArgParser {

(log_format, start_tag, end_tag, api_key, model, version)
}
}
}
2 changes: 1 addition & 1 deletion src/argparser/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod arg_parser;
pub mod arg_parser;
2 changes: 1 addition & 1 deletion src/filereader/file_reader.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/filereader/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod file_reader;
pub mod file_reader;
6 changes: 3 additions & 3 deletions src/gitrunner/git_runner.rs
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down Expand Up @@ -51,4 +51,4 @@ impl GitRunner {

Ok(output_str)
}
}
}
2 changes: 1 addition & 1 deletion src/gitrunner/git_runner_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ impl From<std::string::FromUtf8Error> for GitRunnerError {
fn from(err: std::string::FromUtf8Error) -> GitRunnerError {
GitRunnerError::Utf8Error(err)
}
}
}
4 changes: 2 additions & 2 deletions src/gitrunner/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod git_runner;
pub mod git_runner_error;
pub mod git_runner;
pub mod git_runner_error;
33 changes: 19 additions & 14 deletions src/gptrunner/gpt_runner.rs
Original file line number Diff line number Diff line change
@@ -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 {}
Expand All @@ -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())
}
}
}
2 changes: 1 addition & 1 deletion src/gptrunner/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod gpt_runner;
pub mod gpt_runner;
25 changes: 6 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -27,48 +26,36 @@ 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)?;
},
}
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?;
println!("GPT response {}", gpt_response);
}

Ok(())
}
}
5 changes: 5 additions & 0 deletions src/output_file_format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub struct OutputFileFormat {}

impl OutputFileFormat {

}
Loading