Last active
November 3, 2020 13:28
-
-
Save adamelso/2c0fa7052d04aee54fc7 to your computer and use it in GitHub Desktop.
Delete inactive branches from Platform.sh - Edit to your own needs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./plaform-inactive.sh delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
function platform_sh_show_inactive { | |
TABLE=$(platform | grep 'Inactive') | |
COUNT=0 | |
while read -r ROW; do | |
while IFS='|' read -ra BRANCH; do | |
echo "${BRANCH[1]}" | |
done <<< "$ROW" | |
done <<< "$TABLE" | |
} | |
function platform_sh_filter_inactive_by_prefix { | |
BRANCHES=$( platform_sh_show_inactive ) | |
while read -r BRANCH; do | |
if [[ $BRANCH == ae-* ]]; then | |
echo $BRANCH | |
fi | |
done <<< "$BRANCHES" | |
} | |
function platform_sh_delete_inactive { | |
BRANCHES=$( platform_sh_filter_inactive_by_prefix ) | |
while read -r BRANCH; do | |
platform environment:delete --environment=$BRANCH | |
done <<< "$BRANCHES" | |
} | |
COMMAND="$1" | |
shift | |
case "$COMMAND" in | |
'filter' ) | |
platform_sh_filter_inactive_by_prefix | |
;; | |
'show' ) | |
platform_sh_show_inactive | |
;; | |
'delete' ) | |
platform_sh_delete_inactive | |
;; | |
* ) | |
echo "error: command '$COMMAND' not found" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment