Skip to content

Commit

Permalink
Merge pull request #24 from siisurit/8-check-project-item-for-linked-…
Browse files Browse the repository at this point in the history
…project-item

#8 Check project item for linked project item
  • Loading branch information
mcsken authored Nov 1, 2024
2 parents b8c62ec + d2b9b4c commit aa393c1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions check_done/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ def has_unfinished_goals(self):
return parser.has_unfinished_goals()


def _is_missing_linked_project_item(project_item: ProjectItemInfo) -> bool:
return len(project_item.linked_project_item.nodes) == 0


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"),
(_is_missing_linked_project_item, "missing linked project item"),
]
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def matching_project_id(node_infos: list[ProjectV2NodeInfo]) -> str:
def matching_last_project_state_option_id(node_infos: list[ProjectV2SingleSelectFieldNodeInfo]) -> str:
try:
return next(
# TODO: Ponder giving the user the option to pick which project state option instead of picking
# TODO#13: Ponder giving the user the option to pick which project state option instead of picking
# the last one.
# Take into consideration that the GraphQL query allows for filtering the status options by name,
# which is interesting when there are emoji's in the name like in the case of Siisurit...
Expand Down
21 changes: 20 additions & 1 deletion check_done/done_project_items_info/info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import StrEnum
from typing import Any

from pydantic import BaseModel, ConfigDict, Field, NonNegativeInt, field_validator
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, NonNegativeInt, field_validator


class NodesTypeName(StrEnum):
Expand Down Expand Up @@ -84,14 +84,33 @@ class MilestoneInfo(BaseModel):
id: str


class LinkedProjectItemNodeInfo(BaseModel):
number: NonNegativeInt
title: str


class LinkedProjectItemInfo(BaseModel):
nodes: list[LinkedProjectItemNodeInfo]


# NOTE: For simplicity, both issues and pull requests are treated the same under a generic "project item" type,
# since all their underlying properties needed for checking are essentially identical,
# there is no value in differentiating between them as long as this continues to be the case.
class ProjectItemInfo(BaseModel):
"""A generic type representing both issues and pull requests in a project board."""

assignees: AssigneesInfo
body_html: str = Field(alias="bodyHTML", default=None)
closed: bool
number: NonNegativeInt
repository: RepositoryInfo
milestone: MilestoneInfo | None
title: str
linked_project_item: LinkedProjectItemInfo = Field(
validation_alias=AliasChoices(
"closedByPullRequestsReferences", "closingIssuesReferences", "linked_project_item"
)
)


class ProjectV2ItemNodeInfo(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ query projectV2Issues(
milestone {
id
}
closedByPullRequestsReferences(first: 1) {
nodes {
number
title
}
}
closed
title
repository {
Expand All @@ -39,6 +45,12 @@ query projectV2Issues(
milestone {
id
}
closingIssuesReferences(first: 1) {
nodes {
number
title
}
}
closed
title
repository {
Expand Down
11 changes: 10 additions & 1 deletion tests/test_checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from check_done.checks import has_unfinished_goals
from check_done.done_project_items_info.info import AssigneesInfo, MilestoneInfo, ProjectItemInfo, RepositoryInfo
from check_done.done_project_items_info.info import (
AssigneesInfo,
LinkedProjectItemInfo,
MilestoneInfo,
ProjectItemInfo,
RepositoryInfo,
)


def test_can_check_for_unfinished_goals():
Expand All @@ -22,6 +28,7 @@ def test_can_check_for_unfinished_goals():
repository=RepositoryInfo(name="test_repo"),
milestone=MilestoneInfo(id="1"),
title="Test",
linked_project_item=LinkedProjectItemInfo(nodes=[]),
)
html_with_an_finished_goals = """
<h2 dir="auto">Goals</h2>
Expand All @@ -42,6 +49,7 @@ def test_can_check_for_unfinished_goals():
repository=RepositoryInfo(name="test_repo"),
milestone=MilestoneInfo(id="1"),
title="Test",
linked_project_item=LinkedProjectItemInfo(nodes=[]),
)
empty_html_body = ""
project_item_with_empty_html_body = ProjectItemInfo(
Expand All @@ -52,6 +60,7 @@ def test_can_check_for_unfinished_goals():
repository=RepositoryInfo(name="test_repo"),
milestone=MilestoneInfo(id="1"),
title="Test",
linked_project_item=LinkedProjectItemInfo(nodes=[]),
)

assert has_unfinished_goals(project_item_with_unfinished_goals) is True
Expand Down

0 comments on commit aa393c1

Please sign in to comment.