|
#!/usr/bin/env bash |
|
|
|
# COMMAND LINE ARGUMENTS |
|
FUNC=${1:-"tracked_by_git"} |
|
FILTER=${2:-"all"} |
|
OUR_BRANCH=${3:-"HEAD"} |
|
THEIR_BRANCH=${4:-"origin/master"} |
|
|
|
# LIBRARY CODE |
|
function filter { |
|
regexp="$1" |
|
grep -E "$regexp" |
|
} |
|
|
|
function exclude { |
|
regexp="$1" |
|
grep -Ev "$regexp" |
|
} |
|
|
|
function branch_changes { |
|
git diff --name-status "$THEIR_BRANCH".."$OUR_BRANCH" |
|
} |
|
|
|
function user_email { |
|
mailmap_entry=$(echo "<$(git config user.email)>" | git check-mailmap --stdin) |
|
echo $mailmap_entry | sed -E 's/^.*<|>.*$//g' |
|
} |
|
|
|
function with_leading_dot { |
|
while read path; do echo "./$path"; done |
|
} |
|
|
|
# AVAILABLE COMMANDS |
|
function touched_by_user { |
|
git log --use-mailmap --no-merges --author="$(user_email)" --diff-filter=ACM --name-only --pretty=format:"" | sort -u |
|
} |
|
|
|
function in_git_stage { |
|
git status --short | cut -d ' ' -f3 |
|
} |
|
|
|
function added_in_git_stage { |
|
git status --short | filter "^ A" | cut -d ' ' -f3 |
|
} |
|
|
|
function touched_in_branch { |
|
branch_changes | cut -f2 |
|
} |
|
|
|
function added_in_branch { |
|
branch_changes | filter "^A" | cut -f2 |
|
} |
|
|
|
function tracked_by_git { |
|
git ls-tree -r HEAD --name-only |
|
} |
|
|
|
function src_dirs { |
|
find packages internals -name src -type d |
|
} |
|
|
|
# REGULAR EXPRESSIONS |
|
regexp_fixtures="\/fixtures\/" |
|
regexp_images="\.(bmp|gif|jpeg|jpg|png|svg)$" |
|
regexp_js="\.jsx?$" |
|
regexp_json="\.json$" |
|
regexp_md="\.md$" |
|
regexp_package_json="package\.json$" |
|
regexp_packages_dir="packages\/" |
|
regexp_recipes="\/recipes\/" |
|
regexp_rollup="\/rollup\.config\.js" |
|
regexp_scss="\.scss$" |
|
regexp_shell="\.sh$" |
|
regexp_spec_e2e="\.ui\.spec\." |
|
regexp_spec="\.spec\." |
|
regexp_storybook="(\/story\/|\/story.jsx?$)" |
|
|
|
# EXECUTE SCRIPT |
|
function apply_filters_to_function { |
|
if [ "$FILTER" = "fixtures" ]; then |
|
$FUNC | filter "$regexp_fixtures" |
|
elif [ "$FILTER" = "images" ]; then |
|
$FUNC | filter "$regexp_images" |
|
elif [ "$FILTER" = "jest" ]; then |
|
$FUNC | filter "$regexp_spec" \ |
|
| exclude "$regexp_spec_e2e" |
|
elif [ "$FILTER" = "js-source" ]; then |
|
$FUNC | filter "$regexp_js" \ |
|
| filter "$regexp_packages_dir" \ |
|
| exclude "$regexp_spec" \ |
|
| exclude "$regexp_fixtures" \ |
|
| exclude "$regexp_storybook" \ |
|
| exclude "$regexp_rollup" |
|
elif [ "$FILTER" = "js" ]; then |
|
$FUNC | filter "$regexp_js" |
|
elif [ "$FILTER" = "json" ]; then |
|
$FUNC | filter "$regexp_json" |
|
elif [ "$FILTER" = "md" ]; then |
|
$FUNC | filter "$regexp_md" |
|
elif [ "$FILTER" = "package-json" ]; then |
|
$FUNC | filter "$regexp_package_json" |
|
elif [ "$FILTER" = "recipes" ]; then |
|
$FUNC | filter "$regexp_recipes" |
|
elif [ "$FILTER" = "scss" ]; then |
|
$FUNC | filter "$regexp_scss" |
|
elif [ "$FILTER" = "shell" ]; then |
|
$FUNC | filter "$regexp_shell" |
|
elif [ "$FILTER" = "storybook" ]; then |
|
$FUNC | filter "$regexp_storybook" |
|
else |
|
$FUNC |
|
fi |
|
} |
|
|
|
apply_filters_to_function | with_leading_dot |