Skip to content

Commit

Permalink
#7 Check goals
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsken committed Nov 1, 2024
1 parent 21ad983 commit 65f2a82
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
27 changes: 26 additions & 1 deletion check_done/checks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from html.parser import HTMLParser

from check_done.done_project_items_info.done_project_items_info import done_project_items_info
from check_done.done_project_items_info.info import ProjectItemInfo

Expand Down Expand Up @@ -33,15 +35,38 @@ def _is_not_closed(project_item: ProjectItemInfo) -> bool:


def _is_not_assigned(project_item: ProjectItemInfo) -> bool:
return project_item.assignees.total_count < 1
return project_item.assignees.total_count == 0


def _has_no_milestone(project_item: ProjectItemInfo) -> bool:
return project_item.milestone is None


def has_unfinished_goals(project_item: ProjectItemInfo) -> bool:
class _GoalsHTMLParser(HTMLParser):
def __init__(self):
super().__init__()
self.is_any_goal_unchecked = False

def handle_starttag(self, tag, attrs):
if tag == "input":
attr_dict = dict(attrs)
is_checkbox = attr_dict.get("type") == "checkbox"
is_unchecked = "checked" not in attr_dict
if is_checkbox and is_unchecked:
self.is_any_goal_unchecked = True

def has_unfinished_goals(self):
return self.is_any_goal_unchecked

parser = _GoalsHTMLParser()
parser.feed(project_item.body_html)
return parser.has_unfinished_goals()


CONDITION_CHECK_AND_WARNING_REASON_LIST = [
(_is_not_closed, "not closed"),
(_is_not_assigned, "missing assignee"),
(_has_no_milestone, "missing milestone"),
(has_unfinished_goals, "missing finished goals"),
]
1 change: 1 addition & 0 deletions check_done/done_project_items_info/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class MilestoneInfo(BaseModel):

class ProjectItemInfo(BaseModel):
assignees: AssigneesInfo
body_html: str = Field(alias="bodyHTML", default=None)
closed: bool
number: NonNegativeInt
repository: RepositoryInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ query projectV2Issues(
assignees {
totalCount
}
bodyHTML
number
milestone {
id
Expand All @@ -33,6 +34,7 @@ query projectV2Issues(
assignees {
totalCount
}
bodyHTML
number
milestone {
id
Expand Down
59 changes: 59 additions & 0 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from check_done.checks import has_unfinished_goals
from check_done.done_project_items_info.info import AssigneesInfo, MilestoneInfo, ProjectItemInfo, RepositoryInfo


def test_can_check_for_unfinished_goals():
html_with_an_unfinished_goals = """
<h2 dir="auto">Goals</h2>
<ul class="contains-task-list">
<li class="task-list-item">
<input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Test 1.
</li>
<li class="task-list-item">
<input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Test. 2
</li>
</ul>
"""
project_item_with_unfinished_goals = ProjectItemInfo(
assignees=AssigneesInfo(totalCount=1),
bodyHTML=html_with_an_unfinished_goals,
closed=True,
number=1,
repository=RepositoryInfo(name="test_repo"),
milestone=MilestoneInfo(id="1"),
title="Test",
)
html_with_an_finished_goals = """
<h2 dir="auto">Goals</h2>
<ul class="contains-task-list">
<li class="task-list-item">
<input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Test 1.
</li>
<li class="task-list-item">
<input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Test. 2
</li>
</ul>
"""
project_item_with_finished_goals = ProjectItemInfo(
assignees=AssigneesInfo(totalCount=1),
bodyHTML=html_with_an_finished_goals,
closed=True,
number=1,
repository=RepositoryInfo(name="test_repo"),
milestone=MilestoneInfo(id="1"),
title="Test",
)
empty_html_body = ""
project_item_with_empty_html_body = ProjectItemInfo(
assignees=AssigneesInfo(totalCount=1),
bodyHTML=empty_html_body,
closed=True,
number=1,
repository=RepositoryInfo(name="test_repo"),
milestone=MilestoneInfo(id="1"),
title="Test",
)

assert has_unfinished_goals(project_item_with_unfinished_goals) is True
assert has_unfinished_goals(project_item_with_finished_goals) is False
assert has_unfinished_goals(project_item_with_empty_html_body) is False

0 comments on commit 65f2a82

Please sign in to comment.