File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ msg_file=" ${1:- } "
5+ if [[ -z " $msg_file " || ! -f " $msg_file " ]]; then
6+ exit 0
7+ fi
8+
9+ # Do not override an explicit commit message.
10+ if [[ -s " $msg_file " ]]; then
11+ exit 0
12+ fi
13+
14+ files=$( git diff --cached --name-only --diff-filter=ACMR 2> /dev/null || true)
15+ if [[ -z " $files " ]]; then
16+ exit 0
17+ fi
18+
19+ # Prefer a conventional-commit style subject.
20+ type=" chore"
21+ for path in $files ; do
22+ lower=$( printf ' %s' " $path " | tr ' [:upper:]' ' [:lower:]' )
23+ if [[ " $lower " == * " fix" * || " $lower " == * " bug" * || " $lower " == * " error" * || " $lower " == * " debug" * ]]; then
24+ type=" fix"
25+ break
26+ elif [[ " $lower " == * " test" * || " $lower " == * " spec" * ]]; then
27+ type=" test"
28+ elif [[ " $lower " == * " readme" * || " $lower " == * " doc" * || " $lower " == * " guide" * ]]; then
29+ type=" docs"
30+ elif [[ " $lower " == * " feature" * || " $lower " == * " add" * || " $lower " == * " new" * ]]; then
31+ type=" feat"
32+ fi
33+ done
34+
35+ first_path=$( printf ' %s\n' " $files " | head -n 1)
36+ base_name=$( basename " $first_path " )
37+ clean_name=${base_name% .* }
38+ if [[ -z " $clean_name " || " $clean_name " == " ." ]]; then
39+ clean_name=" project"
40+ fi
41+
42+ if [[ $( printf ' %s\n' " $files " | wc -l | tr -d ' ' ) -gt 1 ]]; then
43+ summary=" update project files"
44+ else
45+ summary=" update ${clean_name} "
46+ fi
47+
48+ printf ' %s: %s\n' " $type " " $summary " > " $msg_file "
You can’t perform that action at this time.
0 commit comments