From ceceb3aa1d5209d2015a2acb55486ce70436e2a6 Mon Sep 17 00:00:00 2001 From: Neil Muller Date: Sun, 22 Mar 2020 14:39:07 +0200 Subject: [PATCH] Restructure --- irker | 17 ++++------------- post-receive | 23 +++++++++++++++++++++++ slack | 18 ++++-------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/irker b/irker index eb4bd1e..436e190 100755 --- a/irker +++ b/irker @@ -2,7 +2,7 @@ IRKERPATH=/usr/bin/ -function help() { +function help_irker() { echo "Required config settings:" echo " git config irker.channels 'channel1 channel2 ..'" echo " git config irker.project 'Project name'" @@ -16,6 +16,9 @@ function notify_irker() { new=$2 refname=$3 + echo "irker $1 $2 $3" + return + if [ "x$old" = "x0000000000000000000000000000000000000000" ]; then # We're pushing into an empty repo, so we need a different command # to get the rev list @@ -36,15 +39,3 @@ function notify_irker() { $(git rev-list --reverse ${old}..${new}) fi } - -channels=$(git config --get irker.channels) - -while read line; do - set -- $line - if [ -n "$channels" ]; then - notify_irker $* - fi - RET=$? -done - -exit $RET diff --git a/post-receive b/post-receive index e69de29..3aeae35 100755 --- a/post-receive +++ b/post-receive @@ -0,0 +1,23 @@ +#!/bin/bash +HOOKDIR=$(dirname $0) + +# Load functions +. $HOOKDIR/irker +. $HOOKDIR/slack + + +channels=$(git config --get irker.channels) + +webhook_url=$(git config --get hooks.slack.webhook-url) + +while read line; do + set -- $line + if [ -n "$channels" ]; then + notify_irker $* + fi + if [ -n "$webhook_url" ]; then + notify_slack $* + fi + RET=$? +done +exit $RET diff --git a/slack b/slack index 45187cf..ac6e114 100755 --- a/slack +++ b/slack @@ -8,7 +8,7 @@ # Based on post-receive.irc by Mikael Fridh https://gist.github.com/1821358 # -function help() { +function help_slack() { echo "Required config settings:" echo " git config hooks.slack.webhook-url 'https://hooks.slack.com/services/...'" echo " git config hooks.slack.channel 'general'" @@ -22,6 +22,9 @@ function notify_slack() { newrev=$(git rev-parse $2) refname="$3" + echo "slack $1 $2 $3" + return + # --- Interpret # 0000->1234 (create) # 1234->2345 (update) @@ -233,16 +236,3 @@ function notify_slack() { "$webhook_url" \ >/dev/null } - -webhook_url=$(git config --get hooks.slack.webhook-url) - -while read line; do - set -- $line - if [ -n "$webhook_url" ]; then - notify_slack $* - fi - - RET=$? -done - -exit $RET -- 2.34.1