mirror of
https://github.com/donl/homebrew-cask-versions.git
synced 2026-07-16 22:06:43 -06:00
156 lines
4.6 KiB
Bash
Executable file
156 lines
4.6 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# project_stats
|
|
#
|
|
# stats on project/release from git database
|
|
#
|
|
|
|
###
|
|
### settings
|
|
###
|
|
|
|
set -e # exit on any uncaught error
|
|
set +o histexpand # don't expand history expressions
|
|
shopt -s nocasematch # case-insensitive regular expressions
|
|
|
|
###
|
|
### configurable global variables
|
|
###
|
|
|
|
# these paths relative to project root
|
|
cask_paths="Casks"
|
|
code_paths="bin developer lib test brew-cask.rb Rakefile Gemfile Gemfile.lock"
|
|
doc_paths="LICENSE *.md"
|
|
initial_commit="5a0d1d5556e3f963a0d34da46e16ecffa59ea2fc"
|
|
end_object="HEAD"
|
|
|
|
###
|
|
### functions
|
|
###
|
|
|
|
warn () {
|
|
local message="$@"
|
|
if ! [[ $message =~ "\n"$ ]]; then
|
|
message="${message}\n"
|
|
fi
|
|
printf "$message" 1>&2
|
|
}
|
|
|
|
die () {
|
|
warn "$@"
|
|
exit 1
|
|
}
|
|
|
|
cd_to_project_root () {
|
|
local script_dir="$(/usr/bin/dirname $0)"
|
|
cd "$script_dir"
|
|
local git_root="$(git rev-parse --show-toplevel)"
|
|
if [[ -z "$git_root" ]]; then
|
|
die "ERROR: Could not find git project root"
|
|
fi
|
|
cd "$git_root"
|
|
}
|
|
|
|
warn_if_off_branch () {
|
|
local wanted_branch='master'
|
|
if [[ -n "$1" ]]; then
|
|
wanted_branch="$1"
|
|
fi
|
|
|
|
local current_branch="$(git rev-parse --abbrev-ref HEAD)"
|
|
if ! [[ "$current_branch" = "$wanted_branch" ]]; then
|
|
warn "\nWARNING: you are running from branch '$current_branch', not '$wanted_branch'\n\n"
|
|
fi
|
|
}
|
|
|
|
verify_git_object () {
|
|
local object="$1"
|
|
|
|
if ! git rev-parse --verify "$object" -- >/dev/null 2>&1; then
|
|
die "\nERROR: No such commit object: '$object'\n\n"
|
|
fi
|
|
}
|
|
|
|
###
|
|
### main
|
|
###
|
|
|
|
_project_stats () {
|
|
|
|
local start_object="$initial_commit"
|
|
|
|
cd_to_project_root
|
|
warn_if_off_branch 'master'
|
|
|
|
if [[ "$1" = 'release' ]]; then
|
|
start_object="$(git describe --tags --abbrev=0)"
|
|
elif [[ -n "$1" ]]; then
|
|
start_object="$1"
|
|
fi
|
|
verify_git_object "$start_object"
|
|
|
|
printf "Unique contributors"
|
|
if ! [[ "$start_object" = "$initial_commit" ]]; then
|
|
printf " since $start_object"
|
|
fi
|
|
printf "\n"
|
|
|
|
local git_log_cmd="git log --no-merges --format='%ae' ${start_object}..${end_object}"
|
|
|
|
local cask_authors="$($git_log_cmd -- $cask_paths | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
|
printf " Casks\t$cask_authors\n"
|
|
printf " code\t"
|
|
$git_log_cmd -- $code_paths | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l
|
|
printf " docs\t"
|
|
$git_log_cmd -- $doc_paths | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l
|
|
printf " any\t"
|
|
$git_log_cmd -- . | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l
|
|
if ! [[ "$start_object" = "$initial_commit" ]]; then
|
|
local alltime_contribs="$(git log --no-merges --format='%ae' ${initial_commit}..${end_object} -- . | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
|
local prior_contribs="$(git log --no-merges --format='%ae' ${initial_commit}..${start_object} -- . | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
|
# arithmetic removes whitespace
|
|
((alltime_contribs += 0))
|
|
((new_contribs = alltime_contribs - prior_contribs))
|
|
printf "\nAll-time contributors\t$alltime_contribs\n"
|
|
printf "New contributors since $start_object\t$new_contribs\n"
|
|
fi
|
|
|
|
printf "\n"
|
|
|
|
if ! [[ "$start_object" = "$initial_commit" ]]; then
|
|
local new_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^A.*\.rb' | cut -f2 | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
|
local deleted_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^D.*\.rb' | cut -f2 | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
|
local updated_casks="$(git diff --name-status "$start_object" "$end_object" -- $cask_paths | /usr/bin/grep '^M.*\.rb' | cut -f2 | /usr/bin/sort | /usr/bin/uniq | /usr/bin/wc -l)"
|
|
# arithmetic removes whitespace
|
|
((cask_authors += 0))
|
|
((deleted_casks += 0))
|
|
((new_casks -= deleted_casks))
|
|
((updated_casks += 0))
|
|
printf "$new_casks Casks added ($updated_casks updated) by $cask_authors contributors since $start_object\n"
|
|
fi
|
|
|
|
printf "Total current Casks in HEAD\t"
|
|
/usr/bin/find $cask_paths -name '*.rb' | /usr/bin/wc -l
|
|
|
|
}
|
|
|
|
# process args
|
|
if [[ $1 =~ ^-+h(elp)?$ ]]; then
|
|
printf "project_stats [ <commit-object> ]
|
|
|
|
With optional single argument, (eg a tag or commit-hash)
|
|
show statistics since that commit object.
|
|
|
|
Use the special argument 'release' to calculate since the
|
|
most recent tag (usually the same as the last release).
|
|
|
|
Without argument, show statistics since first commit.
|
|
|
|
"
|
|
exit
|
|
fi
|
|
|
|
# dispatch main
|
|
_project_stats "${@}"
|
|
|
|
#
|