For quite some time we were not able to delete our git development
branches. Now, that the functionality has been restored, we'd like to
remove all the branches that are no longer needed (preferably in an
automated way).

Here's a script I came up with, that should identify all branches and their
respective Jira ticket correctly:

for branch in $(git branch -r | grep -Po 'TINKERPOP[3]?-.*'); do
  jira=`sed 's/TINKERPOP3/TINKERPOP/' <<< $branch | grep -Po
'TINKERPOP-[0-9]*'`
  status=`curl -s https://issues.apache.org/jira/browse/$jira | grep -A1
status-val | grep -Po '(?<=>)[^<]*(?=</span>)' | head -n1`
  echo "$branch -- $status"
done


This script identifies and prints the respective Jira ticket status for any
existing branch. The final version would not print the status, but use it
to determine, whether a branch can be deleted or not:

if [ "$status" == "Closed" ]; then
  git push origin --delete $branch
fi


It's a bit scary to delete a bunch of branches using a script and before I
delete some work in progress, I'd like anybody - who has some branches in
the main repository - to take a minute to review the script. Please raise
any concerns, if you think the script might delete too much. If nobody has
any complaints, then we'll use the script during the upcoming code freeze
week.

Cheers,
Daniel

Reply via email to