diff --git a/src/rules/team/timesensitive_rank.py b/src/rules/team/timesensitive_rank.py index 0e3aad5..1610619 100644 --- a/src/rules/team/timesensitive_rank.py +++ b/src/rules/team/timesensitive_rank.py @@ -9,6 +9,8 @@ import jira +PRIORITIES = ["Blocker", "Critical", "Major", "Normal", "Minor", "Trivial", "Undefined"] + def check_timesensitive_rank( issues: list[jira.resources.Issue], @@ -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: diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 9614fab..2c9510d 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -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"] = {} @@ -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})>" @@ -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, + ) diff --git a/src/tests/test_timesensitive_rank.py b/src/tests/test_timesensitive_rank.py index 24c4f04..caa1d4a 100644 --- a/src/tests/test_timesensitive_rank.py +++ b/src/tests/test_timesensitive_rank.py @@ -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