void/local/bin/scripts/irc-post-commit-hook

27 lines
1.2 KiB
Plaintext
Raw Normal View History

2024-02-29 03:45:58 +00:00
#!/bin/sh
# irc post-commit hook - developed by acidvegas (https://git.acid.vegas/void)
# Place this file in .git/hooks/post-commit and chmod +x
# Configuration
2024-11-29 08:15:53 +00:00
WEECHAT_NETWORK="supernets"
2024-02-29 03:45:58 +00:00
WEECHAT_CHANNEL="#dev"
WEECHAT_FIFO="/home/acidvegas/.local/share/weechat/weechat_fifo"
SSH_SERVER="war"
# Get commit data for the message
_data=$(git log -1 --graph --pretty=format:"%h|%s|%cn")
_hash=$(echo "$_data" | cut -d'|' -f1 | cut -c 3-)
_msg=$(echo "$_data" | cut -d'|' -f2)
_name=$(echo "$_data" | cut -d'|' -f3)
#_name=$(basename $(dirname $(git rev-parse --show-toplevel))) # For locally parsing organization names
_repo=$(basename -s .git $(git config --get remote.origin.url))
_summary=$(git show $_hash --stat | grep -E "fil(e|es) changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {printf "%s|+%s|-%s", files, inserted, deleted }')
_files=$(echo $_summary | cut -d'|' -f1)
_inserts=$(echo $_summary | cut -d'|' -f2)
_deletes=$(echo $_summary | cut -d'|' -f3)
2024-11-29 08:15:53 +00:00
_ircmsg="irc.$WEECHAT_NETWORK.$WEECHAT_CHANNEL *14[11GitHub14] Commit pushed to 08$_name/$_repo (06$_hash) 14[$_files14|03$_inserts14|04$_deletes14] : $_msg"
2024-02-29 03:45:58 +00:00
# Send the message to weechat
2024-11-29 08:15:53 +00:00
echo "$_ircmsg" | ssh $SSH_SERVER tee $WEECHAT_FIFO > /dev/null