WIP: add log graph to notifications
All checks were successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-08-06 20:48:53 +01:00
parent 8c19680056
commit c37bd2c64d
7 changed files with 76 additions and 0 deletions

7
Cargo.lock generated
View file

@ -993,6 +993,7 @@ dependencies = [
"secrecy",
"serde",
"serde_json",
"take-until",
"test-log",
"thiserror",
"time",
@ -3635,6 +3636,12 @@ dependencies = [
"libc",
]
[[package]]
name = "take-until"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb"
[[package]]
name = "tempfile"
version = "3.10.1"

View file

@ -84,6 +84,9 @@ anyhow = "1.0"
thiserror = "1.0"
pike = "0.1"
# iters
take-until = "0.2"
# file watcher
notify = "6.1"

View file

@ -57,6 +57,9 @@ serde_json = { workspace = true }
mockall = { workspace = true }
#iters
take-until = { workspace = true }
[dev-dependencies]
# Testing
assert2 = { workspace = true }

View file

@ -0,0 +1,3 @@
use crate::newtype;
newtype!(LogGraph, Vec<String>, "Git log showing branch positions");

View file

@ -7,6 +7,7 @@ mod forge_config;
mod forge_details;
mod forge_type;
pub mod git_dir;
mod graphs;
mod host_name;
mod registered_webhook;
mod remote_url;

View file

@ -0,0 +1,58 @@
//
use std::borrow::ToOwned;
use take_until::TakeUntilExt;
use crate::{GitDir, RepoBranches};
// create a graph to log relative positions
//
// ANCESTOR=$(git merge-base --octopus origin/main origin/next origin/dev)
// SHORT_ANCESTOR=$(echo $ANCESTOR | cut -b -7)
fn ancesstor(gitdir: &GitDir, branches: &RepoBranches) -> Option<String> {
let result = std::process::Command::new("/usr/bin/git")
.current_dir(gitdir.to_path_buf())
.args([
"merge-base",
"--octopus",
format!("origin/{}", branches.main()).as_str(),
format!("origin/{}", branches.next()).as_str(),
format!("origin/{}", branches.dev()).as_str(),
])
.output();
if let Ok(output) = result {
return String::from_utf8_lossy(output.stdout.as_slice())
.split('\n')
.take(1)
.map(|line| line.chars().take(7).collect::<String>())
.collect::<Vec<_>>()
.first()
.cloned();
}
None
}
// git log --oneline --graph --decorate origin/main origin/dev origin/next | awk "1;/$SHORT_ANCESTOR/{exit}"
fn log(gitdir: &GitDir, branches: &RepoBranches, ancestor: &str) -> Vec<String> {
let result = std::process::Command::new("/usr/bin/git")
.current_dir(gitdir.to_path_buf())
.args([
"log",
"--oneline",
"--graph",
"--decorate",
format!("origin/{}", branches.main()).as_str(),
format!("origin/{}", branches.next()).as_str(),
format!("origin/{}", branches.dev()).as_str(),
])
.output();
if let Ok(output) = result {
return String::from_utf8_lossy(output.stdout.as_slice())
.split('\n')
.take_until(|line| line.starts_with(ancestor))
.map(ToOwned::to_owned)
.collect();
}
vec![]
}

View file

@ -6,6 +6,7 @@ pub mod forge;
mod generation;
mod git_ref;
mod git_remote;
pub mod graph;
pub mod push;
mod repo_details;
pub mod repository;