<commit_before>#!/usr/bin/env bash

function cleanup {
  rm -rf "$WORK_DIR"
  echo -e "\033[33mDeleted temp working directory $WORK_DIR\033[0m"
}

function check-deps() {
  if ! which abc2midi &> /dev/null; then
  	>&2 echo “Error: Please install abc2midi and make sure it is in your path”
  	exit 1
  fi

  if ! which lein &> /dev/null; then
  	>&2 echo “Error: Please install Leinginen and make sure it is in your path”
  	exit 1
  fi

  if ! which java &> /dev/null; then
  	>&2 echo “Error: Please install Java and make sure it is in your path”
  	exit 1
  fi

  if ! which timidity &> /dev/null; then
  	>&2 echo “Error: Please install timidity and make sure it is in your path”
  	exit 1
  fi
}

function check-usage() {
  if [[ $# -lt 2 ]]; then
    >&2 echo "Usage: go-gh.sh <github-user> <github-repo>"
    exit 1
  fi
}

function clone-repo() {
  echo -e "\033[33mCloning repo to $WORK_DIR...\033[0m"
  cd $WORK_DIR
  git clone -q https://github.com/$GITHUB_USER/$GITHUB_REPO.git
}

function collect-commit-info() {
  echo -e "\033[33mFind commit history for each Java file...\033[0m"
  pushd $WORK_DIR/$GITHUB_REPO >/dev/null
  find . -regex $SOURCE_FILE_RE | xargs -n1 git blame -f -t -e | awk -v PREFIX=${WORK_DIR}/${GITHUB_REPO}/ -F "[ ()]+" '{print PREFIX $2 "#"$6 " AU=" $3 " TS=" $4}' > ${WORK_DIR}/blames.txt
  popd >/dev/null
}

function collect-duplication-metrics() {
  echo -e "\033[34mGenerating Checkstyle duplication metrics...\033[0m"
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  CHECKSTYLEDIR=$DIR/resources
  java -jar $CHECKSTYLEDIR/simian-2.4.0.jar -threshold=4 -failOnDuplication- -excludes="**/test/**/*.java" $WORK_DIR/**/*.java | tail -3 | head -2 > ${WORK_DIR}/duplication.txt
  DUPLICATESTATS=`cat ${WORK_DIR}/duplication.txt`
  TOTALDUPLINESRE='Found ([0-9]+).*'
  TOTALLINESRE='Processed a total of ([0-9]+).*'<commit_msg>Git blame output now in EDN<commit_after>#!/usr/bin/env bash

function cleanup {
  rm -rf "$WORK_DIR"
  echo -e "\033[33mDeleted temp working directory $WORK_DIR\033[0m"
}

function check-deps() {
  if ! which abc2midi &> /dev/null; then
  	>&2 echo “Error: Please install abc2midi and make sure it is in your path”
  	exit 1
  fi

  if ! which lein &> /dev/null; then
  	>&2 echo “Error: Please install Leinginen and make sure it is in your path”
  	exit 1
  fi

  if ! which java &> /dev/null; then
  	>&2 echo “Error: Please install Java and make sure it is in your path”
  	exit 1
  fi

  if ! which timidity &> /dev/null; then
  	>&2 echo “Error: Please install timidity and make sure it is in your path”
  	exit 1
  fi
}

function check-usage() {
  if [[ $# -lt 2 ]]; then
    >&2 echo "Usage: go-gh.sh <github-user> <github-repo>"
    exit 1
  fi
}

function clone-repo() {
  echo -e "\033[33mCloning repo to $WORK_DIR...\033[0m"
  cd $WORK_DIR
  git clone -q https://github.com/$GITHUB_USER/$GITHUB_REPO.git
}

function collect-commit-info() {
  echo -e "\033[33mFind commit history for each Java file...\033[0m"
  pushd $WORK_DIR/$GITHUB_REPO >/dev/null
  find . -regex $SOURCE_FILE_RE | xargs -n1 git blame -f -t -e | awk -v PREFIX=${WORK_DIR}/${GITHUB_REPO}/ -F "[ ()]+" '{print "{:source-file \"" PREFIX $2 "#"$6 "\" :author \"" $3 "\" :timestamp \"" $4 "\"}"}' > ${WORK_DIR}/blames.txt
  popd >/dev/null
}

function collect-duplication-metrics() {
  echo -e "\033[34mGenerating Checkstyle duplication metrics...\033[0m"
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  CHECKSTYLEDIR=$DIR/resources
  java -jar $CHECKSTYLEDIR/simian-2.4.0.jar -threshold=4 -failOnDuplication- -excludes="**/test/**/*.java" $WORK_DIR/**/*.java | tail -3 | head -2 > ${WORK_DIR}/duplication.txt
  DUPLICATESTATS=`cat ${WORK_DIR}/duplication.txt`
  TOTALDUPLINESRE='Found ([0-9]+).*'
  TOTALLINESRE='Processed a total of ([0-9]+).*'
{'fraction_non_alphanumeric': 0.16692913385826771, 'fraction_numerical': 0.03412073490813648, 'mean_word_length': 3.3110859728506785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 33, 'https://': 2, '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': '1802328', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1454, 'n_words': 419}