Last active
February 11, 2020 14:35
-
-
Save AaronDMarasco-VSI/87448c15158a91d2fe8462e6339b185d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# Note: The job "Maintenance/Branch_Check_Configure" needs to be re-run whenever this file is changed! | |
declare -A merged | |
declare -A ignores | |
declare -A aliases | |
declare -A authors | |
declare -A authors_delete | |
ignores[master]=1 | |
ignores[develop]=1 | |
ignores[develop_oss_merge]=1 | |
ignores[open_source_pristine]=1 | |
aliases["Aaron Marasco"]="Aaron D. Marasco" | |
# Jenkins does this automatically: | |
if [ -z "${JENKINS_HOME}" ]; then | |
echo "Pulling and pruning..." | |
git pull --prune || exit 1 | |
fi | |
# Get merged list for "develop" | |
for branch in $(git branch -r --merged origin/develop | egrep '^\s*origin/' | cut -f2- -d/ | grep -v -- '->'); do | |
merged[${branch}]=1 | |
done | |
# Get list of remote branches | |
for branch in $(git branch -r | egrep '^\s*origin/' | cut -f2- -d/ | egrep -v '^v[1-9]' | grep -v -- '->' | sort); do | |
# git log -1 --pretty="format:Checking branch ${branch}: %an %h%d (%ar)%n" "origin/${branch}" | |
author=$(git log -1 --pretty="format:%an" "origin/${branch}") | |
[ -n "${aliases[${author}]}" ] && author="${aliases[${author}]}" | |
if [ -n "${merged[${branch}]}" -a -z "${ignores[${branch}]}" ]; then | |
# echo "** Branch seems to be merged **" | |
authors_delete["${author}"]="${authors_delete["${author}"]} ${branch}" | |
# Need to initalize the author in case this is their only branch AV-4808 | |
authors["${author}"]="${authors["${author}"]}" | |
else | |
authors["${author}"]="${authors["${author}"]} ${branch}" | |
fi | |
done | |
# unset authors_delete; declare -A authors_delete # for debugging return values, etc | |
{ # Begin tee redirect ended below | |
# echo "Author report:" | |
for author in "${!authors[@]}"; do | |
echo "${author}:" | |
for branch in ${authors_delete["${author}"]}; do | |
git log -1 --pretty="format: ${branch}: %ar (merged)%n" "origin/${branch}" | |
done | |
for branch in ${authors["${author}"]}; do | |
git log -1 --pretty="format: ${branch}: %ar%n" "origin/${branch}" | |
done | |
done | |
if (( ${#authors_delete[@]} )); then | |
printf "\n===\n\n" | |
echo "Branches ready to delete:" | |
for author in "${!authors[@]}"; do | |
if [ -n "${authors_delete[${author}]}" ]; then | |
echo "${author}:" | |
fi | |
for branch in ${authors_delete["${author}"]}; do | |
git log -1 --pretty="format: ${branch} (%ar)%n" "origin/${branch}" | |
done | |
done | |
fi | |
} | tee branch_report.log | |
(( ${#authors_delete[@]} )) && exit 2 # If anything reported, return 2 for Jenkins "unstable" | |
exit 0 # Script success if this far (otherwise would return 1 because above line FAILED) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment