-
-
Save bkw/4194016 to your computer and use it in GitHub Desktop.
Remove branches that belong to closed tickets
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/env bash | |
set -eu | |
# Base Repository URL | |
SVN_URL=http://svn-repo-url | |
# Atlassian Jira URL | |
JIRA_URL=https://jira-url | |
# Jira Project Key | |
PROJECT=project-key | |
# Jira and SVN Username | |
USERNAME=jira-svn-username | |
# Jira and SVN Password | |
PASSWORD=jira-svn-password | |
# Return a list of existing branches prefixed with an jira issue key | |
BRANCHES=$(svn list --username $USERNAME --password $PASSWORD $SVN_URL/$PROJECT/branches | grep "$PROJECT-[0-9]\+" | xargs -n1 basename) | |
REPORT_ALL="| %-18.18s | %-13.13s | %-35.35s | %-10.10s |\n" | |
REPORT_CLOSED="| %-18.18s | %-13.13s | %-35.35s | \e[00;32m%-10.10s\e[00m |\n" | |
printf "$REPORT_ALL" "BRANCH" "ISSUE KEY" "SUMMARY" "STATUS" | |
for BRANCH in $BRANCHES; do | |
ISSUE_KEY=$(perl -pe 's|($PROJECT-[0-9]+).*|\1|' <<< $BRANCH) | |
# Request ticket information | |
TICKET=$(curl -s -u $USERNAME:$PASSWORD -H "Content-Type: application/json" $JIRA_URL/rest/api/2/issue/$ISSUE_KEY) | |
TICKET_STATUS=$(jshon -Q -e fields -e status -e name -u <<< $TICKET) | |
TICKET_SUMMARY=$(jshon -Q -e fields -e summary -u <<< $TICKET) | |
if [ "$TICKET_STATUS" == 'Closed' ] ; then | |
printf "$REPORT_CLOSED" ${BRANCH} "$ISSUE_KEY" "$TICKET_SUMMARY" "$TICKET_STATUS" | |
svn delete --username $USERNAME --password $PASSWORD -m "$ISSUE_KEY $TICKET_SUMMARY [CLOSED]" $SVN_URL/$PROJECT/branches/$BRANCH | |
else | |
printf "$REPORT_ALL" "$BRANCH" "$ISSUE_KEY" "$TICKET_SUMMARY" "$TICKET_STATUS" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment