pub / git_activity

Generates Github-style activity graphs as HTML
git clone https://https://src.jayvii.de/pub/git_activity.git
Home | Log | Files | Exports | Refs | README | RSS

commit a2994ece5e28cb43184a96b607acf5a406b73251
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Thu,  6 Jun 2024 21:47:39 +0200

initial script

Diffstat:
A.reuse/dep5 | 8++++++++
AREADME | 20++++++++++++++++++++
Aactivity.sh | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/.reuse/dep5 b/.reuse/dep5 @@ -0,0 +1,8 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: git_activity +Upstream-Contact: JayVii <jayvii[AT]posteo[DOT]de> +Source: https://src.jayvii.de/pub/git_activity + +Files: README +Copyright: 2024 JayVii <jayvii[AT]posteo[DOT]de> +License: AGPL-3.0-or-later diff --git a/README b/README @@ -0,0 +1,20 @@ +git_activity +============ + +Please send patches or remarks to <jayvii[AT]posteo[DOT]de> + +Script that generates git-activity bars similar to the "GitHub Activity" graphs +as HTML. + +Written for the integration into my stagit setup, this may be used for other +websites as well (https://src.jayvii.de/pub/stagit-jayvii.de). + +Usage +----- + + ./activity.sh /PATH/TO/GIT/REPO /PATH/TO/ANOTHER/REPO /PATH/TO/MORE/REPOS + +License +------- + +git_activity is licensed under AGPL-3.0-or-later diff --git a/activity.sh b/activity.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de> + +# Fetch Inputs ----------------------------------------------------------------- + +# all given arguments are interpreted as git-directories +DIRS="$@" + +# Output Functions ------------------------------------------------------------- + +# HTML output +function html_output { + TTL="" + DTE="$1" + CMT="$2" + OPC="$3" + if [[ ! -z $DTE ]]; then TTL+="$DTE"; fi + if [[ ! -z $CMT ]]; then TTL+=": $CMT commits"; fi + if [[ $OPC -lt 5 ]]; then OPC=5; fi + ID="activity-$OPC" + CL="activitypoint" + STL="opacity:calc($OPC/100);" + ARGS="id=\"$ID\" class=\"activitypoint\" style=\"$STL\" title=\"$TTL\"" + printf "<span $ARGS\">&#9632;</span>" +} + +# Collect activity ------------------------------------------------------------- + +# By Months +for DIR in $DIRS; do + ACTIVITY+="$( + git \ + -C $DIR \ + log --date=short --pretty=format:%ad | \ + awk '{print substr($1, 1, 7)}' + )\n" +done + +# aggregate activity +AGGREGATE=$( + printf "$ACTIVITY" | \ + sort | \ + uniq -c +) + +# Process Activity ------------------------------------------------------------- + +# get timeframe +MIN_TIME=$(echo "$AGGREGATE" | head -n 1 | awk '{ print $NF }') +MAX_TIME=$(date +%Y-%m -d "next month") + +# get value range +MIN_VAL=0 +MAX_VAL=$(echo "$AGGREGATE" | awk '{ print $1 }' | sort -n | tail -n 1) + +# Generate output -------------------------------------------------------------- + +# initilise html +MIN_TIME_PRETTY=$(date --date "${MIN_TIME}-01" "+%b, %Y") +MAX_TIME_PRETTY=$(date --date "${MAX_TIME}-01 -1 day" "+%b, %Y") +HTML="<h6>Activity: ${MIN_TIME_PRETTY} - ${MAX_TIME_PRETTY}</h6>" + +# cycle through months from earliest timepoint +CUR_TIME=$MIN_TIME +while [ $CUR_TIME != $MAX_TIME ]; do + + # fetch current value + CUR_VAL=$(echo "$AGGREGATE" | grep $CUR_TIME | awk '{ print $1 }') + + # normalise current value [0, 100] + NRM_VAL=$((${CUR_VAL:-0} * 100 / $MAX_VAL)) + + # list data in variable + # DATA+="$CUR_TIME ${CUR_VAL:-0} ${NRM_VAL:-5}\n" + + # output HTML + CUR_TIME_PRETTY=$(date --date "${CUR_TIME}-01" "+%b, %Y") + HTML+=$(html_output "$CUR_TIME_PRETTY" ${CUR_VAL:-0} ${NRM_VAL:-0}) + + # update current time + CUR_TIME=$(date --date "${CUR_TIME}-01 +1 month" +%Y-%m) + + # reset variables for next round + CUR_VAL="" + NRM_VAL="" + +done + +# add legend +HTML+="<br><p id=\"activitylegend\">Less " +for LV in $(seq 0 20 100); do + LND_VAL=$(($LV * $MAX_VAL / 100)) + HTML+=$(html_output 'Legend' $LND_VAL $LV) +done +HTML+=" More</p>" + +# add "activitybar" div +HTML="<div id=\"activitybar\">$HTML</div>" + +# Print output ----------------------------------------------------------------- + +printf "$HTML"