Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Last active February 28, 2023 00:35
Show Gist options
  • Save ralphbean/34632d6050a0fb37119d2c40ba6ba09e to your computer and use it in GitHub Desktop.
Save ralphbean/34632d6050a0fb37119d2c40ba6ba09e to your computer and use it in GitHub Desktop.
Find all instances in a JIRA project where rank and priority disagree
#!/usr/bin/env python
""" Find all issues that have conflicting rank and priority.
This script accepts one argument: a project id. It will search for all issues of a certain type in
that project and print out all instances it can find where one issue is ranked higher than another
while also having lower priority.
"""
import argparse
import os
import sys
import jira
def get_args():
"""
Parse args from the command-line.
"""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"project",
help="Name of the project we are prioritizing in",
)
parser.add_argument(
"--type",
default="Feature",
help="Type of issue that we're searching for"
)
parser.add_argument(
"--status",
help="Optional parameter to select issues in only one status"
)
return parser.parse_args()
args = get_args()
url = os.environ.get("JIRA_URL", "https://issues.redhat.com")
token = os.environ.get("JIRA_TOKEN")
if not token:
print("Set JIRA_TOKEN environment variable to your JIRA personal access token")
sys.exit(1)
JIRA = jira.client.JIRA(server=url, token_auth=token)
query = f"project={args.project} and type={args.type} and statusCategory != Done"
if args.status:
query = f"{query} and status='{args.status}'"
print("Searching for things of type {args.type}:", file=sys.stderr)
print(" > " + query, file=sys.stderr)
results = JIRA.search_issues(query)
if not results:
print(f"None found via: {query}")
sys.exit(1)
priorities = {
'Undefined': 0,
'Trivial': 1,
'Minor': 2,
'Normal': 3,
'Major': 4,
'Critical': 5,
'Blocker': 6,
}
rank = lambda issue: issue.fields.customfield_12311940
priority = lambda issue: priorities[issue.fields.priority.name]
link = lambda issue: f"{url}/browse/{issue.key}"
count = 0
for left in results:
for right in results:
if left == right:
continue
if rank(left) < rank(right) and priority(left) < priority(right):
print(f"{link(left)},{left.fields.priority.name},is ranked higher than,{link(right)},{right.fields.priority.name}")
count = count + 1
print(f"Found {count} nonsensical priority arrangements.", file=sys.stderr)
sys.exit(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment