diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2020-04-10 17:24:45 -0400 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2020-04-12 19:00:58 -0400 |
commit | 013f6827155ccc676f9f47b52464f1d1bffec7df (patch) | |
tree | 8e4def8a4793ad134856d24cde3456aa034ede3a | |
parent | 908830a90c483356e026864547ddde79c33efdf6 (diff) |
bugfix git hook
-rwxr-xr-x | notify-pbot-git-hook | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/notify-pbot-git-hook b/notify-pbot-git-hook index b646910..8331c14 100755 --- a/notify-pbot-git-hook +++ b/notify-pbot-git-hook @@ -7,6 +7,7 @@ ## constants ## + readonly LOG_PBOT_GIT_HOOK=1 readonly LOG_DIR=/var/log/pbot readonly SHA_REGEX='^([0-9a-f]{40})$' @@ -18,8 +19,9 @@ LogFile() # (repo ref) { local repo=$1 local ref=$2 + local log_file=${LOG_DIR}/notify-pbot-${repo}-${ref} - echo ${LOG_DIR}/notify-pbot-${repo}-${ref} + echo ${log_file} } LogParseRefDataIn() # (ref_data prev_sha curr_sha ref_file repo ref is_deletion) @@ -29,8 +31,8 @@ LogParseRefDataIn() # (ref_data prev_sha curr_sha ref_file repo ref is_deletion) local log_file=$(LogFile ${repo} ${ref}) (( $LOG_PBOT_GIT_HOOK )) && echo "ref_data=${ref_data}" > ${log_file} && \ - echo "prev=${prev}" >> ${log_file} && \ - echo "curr=${curr}" >> ${log_file} && \ + echo "prev=${prev_sha}" >> ${log_file} && \ + echo "curr=${curr_sha}" >> ${log_file} && \ echo "ref_file=${ref_file}" >> ${log_file} && \ echo "ref=${ref}" >> ${log_file} && \ echo "is_deletion=${is_deletion}" >> ${log_file} @@ -56,36 +58,36 @@ LogParseRefDataOut() # (hacker author log_msg n_behind n_ahead n_total repo ref) ParseRefData() # (prev_sha curr_sha ref_file) { - local prev=$1 - local curr=$2 + local prev_sha=$1 + local curr_sha=$2 local ref_file=$3 local ref=${ref_file##*/} local repo=$(basename $(pwd)) local is_deletion=$(git show-ref "${ref}" > /dev/null && echo 0 || echo 1) - LogParseRefDataIn ${ref_data} ${prev_sha} ${curr_sha} ${ref_file} ${repo} ${ref} ${is_deletion} + LogParseRefDataIn "${ref_data}" ${prev_sha} ${curr_sha} ${ref_file} ${repo} ${ref} ${is_deletion} # validate ref data - [[ "$#" == '3' ]] && \ - [[ "${prev}" =~ ${SHA_REGEX} ]] && \ - [[ "${curr}" =~ ${SHA_REGEX} ]] && \ - [[ "${ref}" ]] || return + [[ "$#" == '3' ]] && \ + [[ "${prev_sha}" =~ ${SHA_REGEX} ]] && \ + [[ "${curr_sha}" =~ ${SHA_REGEX} ]] && \ + [[ "${ref}" ]] || return # collect push details - local hacker=$( /usr/lib/parabola-hackers/last-hacker-login ) - local author="$( git log -1 --format='%an' ${curr} )" - local log_msg="$(git log -1 --format='%s' ${curr} )" - local n_behind=$(git rev-list --count ${curr}..${prev} 2> /dev/null) - local n_ahead=$( git rev-list --count ${prev}..${curr} 2> /dev/null) - local n_total=$( git rev-list --count ${ref} 2> /dev/null) + local hacker=$( /usr/lib/parabola-hackers/last-hacker-login ) + local author="$( git log -1 --format='%an' ${curr_sha} )" + local log_msg="$(git log -1 --format='%s' ${curr_sha} )" + 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) LogParseRefDataOut ${hacker} ${author} ${log_msg} ${n_behind} ${n_ahead} ${n_total} ${repo} ${ref} - # fall-back to author name if the detector fails + # fall-back to author name if the hacker detector fails [[ "${hacker}" ]] || hacker="${author}" # detect new ref - [[ ${prev} =~ ^0{40}$ ]] && n_behind='∞' n_ahead=${n_total} + [[ ${prev_sha} =~ ^0{40}$ ]] && n_behind='∞' n_ahead=${n_total} # prepare pbot message if (( ${is_deletion} )) |