feat(scripts): correctly handle path scopes
This commit is contained in:
parent
a5d9a9670e
commit
e8f31036f6
|
@ -52,6 +52,7 @@ MODIFIED_PATHS=()
|
|||
while IFS= read -r file
|
||||
do
|
||||
path="$(head_path "$file")"
|
||||
path="${path%/}"
|
||||
debug_log "$(printf 'file: %s\n' "$file")"
|
||||
debug_log "$(printf 'path: %s\n' "$path")"
|
||||
MODIFIED_PATHS+=("$path")
|
||||
|
@ -59,36 +60,34 @@ done <<< "${MODIFIED_FILES}"
|
|||
|
||||
debug_log "$(printf 'paths: %d\n' "${#MODIFIED_PATHS[@]}")"
|
||||
|
||||
readarray -t UNIQUE_PATHS < <(printf '%s\n' "${MODIFIED_PATHS[@]}" | sort | uniq)
|
||||
|
||||
debug_log "$(printf 'unique paths: %s\n' "${UNIQUE_PATHS[@]}")"
|
||||
|
||||
readarray -t UNIQUE_SCOPES < <(for i in ${UNIQUE_PATHS[@]}; do echo $i; done | grep -e '.*/$')
|
||||
readarray -t UNIQUE_SCOPES < <(printf '%s\n' "${MODIFIED_PATHS[@]}" | sort | uniq)
|
||||
|
||||
debug_log "$(printf 'unique scopes: %s\n' "${UNIQUE_SCOPES[@]}")"
|
||||
|
||||
# git prefix
|
||||
GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||
GIT_PREFIX="$(printf '%s\n' "${GIT_BRANCH}" | sed 's:/.*$::g')"
|
||||
|
||||
BRANCH_PREFIX="$(printf '%s\n' "${GIT_BRANCH}" | sed 's:/.*$::g')"
|
||||
COMMIT_PREFIX="${COMMIT_PREFIX:-${GIT_PREFIX}}"
|
||||
|
||||
debug_log "branch: $GIT_BRANCH"
|
||||
debug_log "prefix: $BRANCH_PREFIX"
|
||||
debug_log "prefix: $COMMIT_PREFIX"
|
||||
|
||||
DEFAULT_MESSAGE="$(cat ${MESSAGE_FILE})"
|
||||
COMMIT_MESSAGE=""
|
||||
|
||||
if [[ ${#UNIQUE_SCOPES[@]} -gt 1 ]];
|
||||
then
|
||||
debug_log "many paths"
|
||||
COMMIT_MESSAGE="${BRANCH_PREFIX}: ${DEFAULT_MESSAGE}"
|
||||
debug_log "many scopes"
|
||||
COMMIT_MESSAGE="${COMMIT_PREFIX}: ${DEFAULT_MESSAGE}"
|
||||
else
|
||||
debug_log "single path"
|
||||
debug_log "single scope"
|
||||
if [[ ! -z "${UNIQUE_SCOPES[0]}" ]];
|
||||
then
|
||||
COMMIT_MESSAGE="${BRANCH_PREFIX}(${UNIQUE_SCOPES[0]}): ${DEFAULT_MESSAGE}"
|
||||
COMMIT_MESSAGE="${COMMIT_PREFIX}(${UNIQUE_SCOPES[0]}): ${DEFAULT_MESSAGE}"
|
||||
else
|
||||
COMMIT_MESSAGE="${BRANCH_PREFIX}(???): ${DEFAULT_MESSAGE}"
|
||||
debug_log "empty scope"
|
||||
COMMIT_MESSAGE="${COMMIT_PREFIX}(???): ${DEFAULT_MESSAGE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue