From 2712d1a9f069e8dac601bdeefe1d9ee59527eb40 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Mon, 19 Aug 2019 20:04:29 +0700 Subject: [PATCH] chore: cleanup and minify code --- please | 43 ++++++++++--------------------------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/please b/please index 45658b0..741ffb9 100755 --- a/please +++ b/please @@ -16,13 +16,9 @@ FULL=`readlink -f $0` # fullpath PLIZ=`basename $0` # name line() { echo -e "\e[${3:-0};$2m$1\e[0m"; } - -error() { line "$1" 31; } - +error() { line "$1" 31; if [[ ! ${2:-0} -eq 0 ]]; then exit $2; fi } ok() { line "${1:- Done}" 32; } - info() { line "$1" 33; } - comment() { line "$1" 30 1; } qgit() { git "$@" &>> $TMP_LOG; } @@ -31,14 +27,10 @@ qgit() { git "$@" &>> $TMP_LOG; } github() { RESP=`bash -c "curl --silent -H 'Authorization: token $GH_AUTH_TOKEN' $@"` - echo "${RESP}" >> ${TMP_LOG} + echo "$RESP" >> ${TMP_LOG} ERROR=`echo $RESP | jq -r '.message?'` - - if [ "" != "$ERROR" ] && [ "null" != "$ERROR" ]; then - error "Github: $ERROR" - exit 1 - fi + if [ "" != "$ERROR" ] && [ "null" != "$ERROR" ]; then error "Github: $ERROR" 1; fi echo "$RESP" } @@ -98,19 +90,12 @@ EXAMPLE organize-commits() # $1 = diff_range, $2 = commit_types_csv { declare -A LABELS=( - [feat]=Features - [fix]="Bug Fixes" - [refactor]="Internal Refactors" - [perf]="Performance Improvements" - [test]=Tests - [docs]=Documentations - [chore]=Miscellaneous - [style]="Code Standards" - [infra]="Infrastructure Changes" + [feat]=Features [fix]="Bug Fixes" [refactor]="Internal Refactors" + [perf]="Performance Improvements" [test]=Tests [docs]=Documentations + [chore]=Miscellaneous [style]="Code Standards" [infra]="Infrastructure Changes" ) declare -A CHANGELOG - while read -r COMMIT; do if [[ $COMMIT =~ ^([a-z]+)\(?([^\)]+)?\)?:\ (.+) ]]; then type="${BASH_REMATCH[1]}" scope="${BASH_REMATCH[2]}" subject="${BASH_REMATCH[3]}" @@ -175,15 +160,10 @@ publish-phar() { PBIN=`cat composer.json | jq -r '.bin[0]?'` if [ "null" == "$PBIN" ]; then - error "Check bin value in composer.json" info "Check ${TMP_LOG} for logs" - exit 1 + error "Check bin value in composer.json" 1 fi - info "Cleaning up ..." - rm -rf ./vendor/cov - ok - info "Compiling phar ..." php `get-box` compile >> ${TMP_LOG} ok @@ -268,8 +248,7 @@ do done if [ "" == "$REPO" ]; then - error "$(pwd) is not git repo" - exit 1 + error "$(pwd) is not git repo" 1 fi GPUSH=0 # git push pending @@ -281,8 +260,7 @@ YES=${YES:-0} # assume yes # gh auth if [ -z "$GH_AUTH_TOKEN" ]; then - error "GH_AUTH_TOKEN missing" - exit 1 + error "GH_AUTH_TOKEN missing" 1 fi GH_REPO="github.com/repos/$REPO" @@ -349,8 +327,7 @@ if [[ $YES -eq 0 ]]; then read -p "Are you sure to release [$NEXT_VERSION]? [y/N] " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then - error "Not releasing $NEXT_VERSION" - exit 1 + error "Not releasing $NEXT_VERSION" 1 fi fi