Compare commits
10 Commits
3c0a1c505c
...
9716a6ea1b
Author | SHA1 | Date | |
---|---|---|---|
9716a6ea1b | |||
8445e2f076 | |||
f96ab7523e | |||
44c996127b | |||
8715e8b753 | |||
28afb4942d | |||
3bff96acab | |||
6ae7ce6a57 | |||
57ed1ca513 | |||
4132b953c9 |
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user