mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-12 20:21:02 +01:00
perf(changelog): use regex-match instead of sed
to parse commit subjects
This commit is contained in:
parent
140bfa8432
commit
0267cb89eb
1 changed files with 20 additions and 10 deletions
|
@ -52,10 +52,15 @@ function parse-commit {
|
||||||
# make a breaking change
|
# make a breaking change
|
||||||
|
|
||||||
function commit:type {
|
function commit:type {
|
||||||
local type="$(sed -E 's/^([a-zA-Z_\-]+)(\(.+\))?!?: .+$/\1/' <<< "$1")"
|
local type
|
||||||
|
|
||||||
|
# Parse commit type from the subject
|
||||||
|
if [[ "$1" =~ '^([a-zA-Z_\-]+)(\(.+\))?!?: .+$' ]]; then
|
||||||
|
type="${match[1]}"
|
||||||
|
fi
|
||||||
|
|
||||||
# If $type doesn't appear in $TYPES array mark it as 'other'
|
# If $type doesn't appear in $TYPES array mark it as 'other'
|
||||||
if [[ -n "${(k)TYPES[(i)$type]}" ]]; then
|
if [[ -n "$type" && -n "${(k)TYPES[(i)$type]}" ]]; then
|
||||||
echo $type
|
echo $type
|
||||||
else
|
else
|
||||||
echo other
|
echo other
|
||||||
|
@ -66,17 +71,18 @@ function parse-commit {
|
||||||
local scope
|
local scope
|
||||||
|
|
||||||
# Try to find scope in "type(<scope>):" format
|
# Try to find scope in "type(<scope>):" format
|
||||||
scope=$(sed -nE 's/^[a-zA-Z_\-]+\((.+)\)!?: .+$/\1/p' <<< "$1")
|
if [[ "$1" =~ '^[a-zA-Z_\-]+\((.+)\)!?: .+$' ]]; then
|
||||||
if [[ -n "$scope" ]]; then
|
echo "${match[1]}"
|
||||||
echo "$scope"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If no scope found, try to find it in "<scope>:" format
|
# If no scope found, try to find it in "<scope>:" format
|
||||||
# Make sure it's not a type before printing it
|
if [[ "$1" =~ '^([a-zA-Z_\-]+): .+$' ]]; then
|
||||||
scope=$(sed -nE 's/^([a-zA-Z_\-]+): .+$/\1/p' <<< "$1")
|
scope="${match[1]}"
|
||||||
if [[ -z "${(k)TYPES[(i)$scope]}" ]]; then
|
# Make sure it's not a type before printing it
|
||||||
echo "$scope"
|
if [[ -z "${(k)TYPES[(i)$scope]}" ]]; then
|
||||||
|
echo "$scope"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +90,11 @@ function parse-commit {
|
||||||
# Only display the relevant part of the commit, i.e. if it has the format
|
# Only display the relevant part of the commit, i.e. if it has the format
|
||||||
# type[(scope)!]: subject, where the part between [] is optional, only
|
# type[(scope)!]: subject, where the part between [] is optional, only
|
||||||
# displays subject. If it doesn't match the format, returns the whole string.
|
# displays subject. If it doesn't match the format, returns the whole string.
|
||||||
sed -E 's/^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$/\2/' <<< "$1"
|
if [[ "$1" =~ '^[a-zA-Z_\-]+(\(.+\))?!?: (.+)$' ]]; then
|
||||||
|
echo "${match[2]}"
|
||||||
|
else
|
||||||
|
echo "$1"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return subject if the body or subject match the breaking change format
|
# Return subject if the body or subject match the breaking change format
|
||||||
|
|
Loading…
Reference in a new issue