summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParabola git <git@parabola.nu>2023-04-07 02:00:21 +0000
committerParabola git <git@parabola.nu>2023-04-07 02:00:21 +0000
commitb5bcd7ccc9071fc6ac20db3825e2b118bb9d939b (patch)
treeb4b8c4824cba11169a9ae18293c04a78f7891074
parent4f19458cc829cbeefecd0c5c9af3df80de035956 (diff)
Update from cron
-rwxr-xr-x.config/git/hooks/update.d/per-branch-no-ff.hook (renamed from .config/git/hooks/update.d/per-branch-no-ff)8
-rw-r--r--.config/git/hooks/update.d/trigger-autobuild-wip.hook (renamed from .config/git/hooks/update.d/trigger-autobuild.wip)0
-rw-r--r--.config/git/hooks/update.d/wip.hook97
3 files changed, 105 insertions, 0 deletions
diff --git a/.config/git/hooks/update.d/per-branch-no-ff b/.config/git/hooks/update.d/per-branch-no-ff.hook
index 9551fcf..cde3dac 100755
--- a/.config/git/hooks/update.d/per-branch-no-ff
+++ b/.config/git/hooks/update.d/per-branch-no-ff.hook
@@ -5,10 +5,18 @@ readonly REF=$1
readonly PREV_SHA=$2
readonly NEXT_SHA=$3
+readonly REPOS_RX='abslibre|packages|community'
+[[ "${REPO}" =~ ^(${REPOS_RX})\.git || # WIP
+ "${REF}" != 'refs/heads/master' ]] || \
+git merge-base --is-ancestor "${PREV_SHA}" "${NEXT_SHA}"
+exit $? # WIP
+
+
# prevent re-writing history on abslibre master branch
# autobuilder can not handle non-fast-forward commits
[[ "${REPO}" != 'abslibre.git' ]] || \
[[ "${REF}" != 'refs/heads/master' ]] || \
+
git merge-base --is-ancestor "${PREV_SHA}" "${NEXT_SHA}"
exit $?
diff --git a/.config/git/hooks/update.d/trigger-autobuild.wip b/.config/git/hooks/update.d/trigger-autobuild-wip.hook
index 15c7c5a..15c7c5a 100644
--- a/.config/git/hooks/update.d/trigger-autobuild.wip
+++ b/.config/git/hooks/update.d/trigger-autobuild-wip.hook
diff --git a/.config/git/hooks/update.d/wip.hook b/.config/git/hooks/update.d/wip.hook
new file mode 100644
index 0000000..2a524ed
--- /dev/null
+++ b/.config/git/hooks/update.d/wip.hook
@@ -0,0 +1,97 @@
+#!/bin/bash
+echo "wip.hook" ; exit
+# notify-pbot-git-hook - git post-receive hook for pbot-say
+#
+# Copyright 2019-2020 bill-auger <bill-auger@programmer.net>
+#
+# This file is part of the 'pbot' program
+#
+# 'pbot' is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# 'pbot' is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License version 3
+# along with 'pbot'. If not, see <http://www.gnu.org/licenses/>.
+
+
+# this hook receives data via STDIN - one line per pushed ref
+# each as 'ref_data' - where 'ref_data' is: prev_sha curr_sha ref_file
+# e.g.
+# 0000000000000000000000000000000000000000 0123456789abcdef0123456789abcdef01234567 refs/heads/new-branch
+# 0123456789abcdef0123456789abcdef01234567 89abcdef0123456789abcdef0123456789abcdef refs/heads/existing-branch
+# 89abcdef0123456789abcdef0123456789abcdef 0000000000000000000000000000000000000000 refs/heads/deleted-branch
+
+
+## constants ##
+
+readonly REPO=$(basename $(pwd))
+readonly LIB_DIR=/usr/lib/parabola-hackers
+readonly LOG_DIR=/var/log/pbot
+readonly LOG_FILE=${LOG_DIR}/notify-pbot-$(date +%Y-%m-%d_%H-%M-%S)_${REPO}
+readonly SHA_REGEX='^([0-9a-f]{40})$'
+
+
+## logging ##
+
+LogParseRefData() # (var_name [var_name ... ])
+{
+ while (( $# )) && echo "${1}=${!1-ERR}" 2> /dev/null >> "${LOG_FILE}" ; do shift ; done ;
+}
+
+
+## helpers ##
+
+ParseRefData() # (prev_sha curr_sha ref_file)
+{
+ local ref_data="$@"
+ local prev_sha=$1
+ local curr_sha=$2
+ local ref_file=$3
+ local ref=${ref_file##*/}
+ local is_deletion=$(git show-ref "${ref}" > /dev/null && echo 0 || echo 1)
+ local log_refdata_args=(REPO ref_data prev_sha curr_sha ref_file ref is_deletion)
+
+ # validate ref data
+ if [[ "$#" == '3' ]] && \
+ [[ "${prev_sha}" =~ ${SHA_REGEX} ]] && \
+ [[ "${curr_sha}" =~ ${SHA_REGEX} ]] && \
+ [[ -n "${ref}" ]]
+ then LogParseRefData ${log_refdata_args[@]}
+ else return 1 $(LogParseRefData invalid ${log_refdata_args[@]})
+ fi
+
+ # collect push details
+# local hacker=$( ${LIB_DIR}/last-git-login )
+hacker='' # last-git-login is unreliable
+ local author="$( git log -1 --format='%an' ${curr_sha} 2> /dev/null)"
+ local log_msg="$(git log -1 --format='%s' ${curr_sha} 2> /dev/null)"
+ local n_behind=$(git rev-list --count ${curr_sha}..${prev_sha} 2> /dev/null)
+ local n_ahead=$( git rev-list --count ${prev_sha}..${curr_sha} 2> /dev/null)
+ local n_total=$( git rev-list --count ${ref} 2> /dev/null)
+
+ LogParseRefData hacker author log_msg n_behind n_ahead n_total ; echo >> ${LOG_FILE} ;
+
+ # fall-back to author name if the hacker detector fails
+ [[ -n "${author}" ]] || author='someone' # deletion
+ [[ -n "${hacker}" ]] || hacker="${author}" # broken/buggy last-hacker-login
+
+ # detect new ref
+ [[ ${prev_sha} =~ ^0{40}$ ]] && n_behind='∞' n_ahead=${n_total}
+
+ # prepare pbot message
+ if (( ${is_deletion} ))
+ then echo "${hacker} deleted branch: ${REPO}/${ref}"
+ else echo "${hacker} pushed (-${n_behind} +${n_ahead}) commits to ${REPO}/${ref}: ${log_msg}"
+ fi
+}
+
+
+## main entry ##
+
+while read ref_data ; do pbot-say "$(ParseRefData ${ref_data})" ; sleep 2 ; done ;