Created
October 1, 2019 19:43
-
-
Save jpeckham/687de0b6d6845161c48e6571f43f9ac2 to your computer and use it in GitHub Desktop.
delete unused versions in jira
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
from jira import JIRA | |
import secrets | |
import urllib3 | |
import requests | |
urllib3.disable_warnings() # deleting warnings about ssl. i'm local and can check before i run this, so i don't care. | |
# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK | |
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details). | |
# Override this with the options parameter. | |
base_url = 'https://jira.yourdomain.com' | |
options = { | |
'server': base_url, | |
'verify': False | |
} | |
jira = JIRA(options, basic_auth=(secrets.username, secrets.password)) | |
projects = jira.projects() | |
#if you want to limit the keys you delete in. fill this tuple out | |
projects_i_want = ('PROJ1', 'PROJ2') | |
#otherwise get rid of the filter below | |
for project in filter(lambda p: projects_i_want.__contains__(p.key), projects): | |
for version in jira.project_versions(project.id): | |
search_result = jira.search_issues(jql_str = f'project = {project.key} AND fixVersion = {version.id}', maxResults=0) | |
print(f'proj: {project.key} vers: {version.name} total:{search_result.total}') | |
# example delete DELETE https://foobar.atlassian.net/rest/api/2/version/14455 | |
if search_result.total == 0: | |
#didn't have an api helper in the jira lib for this | |
delete_result = requests.delete(f'{base_url}/rest/api/2/version/{version.id}', auth=requests.auth.HTTPBasicAuth(secrets.username, secrets.password), verify=False) | |
if delete_result.ok: | |
print(f'deleted {version.name}') | |
else: | |
print(f'failed to delete {version.name}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment