Compare commits

...

10 Commits

Author SHA1 Message Date
9716a6ea1b
"feat(pr_handler): Add PR title and description generation \n\nPR Description:\nAdded PR title and description generation to the PrHandler struct. The new method now returns an optional tuple containing the PR title and description. The PR title is generated based on the change type and scope, while the description is generated in markdown format to describe the changes made in this diff." 2025-01-12 13:12:38 -05:00
8445e2f076
"feat(ml_interface): add prompt validation to make_request function" 2025-01-12 13:12:14 -05:00
f96ab7523e
"feat(ml_interface): update ml_body temperature value" 2025-01-12 13:11:53 -05:00
44c996127b
"feat(git_grabber): generate repo description from reflog" 2025-01-12 13:11:37 -05:00
8715e8b753
"feat(io): Panic if Git diff command fails" 2025-01-12 13:11:16 -05:00
28afb4942d
"feat(commit_handler): Update commit handler to generate commit message based on diff changes." 2025-01-12 13:10:43 -05:00
3bff96acab
"feat(grabber): Update GitGrabber to ignore whitespace and blank lines in diff output" 2025-01-12 13:10:23 -05:00
6ae7ce6a57
"feat(arg_parser): Add interactive mode and help message" 2025-01-12 13:00:18 -05:00
57ed1ca513
"feat(main): Added a comment that is incorrect and will not affect the program's functionality." 2025-01-12 12:53:10 -05:00
4132b953c9
"feat(main): Update main function to use new MlBody and ml.make_request APIs" 2025-01-12 12:50:59 -05:00
6 changed files with 65 additions and 33 deletions

View File

@ -13,6 +13,7 @@ impl ArgParser {
let arg = args().nth(1);
if arg.is_none() {
// <-- interactive mode will go here
println!("...(future) interactive mode not implimented... exiting");
return None;
}
let arg = arg.unwrap();
@ -20,13 +21,10 @@ impl ArgParser {
"-c" => Some(ParsedArg::Commit),
"-p" => Some(ParsedArg::PullRequest),
"-h" => {
println!("help stuff here");
None
}
_ => {
println!("Available Commands: -c [commit] -p [pull request] -h [help]");
None
}
_ => None,
}
}
}

View File

@ -4,7 +4,17 @@ pub struct CommitHandler {}
impl CommitHandler {
pub fn new() -> Option<(String, String)> {
let dirs = String::from("create a short commit message from this diff, with format Task(<branch_name>): <commit_message>. only respond with the commit message");
Some((dirs, GitGrabber::get_diff()))
let dirs = String::from(format!("
<Variables>
change_type: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
<Commit Instructions>
create a short commit message from this entire diff, with format <change_type>(<scope>): <commit_message>.
the commit message should vaguely describe the changes present unless a small change is made that can be
precisely described withtin a short commit message
<Response Constraints>
Only respond with the commit message.
"));
let prompt = GitGrabber::get_diff();
Some((dirs, prompt))
}
}

View File

@ -1,3 +1,4 @@
use core::panic;
use std::{
fs::write,
io::Write,
@ -20,32 +21,39 @@ impl GitGrabber {
.expect("Failed to get branch");
let b = from_utf8(&branch.stdout).unwrap();
String::from(b)
String::from(b.strip_suffix("\n").unwrap())
}
pub fn get_diff() -> String {
// just to print
let staged_files_output = Command::new("git")
.args(["diff", "--staged"])
let output = Command::new("git")
.args([
"diff",
"--staged",
"--ignore-all-space",
"--ignore-blank-lines",
"--ignore-cr-at-eol",
"--minimal",
"--no-prefix",
"--no-renames",
"--word-diff",
"--inter-hunk-context=0",
])
.output()
.expect("Failed to get diff");
let b = from_utf8(&staged_files_output.stdout).unwrap();
if !output.status.success() {
panic!("Did you forget to stage your files?");
}
let b = from_utf8(&output.stdout).unwrap();
String::from(b)
}
pub fn generate_repo_desc(origin_branch: &str, local_branch: &str) -> String {
pub fn generate_repo_desc() -> String {
let curr_branch = GitGrabber::get_current_branch();
let output = Command::new("git")
.args([
"rev-list",
"--left-right",
"--pretty=oneline",
&format!(
"{}...{}",
origin_branch.to_string(),
local_branch.to_string()
),
])
.args(["reflog", "show", &curr_branch])
.output()
.expect("Failed to get repo details");

View File

@ -16,18 +16,19 @@ fn main() {
None => None,
};
// 1+2 = 5
if prompt.is_none() {
println!("Sorry nothing to do.. exiting");
return;
}
let mut ml = MlInterface::new();
let (directions, content) = prompt.unwrap();
let mind_gen_text = MlBody::new(content, directions);
let res_text = ml.make_request(mind_gen_text).unwrap().text().unwrap();
let body = MlBody::new(content, directions);
let res_text = ml.make_request(body).unwrap().text().unwrap();
let response: Result<MlResponse, _> = serde_json::from_str(&res_text);
if response.is_err() {
panic!("oop something went wrong: {:?}", response.err());
}
println!("{:#?}", response.unwrap());
println!("{:?}", response.unwrap().response);
}

View File

@ -1,3 +1,5 @@
use std::error::Error;
use reqwest::blocking::Client;
use serde::{Deserialize, Serialize};
@ -48,7 +50,7 @@ impl MlBody {
prompt: content,
system: directions,
options: MlOptions {
temperature: 0.5,
temperature: 0.1,
num_predict: 0,
repeat_last_n: 0,
top_k: 10,
@ -73,11 +75,15 @@ impl MlInterface {
}
#[allow(unused)]
pub fn make_request(
&mut self,
gen_data: MlBody,
) -> Result<reqwest::blocking::Response, reqwest::Error> {
pub fn make_request(&mut self, gen_data: MlBody) -> Result<reqwest::blocking::Response, &str> {
if gen_data.prompt.len() < 1 {
panic!("No prompt provided");
}
let json_body = serde_json::to_string(&gen_data).unwrap();
self.client.post(OLLAMA_ENDP).body(json_body).send()
let res = self.client.post(OLLAMA_ENDP).body(json_body).send();
if res.is_err() {
panic!("Failed to send ollama payload");
}
Ok(res.unwrap())
}
}

View File

@ -3,7 +3,16 @@ use crate::git_grabber::GitGrabber;
pub struct PrHandler {}
impl PrHandler {
pub fn new() -> Option<(String, String)> {
let dirs = String::from("Pull Request Handler");
Some((dirs, GitGrabber::generate_repo_desc("", "")))
let directions = String::from("
<Variables>
change_type: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
<PR Title>
create a short PR title from this diff, with format <change_type>(<scope>): <pr_description>.
<PR Description>
create an additional PR Description in markdown format to describe the changes made in this diff.
<Response Constraints>
Only respond with the Pr title and Pr description.
");
Some((directions, GitGrabber::generate_repo_desc()))
}
}