<commit_before><commit_msg>initial hook restricting author merges<commit_after>#!/bin/bash
#
# This hook restricts changes on the default branch to those made with the GUI Pull Request Merge button, or the Pull Request Merge API.
#
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
while read -r oldrev newrev refname; do
  if [[ "${refname}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
    exit 0
  else
    if [[ "${GITHUB_VIA}" != 'pull request merge button' && \
          "${GITHUB_VIA}" != 'pull request merge api' ]]; then
      echo "Changes to the default branch must be made by Pull Request. Direct pushes, edits, or merges are not allowed."
      exit 1
    else
      AUTHOR_COUNT=$(git log ${DEFAULT_BRANCH}..${newrev} --author="${GITHUB_USER_LOGIN}" --format='%an %cn' | wc -l)
      echo "Found ${AUTHOR_COUNT} commits"
      echo "$oldrev"
      echo "$GITHUB_USER_LOGIN"
      if (( ${AUTHOR_COUNT} == 0 )); then
        # No commits containing the current author
        exit 0
      else
        echo "Merging restricted on this branch. Author of commits cannot merge." 
        echo "Found the following commits by author ${GITHUB_USER_LOGIN}"
        echo -e $(git log ${DEFAULT_BRANCH}..${newrev} --author="${GITHUB_USER_LOGIN}")
        # --format='%an %h'
        exit 1
      fi
    fi
  fi
done
{'fraction_non_alphanumeric': 0.12376613515565679, 'fraction_numerical': 0.0037965072133637054, 'mean_word_length': 2.993939393939394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3946919', 'n_tokens_mistral': 421, 'n_tokens_neox': 403, 'n_words': 144}