Skip to content

Commit

Permalink
Breaking up into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Jun 24, 2020
1 parent 2c3c737 commit d1a9b18
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions dev-tools/module_committers
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@ set -euo pipefail
# module_devs <module name, partial ok>
#

find_beat_dirs() {
find $beats_base_dir -type d -iname \*beat -maxdepth 2 | grep -v libbeat
}

find_module_dirs() {
beat_dirs="$1"
module_name="$2"

module_dirs=""
for beat_dir in $beat_dirs; do
if [ -d "$beat_dir/module" ]; then
module_dirs=$module_dirs" "$(find $beat_dir/module -type d -depth 1)
fi
done

found_dirs=""
for module_dir in $module_dirs; do
module=$(echo $module_dir | awk -F\/ '{ print $NF}')
if [[ "$module" == *"$module_name"* ]]; then
found_dirs=$found_dirs" "$module_dir
fi
done

echo "$found_dirs"
}

print_recent_top_committers() {
module_dirs="$1"
for module_dir in $module_dirs; do
echo "Found matching $module_dir:"
cd $module_dir
echo " Recent top committers:"
git log --since="one year ago" --pretty=format:"%an" -- . | sort | uniq -c | sort -nr | head -3 | awk '{$1 = ""; print " -"$0}'
done
}

module_name="$1"
if [ -z "$module_name" ]; then
echo "Usage: module_devs <module name>"
Expand All @@ -17,26 +53,6 @@ fi

beats_base_dir=$(cd $(dirname $BASH_SOURCE)/..; pwd)

beat_dirs=$(find $beats_base_dir -type d -iname \*beat -maxdepth 2 | grep -v libbeat)

module_dirs=""
for beat_dir in $beat_dirs; do
if [ -d "$beat_dir/module" ]; then
module_dirs=$module_dirs" "$(find $beat_dir/module -type d -depth 1)
fi
done

found_dirs=""
for module_dir in $module_dirs; do
module=$(echo $module_dir | awk -F\/ '{ print $NF}')
if [[ "$module" == *"$module_name"* ]]; then
found_dirs=$found_dirs" "$module_dir
fi
done

for found_dir in $found_dirs; do
echo "Found matching $found_dir:"
cd $found_dir
echo " Recent top committers:"
git log --since="one year ago" --pretty=format:"%an" -- . | sort | uniq -c | sort -nr | head -3 | awk '{$1 = ""; print " -"$0}'
done
beat_dirs=$(find_beat_dirs)
module_dirs=$(find_module_dirs "$beat_dirs" "$module_name")
print_recent_top_committers "$module_dirs"

0 comments on commit d1a9b18

Please sign in to comment.