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::{fs::write, io::Write, process::Command, str::from_utf8};
use std::{env::current_dir, path::PathBuf};
pub struct GitGrabber { // this is a comment test here
pub repo: Option<Repository>, pub struct GitGrabber {}
dir: PathBuf,
}
impl GitGrabber { impl GitGrabber {
pub fn new() -> Self { pub fn new() -> Self {
println!("{:?}", current_dir().unwrap()); GitGrabber {}
GitGrabber {
repo: None,
dir: current_dir().unwrap(),
}
} }
pub fn get_repo(&mut self) { pub fn get_diff(&self) -> String {
let repo = match Repository::open(self.dir.clone()) { // just to print
Ok(repo) => repo, let staged_files_output = Command::new("git")
Err(e) => panic!("Failed to open: {}", e), .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 mind_bridge;
mod transporter; mod transporter;
// use core::panic; use core::panic;
use git_grabber::GitGrabber; use git_grabber::GitGrabber;
use mind_bridge::*; use mind_bridge::*;
// use transporter::Transporter; use transporter::Transporter;
fn main() { 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(); let gg = GitGrabber::new();
gg.get_repo(); let diff = gg.get_diff();
gg.repo let mind_gen_text = MindGen::new(format!("input: {}; branch: {}", diff, "dev"));
let res_text = transporter
.make_request(mind_gen_text)
.unwrap() .unwrap()
.reflog("head") .text()
.unwrap() .unwrap();
.iter() let response: Result<GenRes, _> = serde_json::from_str(&res_text);
.for_each(|x| println!("{:?}", x.message()));
return ();
// let res_text = transporter.make_request(a).unwrap().text().unwrap(); if response.is_err() {
// let response: Result<GenRes, _> = serde_json::from_str(&res_text); panic!("oop something went wrong: {:?}", response.err());
}
// if response.is_err() {
// panic!("oop something went wrong: {:?}", response.err()); println!("{:#?}", response.unwrap().response);
// }
// println!("{:#?}", response.unwrap());
} }