From a5905ae31c60c7d0075ebe4158c9120eaf8fc138 Mon Sep 17 00:00:00 2001 From: Triston Armstrong Date: Tue, 10 Dec 2024 12:11:39 -0500 Subject: [PATCH] Task(dev): Added functionality to GitGrabber to get staged files diff. --- src/git_grabber.rs | 36 +++++++++++++++++++----------------- src/main.rs | 34 +++++++++++++++------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/git_grabber.rs b/src/git_grabber.rs index 78fe3db..f4220a3 100644 --- a/src/git_grabber.rs +++ b/src/git_grabber.rs @@ -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, - 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) } } diff --git a/src/main.rs b/src/main.rs index 1ca91da..c7953e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = serde_json::from_str(&res_text); - // let res_text = transporter.make_request(a).unwrap().text().unwrap(); - // let response: Result = 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); }