Task(dev): Added functionality to GitGrabber to get staged files diff.

This commit is contained in:
Triston Armstrong 2024-12-10 12:11:39 -05:00
parent b552e72cd7
commit a5905ae31c
Signed by: tristonarmstrong
GPG Key ID: A23B48AE45EB6EFE
2 changed files with 34 additions and 36 deletions

View File

@ -1,26 +1,28 @@
use git2::Repository;
use std::{env::current_dir, path::PathBuf};
use std::{fs::write, io::Write, process::Command, str::from_utf8};
pub struct GitGrabber {
pub repo: Option<Repository>,
dir: PathBuf,
}
// this is a comment test here
pub struct GitGrabber {}
impl GitGrabber {
pub fn new() -> Self {
println!("{:?}", current_dir().unwrap());
GitGrabber {
repo: None,
dir: current_dir().unwrap(),
}
GitGrabber {}
}
pub fn get_repo(&mut self) {
let repo = match Repository::open(self.dir.clone()) {
Ok(repo) => repo,
Err(e) => panic!("Failed to open: {}", e),
};
pub fn get_diff(&self) -> String {
// just to print
let staged_files_output = Command::new("git")
.args(["diff", "--staged", "--stat"])
.output()
.expect("Failed to get diff");
let _ = std::io::stdout().write_all(&staged_files_output.stdout);
self.repo = Some(repo);
// actual output
let output = Command::new("git")
.args(["diff", "--staged", "--", ".", "':(exclude)*lock*'"])
.output()
.expect("Failed to execute process");
let b = from_utf8(&output.stdout).unwrap();
String::from(b)
}
}

View File

@ -2,31 +2,27 @@ mod git_grabber;
mod mind_bridge;
mod transporter;
// use core::panic;
use core::panic;
use git_grabber::GitGrabber;
use mind_bridge::*;
// use transporter::Transporter;
use transporter::Transporter;
fn main() {
// let a = MindGen::new("Some random commit message");
// let mut transporter = Transporter::new();
let mut transporter = Transporter::new();
let mut gg = GitGrabber::new();
gg.get_repo();
gg.repo
let gg = GitGrabber::new();
let diff = gg.get_diff();
let mind_gen_text = MindGen::new(format!("input: {}; branch: {}", diff, "dev"));
let res_text = transporter
.make_request(mind_gen_text)
.unwrap()
.reflog("head")
.unwrap()
.iter()
.for_each(|x| println!("{:?}", x.message()));
return ();
.text()
.unwrap();
let response: Result<GenRes, _> = serde_json::from_str(&res_text);
// let res_text = transporter.make_request(a).unwrap().text().unwrap();
// let response: Result<GenRes, _> = serde_json::from_str(&res_text);
if response.is_err() {
panic!("oop something went wrong: {:?}", response.err());
}
// if response.is_err() {
// panic!("oop something went wrong: {:?}", response.err());
// }
// println!("{:#?}", response.unwrap());
println!("{:#?}", response.unwrap().response);
}