-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathgit_graph_commit_times_mermaidjs.sh
executable file
·93 lines (70 loc) · 2.27 KB
/
git_graph_commit_times_mermaidjs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2024-10-04 03:03:56 +0300 (Fri, 04 Oct 2024)
#
# https///github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090,SC1091
. "$srcdir/lib/git.sh"
code="git_commit_times.mmd"
data="data/git_commit_times.dat"
image="images/git_commit_times.svg"
# shellcheck disable=SC2034,SC2154
usage_description="
Generates a MermaidJS graph of Git commit times from the current Git repo checkout's git log
Generates the MermaidJS code and then uses MermaidJS CLI to generate the image
$code - Code
$data - Data
$image - Image
A GNUplot version of this script is adjacent at:
git_graph_commit_times_gnuplot.sh
Requires Git and MermaidJS CLI (mmdc) to be installed to generate the graphs
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args=""
help_usage "$@"
num_args 0 "$@"
check_bin mmdc
if ! is_in_git_repo; then
die "ERROR: must be run from a git repo checkout as it relies on the 'git log' command"
fi
git_repo="$(git_repo)"
timestamp "Running inside checkout of Git repo: $git_repo"
timestamp "Fetching Hour of all commits from Git log"
git log --date=format:'%H' --pretty=format:'%ad' |
sort |
uniq -c |
awk '{print $2" "$1}' > "$data"
echo
export -f parse_file_col_to_csv
timestamp "Generating MermaidJS code for bar chart of commit times"
cat > "$code" <<EOF
xychart-beta
title "$git_repo - Git Commits by Hour"
x-axis [ $(parse_file_col_to_csv "$data" 1) ]
y-axis "Number of Commits"
bar [ $(parse_file_col_to_csv "$data" 2) ]
%%line [ $(parse_file_col_to_csv "$data" 2) ]
EOF
timestamp "Generated MermaidJS code"
echo
timestamp "Generating MermaidJS bar chart image: $image"
mmdc -i "$code" -o "$image" -t dark --quiet # -b transparent
timestamp "Generated MermaidJS image: $image"
if is_CI; then
exit 0
fi
timestamp "Opening generated bar chart"
"$srcdir/../media/imageopen.sh" "$image"