Compare commits

..

No commits in common. "9716a6ea1b5123fe4c5ef402f987cee0b8887668" and "3c0a1c505cdd7b662ad7212bbea3ce3c78371d37" have entirely different histories.

6 changed files with 33 additions and 65 deletions

View File

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

View File

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

View File

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

View File

@ -1,5 +1,3 @@
use std::error::Error;
use reqwest::blocking::Client; use reqwest::blocking::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -50,7 +48,7 @@ impl MlBody {
prompt: content, prompt: content,
system: directions, system: directions,
options: MlOptions { options: MlOptions {
temperature: 0.1, temperature: 0.5,
num_predict: 0, num_predict: 0,
repeat_last_n: 0, repeat_last_n: 0,
top_k: 10, top_k: 10,
@ -75,15 +73,11 @@ impl MlInterface {
} }
#[allow(unused)] #[allow(unused)]
pub fn make_request(&mut self, gen_data: MlBody) -> Result<reqwest::blocking::Response, &str> { pub fn make_request(
if gen_data.prompt.len() < 1 { &mut self,
panic!("No prompt provided"); gen_data: MlBody,
} ) -> Result<reqwest::blocking::Response, reqwest::Error> {
let json_body = serde_json::to_string(&gen_data).unwrap(); let json_body = serde_json::to_string(&gen_data).unwrap();
let res = self.client.post(OLLAMA_ENDP).body(json_body).send(); 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,16 +3,7 @@ use crate::git_grabber::GitGrabber;
pub struct PrHandler {} pub struct PrHandler {}
impl PrHandler { impl PrHandler {
pub fn new() -> Option<(String, String)> { pub fn new() -> Option<(String, String)> {
let directions = String::from(" let dirs = String::from("Pull Request Handler");
<Variables> Some((dirs, GitGrabber::generate_repo_desc("", "")))
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()))
} }
} }