Skip to content

Instantly share code, notes, and snippets.

@adamelso
Last active November 3, 2020 13:28
Show Gist options
  • Save adamelso/2c0fa7052d04aee54fc7 to your computer and use it in GitHub Desktop.
Save adamelso/2c0fa7052d04aee54fc7 to your computer and use it in GitHub Desktop.
Delete inactive branches from Platform.sh - Edit to your own needs
./plaform-inactive.sh delete
#!/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