mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
22 lines
806 B
Bash
Executable File
22 lines
806 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
#
|
|
# Based on the name of the current branch this will compute the name of the associated
|
|
# preview environment.
|
|
#
|
|
# NOTE: This needs to produce the same result as the function in .werft/util/preview.ts
|
|
# See the file for implementation notes.
|
|
#
|
|
function preview-name-from-branch {
|
|
branch_name=$(git symbolic-ref HEAD 2>&1) || error "Cannot get current branch"
|
|
sanitizedd_branch_name=$(echo "$branch_name" | awk '{ sub(/^refs\/heads\//, ""); $0 = tolower($0); gsub(/[^-a-z0-9]/, "-"); print }')
|
|
length=$(echo -n "$sanitizedd_branch_name" | wc -c)
|
|
|
|
if [ "$length" -gt 20 ]; then
|
|
hashed=$(echo -n "${sanitizedd_branch_name}" | sha256sum)
|
|
echo "${sanitizedd_branch_name:0:10}${hashed:0:10}"
|
|
else
|
|
echo "${sanitizedd_branch_name}"
|
|
fi
|
|
}
|