Skip to content

Instantly share code, notes, and snippets.

@sambauers
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sambauers/1447174e25a0906d93f6 to your computer and use it in GitHub Desktop.
Save sambauers/1447174e25a0906d93f6 to your computer and use it in GitHub Desktop.
Grabs all your watched JIRAs and removes your watch on them… very slowly.
<?php
$username = urlencode('your_jira_username');
$password = urlencode('your_jira_password');
$jiraurl = 'https://your_jira_url'; // e.g. https://redant.jira.com
$json = file_get_contents("$jiraurl/rest/api/latest/search?os_username=$username&os_password=$password&jql=issuekey%20in%20watchedIssues()&maxResults=1000");
if ( $json ) {
$data = json_decode($json);
$jiras = array();
foreach ($data->issues as $issue) {
$jiras[] = $issue->key;
}
if (empty($jiras)) {
echo 'No JIRAs in your watchlist.' . "\n";
exit(0);
}
echo 'Removing JIRAs from watchlist:' . "\n";
foreach ($jiras as $jira) {
echo '* ' . $jira;
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "$jiraurl/rest/api/latest/issue/$jira/watchers?os_username=$username&os_password=$password&username=$username",
CURLOPT_CUSTOMREQUEST => 'DELETE'
));
$result = curl_exec($ch);
$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($result && $response === 204) {
echo ' - killed';
} else {
echo ' - still kicking';
}
echo "\n";
curl_close($ch);
}
} else {
echo 'Unable to access JIRA at $jiraurl' . "\n";
exit(1);
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment