Skip to content

Commit

Permalink
improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendzae committed Nov 23, 2024
1 parent 2dcb67f commit 120d7ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
16 changes: 7 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct GsContext {
github: Arc<Octocrab>,
state: GsState,
}
const VERSION: &str = env!("CARGO_PKG_VERSION");

#[tokio::main]
async fn main() -> Result<()> {
Expand Down Expand Up @@ -60,8 +61,9 @@ async fn main() -> Result<()> {
},
Some(Commands::Reset {}) => ctx.reset()?,
None => println!(
"Welcome to {}! Run {} to see available commands.",
style("G-Stack v0.0.3").bold().cyan(),
"Welcome to {} version {}! Run {} to see available commands.",
style("G-Stack").bold().cyan(),
style(VERSION).bold().yellow(),
style("gs help").italic().green(),
),
}
Expand Down Expand Up @@ -371,13 +373,9 @@ impl GsContext {

async fn list_pull_requests(&self) -> Result<()> {
let open_pulls = self.get_pull_requests().await?;
println!(
"{:?}",
open_pulls
.iter()
.map(|pr| pr.title.clone().unwrap())
.collect::<Vec<String>>()
);
for pr in open_pulls.iter() {
println!("#{}: {} ", pr.number, pr.html_url.clone().unwrap());
}
Ok(())
}

Expand Down
28 changes: 21 additions & 7 deletions src/repo_extensions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use anyhow::{bail, Ok};
use console::style;
use regex::Regex;
use std::fmt::Debug;
use std::{ops::Rem, str::FromStr};
Expand All @@ -18,7 +19,7 @@ pub trait RepoExtenstions {
fn remote_repo_url(&self) -> Result<String>;
fn remote_repo_info(&self) -> Result<RemoteRepoInfo>;
fn force_push_to_upstream(&self, upstream: &str, upstream_branch: &BranchName) -> Result<()>;
fn head_sha(&self, branch_name: &String) -> Result<String>;
fn head_sha(&self, branch_name: &String) -> Result<String>;
}

impl RepoExtenstions for Repository {
Expand All @@ -30,15 +31,24 @@ impl RepoExtenstions for Repository {
fn rebase(&self, branch: BranchName, on: BranchName) -> Result<()> {
self.switch_branch(&branch)?;
let output = self.cmd_out(&["rebase", "--update-refs", on.to_string().as_str()])?;
println!("{:?}", output);
println!(
"Rebased branch {} on {} with output: {:?}",
style(branch).green(),
style(on).green(),
style(output.join(",")).white().on_black()
);
Ok(())
}

fn pull_all(&self, branches: &Vec<String>) -> Result<()> {
for branch in branches {
self.switch_branch(&BranchName::from_str(branch.as_str())?)?;
let output = self.cmd_out(&["pull", "--rebase"]).ok();
println!("{:?}", output);
let output = self.cmd_out(&["pull", "--rebase"])?;
println!(
"Pulled branch {} with output: {:?}",
style(branch).green(),
style(output.join(",")).white().on_black()
);
}
Ok(())
}
Expand All @@ -54,7 +64,6 @@ impl RepoExtenstions for Repository {
fn remote_repo_info(&self) -> Result<RemoteRepoInfo> {
let url = self.remote_repo_url()?;
let re = Regex::new(r"(https://github.com/|[email protected]:)([^/]+)/([^/]+)\.git").unwrap();
println!("{}", url);

if let Some(captures) = re.captures(url.as_str()) {
Ok(RemoteRepoInfo {
Expand All @@ -68,13 +77,18 @@ impl RepoExtenstions for Repository {

///Force push the curent branch to its associated remote, specifying the upstream branch
fn force_push_to_upstream(&self, upstream: &str, upstream_branch: &BranchName) -> Result<()> {
self.cmd_out(&[
let output = self.cmd_out(&[
"push",
"-u",
upstream,
upstream_branch.to_string().as_str(),
"--force",
]);
])?;
println!(
"Force pushed to upstream branch {} with output: {:?}",
style(upstream_branch).green(),
style(output.join(",")).white().on_black()
);
Ok(())
}

Expand Down

0 comments on commit 120d7ff

Please sign in to comment.