Skip to content

Commit

Permalink
Increase rank of items by priority, within a block
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Sep 16, 2024
1 parent 572e247 commit 22e5753
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rules/team/timesensitive_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import jira

PRIORITIES = ["Blocker", "Critical", "Major", "Normal", "Minor", "Trivial", "Undefined"]


def check_timesensitive_rank(
issues: list[jira.resources.Issue],
Expand Down Expand Up @@ -86,7 +88,10 @@ def __init__(self, parent):
self.issues = []

def yield_issues(self):
yield from self.issues
def priority(issue):
return PRIORITIES.index(issue.fields.priority.name)

yield from sorted(self.issues, key=priority)

def parent_is_inprogress(self):
if self.parent_issue is None:
Expand Down
32 changes: 31 additions & 1 deletion src/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class MockIssue:
def __init__(self, idx, project, parent, rank, duedate=None):
def __init__(self, idx, project, parent, rank, priority="Undefined", duedate=None):
raw = {}
raw["Context"] = {}
raw["Context"]["Field Ids"] = {}
Expand All @@ -21,6 +21,7 @@ def __init__(self, idx, project, parent, rank, duedate=None):
self.fields.project.key = project
self.fields.rank = rank
self.fields.duedate = duedate
self.fields.priority.name = priority

def __repr__(self):
return f"<{type(self).__name__} {self.fields.project.key}-{self.idx}({self.fields.rank})>"
Expand Down Expand Up @@ -65,3 +66,32 @@ def issues_with_due_dates():
return dict(
child1=child1, child2=child2, child3=child3, child4=child4, child5=child5
)


@pytest.fixture
def issues_with_priorities():
project = "TESTPROJECT"
child0 = MockIssue("child0", project, None, 0, priority="Blocker")
parent1 = MockIssue("parent1", project, None, 2)
parent2 = MockIssue("parent2", project, None, 1)
child1 = MockIssue("child1", project, parent1, 3, priority="Undefined")
child2 = MockIssue("child2", project, parent1, 4, priority="Blocker")
child3 = MockIssue("child3", project, parent1, 5, priority="Trivial")
child4 = MockIssue("child4", project, parent1, 6, priority="Major")
child5 = MockIssue("child5", project, parent2, 7)
child6 = MockIssue("child6", project, parent2, 8, priority="Minor")
child7 = MockIssue("child7", project, parent2, 9)
child8 = MockIssue("child8", project, parent2, 10)
child9 = MockIssue("child9", project, parent2, 11)
return dict(
child0=child0,
child1=child1,
child2=child2,
child3=child3,
child4=child4,
child5=child5,
child6=child6,
child7=child7,
child8=child8,
child9=child9,
)
21 changes: 21 additions & 0 deletions src/tests/test_timesensitive_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,24 @@ def test_rank_with_dates(issues_with_due_dates):
assert new_ranking[2].key == "child2"
assert new_ranking[3].key == "child3"
assert new_ranking[4].key == "child1"


def test_rank_with_priorities(issues_with_priorities):
issues = list(issues_with_priorities.values())
blocks = rules.team.timesensitive_rank.Blocks(issues)
blocks.sort()
new_ranking = blocks.get_issues()
expected = [
"child6",
"child5",
"child7",
"child8",
"child9",
"child2",
"child4",
"child3",
"child1",
"child0",
]
actual = [issue.key for issue in new_ranking]
assert actual == expected

0 comments on commit 22e5753

Please sign in to comment.