Skip to content

Instantly share code, notes, and snippets.

@jvican
Created May 3, 2018 21:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvican/b163ce76d8d6c3da4e6b8bc3036ca18e to your computer and use it in GitHub Desktop.
Save jvican/b163ce76d8d6c3da4e6b8bc3036ca18e to your computer and use it in GitHub Desktop.
Script to find out the percentage of commits that modified sbt build files in a repository.
#!/bin/bash -
#===============================================================================
#
# FILE: sbt-build-stats-git.sh
#
# USAGE: ./sbt-build-stats-git.sh
#
# DESCRIPTION: Script that outputs what's the percentage of commits in a codebase
# that modified the sbt build files. It can be modified to support
# statistics in other files.
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Jorge Vicente Cantero
# ORGANIZATION: Scala Center
# CREATED: 05/03/2018 09:32:45 PM CEST
# REVISION: 1.0
#===============================================================================
set -o nounset # Treat unset variables as an error
BRANCH=${1:-master}
ALL_COMMITS_BUT_FIRST=$(git rev-list --min-parents=1 "$BRANCH")
ALL_COMMITS_BUT_FIRST_COUNT=$(echo "$ALL_COMMITS_BUT_FIRST" | wc -l)
TOTAL_COMMITS=$((ALL_COMMITS_BUT_FIRST_COUNT + 1))
count=0
for commit in $ALL_COMMITS_BUT_FIRST; do
if git diff --name-only "$commit" "$commit"~1 | grep '.*\.sbt$' > /dev/null 2>&1; then
count=$((count + 1))
fi
done
PERCENTAGE=$(echo "scale=2; $count * 100 / $TOTAL_COMMITS" | bc -l)
echo "Total commits in the branch $BRANCH is $TOTAL_COMMITS"
echo "Detected changes in branch $BRANCH is $count"
echo "The percentage of commits that modify sbt build files is $PERCENTAGE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment