Skip to content

Commit

Permalink
Add fetch git last commit info example
Browse files Browse the repository at this point in the history
  • Loading branch information
pymongo committed Oct 12, 2020
1 parent 51c377e commit 8207c28
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
27 changes: 17 additions & 10 deletions examples/basic_execute_shell_command.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use std::process::Command;
#[derive(serde::Deserialize, Debug)]
struct CommitInfo {
hash: String,
date: String,
message: String
}

fn main() {
let mut cmd = Command::new("df");
cmd.arg("-h");
match cmd.output() {
Ok(output) => unsafe {
println!("{}", String::from_utf8_unchecked(output.stdout));
},
Err(e) => println!("{}", e),
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let cmd_res = std::process::Command::new("git")
.arg("log")
.arg("-1")
.arg("--pretty=format:hash=\"%h\"\ndate=\"%ad\"\nmessage=\"%s\"")
.env("DATABASE_URL", "null")
.output()?;
let last_commit_str = String::from_utf8(cmd_res.stdout)?;
let last_commit: CommitInfo = toml::de::from_str(&last_commit_str)?;
dbg!(last_commit);
Ok(())
}
4 changes: 2 additions & 2 deletions examples/double_linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct List<T> {
tail: Node<T>,
}

// impl List<T> {
// impl<T> List<T> {
// fn new(dummy_val: T) -> Self {
// let mut head = Node::new(dummy_val);
// let mut tail = Node::new(dummy_val);
Expand All @@ -37,5 +37,5 @@ struct List<T> {
// }

fn main() {
let mut head: Node<i32> = Node::new(-1);
let _head: Node<i32> = Node::new(-1);
}
2 changes: 0 additions & 2 deletions examples/gzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ fn main() {
let decode_str = decode_gzip_bytes_to_str(gzip_bytes);
println!("{}", decode_str);
assert_eq!(decode_str.as_str(), s);

use std::collections::BinaryHeap;
}
2 changes: 1 addition & 1 deletion examples/rust_decimal_lib_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bigdecimal::BigDecimal;
use rust_decimal::Decimal;
// use rust_decimal::prelude::FromStr;
use rust_decimal::prelude::ToPrimitive;

use std::mem::size_of_val;
use std::str::FromStr;

Expand Down

0 comments on commit 8207c28

Please sign in to comment.