шпаргалки склеротиков

Previous Entry Share Next Entry
gitlab custom hooks (prohibit retagging)
anonymus88
# mkdir /var/opt/gitlab/custom_hooks
# chown -R git:git /var/opt/gitlab/custom_hooks
# cat /var/opt/gitlab/custom_hooks/pre-receive
>>

#!/bin/bash

git='/usr/bin/git'
mailx='/bin/mailx'
send_report_to=(
 'anon@tech.ru'
# 'anon1@tech.ru'
# 'anon2@tech.ru'
)

report_subj='git policy offender has been found'
repo=${PWD#/var/opt/gitlab/git-data/repositories/}

send_report(){
  url=https://${HOSTNAME}/${repo%.git}/commit/"${NEW_REV}"

  commit_info=();
  while read -r; do
    commit_info+=($REPLY);
  done < <(  $git cat-file commit $NEW_REV )

  user="${commit_info[5]}"
  for address in "${send_report_to[@]}"; do
    echo -e 'Failed to force tag' '\n'Rascal is: "${user}" '\n'URL: "${url}" | "$mailx" -s "$report_subj" "$address"
  done
}

check_commit(){
  taglist=()

 { [[ $REFNAME == *'refs/tags/'* ]] && newtag=${REFNAME#refs/tags/} ; } || { return 0 ; }

  while read -r ; do
    taglist+=("$REPLY")
  done < <($git tag)

  for tag in "${taglist[@]}"; do
    [[ "${tag}" == "${newtag}" ]] && { echo "FORCED TAGS PROHIBITED" ; send_report ; exit 1 ; }
  done
}

while read OLD_REV NEW_REV REFNAME ; do
  check_commit

echo

echo  $OLD_REV $NEW_REV $REFNAME >> /tmp/debug
done
exit 0
Tags: ,

?

Log in