Skip to content

Instantly share code, notes, and snippets.

@benjambe
Forked from prenagha/bulkUnwatch.sh
Last active December 16, 2015 13:29
Show Gist options
  • Save benjambe/5441721 to your computer and use it in GitHub Desktop.
Save benjambe/5441721 to your computer and use it in GitHub Desktop.
#
# Bulk Unwatch
# JIRA doesn't support unwatch from the bulk change action
# This script fills the gap
# Known to work with JIRA 5 via the REST API
#
# 1. Using JIRA, Issue Navigator, write a query to get all
# the issues you want to unwatch. Something like
# "issue in watchedIssues() AND status != Closed"
# works well as a starting point.
# 2. Using the View menu, Right-Click on RSS and save the RSS
# output to your computer.
# 3. Run this script against the RSS file you downloaded
# ./bulkUnwatch.sh <JIRA USERID> <JIRA PASSWORD> <RSS FILE>
#
USERID=$1
PASSWORD=$2
RSS=$3
if [ -z "$USERID" -o -z "$PASSWORD" -o ! -f "$RSS" ]
then
echo "bulkUnwatch.sh <JIRA USERID> <JIRA PASSWORD> <RSS FILE>"
exit 1
fi
for URLBASE in `cat $RSS | fgrep "<link>" | fgrep "/browse/" | sed 's/<link>//' | sed 's/<\/link>//' | sed 's/browse/rest\/api\/latest\/issue/'`
do
# 204 response on success
URL="${URLBASE}/watchers?username=${USERID}"
curl --request DELETE \
--write-out "%{http_code}\n" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--user "${USERID}:${PASSWORD}" \
$URL
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment