Skip to content

Commit

Permalink
Merge pull request #21 from siisurit/5-check-assignees
Browse files Browse the repository at this point in the history
#5 Check assignees
  • Loading branch information
mcsken authored Oct 23, 2024
2 parents 8095d2d + a426b0c commit 93b95f0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
52 changes: 31 additions & 21 deletions check_done/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,41 @@
from check_done.done_project_items_info.info import ProjectItemInfo


def check_done_issues_for_warnings() -> list[str | None]:
def check_done_project_items_for_warnings() -> list[str | None]:
result = []
done_issues = done_project_items_info()
criteria_checks = [
_check_done_issues_are_closed,
]
for issue in done_issues:
warnings = [check(issue) for check in criteria_checks if check(issue)]
result.extend(warnings)
done_project_items = done_project_items_info()
for project_item in done_project_items:
warning_reasons = [
warning_reason for check, warning_reason in CONDITION_CHECK_AND_WARNING_REASON_LIST if check(project_item)
]
if len(warning_reasons) >= 1:
warning = _project_item_warning_string(project_item, warning_reasons)
result.append(warning)
return result


def _check_done_issues_are_closed(issue: ProjectItemInfo) -> str | None:
result = None
if not issue.closed:
result = _issue_warning_string(
issue,
"closed",
)
return result


def _issue_warning_string(issue: ProjectItemInfo, reason_for_warning: str) -> str:
# TODO: Ponder better wording.
def _project_item_warning_string(issue: ProjectItemInfo, reasons_for_warning: list[str]) -> str:
if len(reasons_for_warning) >= 3:
reasons_for_warning = f"{', '.join(reasons_for_warning[:-1])}, and {reasons_for_warning[-1]}"
elif len(reasons_for_warning) == 2:
reasons_for_warning = f"{', '.join(reasons_for_warning[:1])} and is {reasons_for_warning[1]}"
else:
reasons_for_warning = reasons_for_warning[0]
return (
f" Done project item should be {reason_for_warning}."
f" Done project item is {reasons_for_warning}."
f" - repository: '{issue.repository.name}', project item: '#{issue.number} {issue.title}'."
)


def _is_not_closed(project_item: ProjectItemInfo) -> bool:
return not project_item.closed


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


CONDITION_CHECK_AND_WARNING_REASON_LIST = [
(_is_not_closed, "not closed"),
(_is_not_assigned, "missing assignee"),
]
4 changes: 2 additions & 2 deletions check_done/command.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging
import sys

from check_done.checks import check_done_issues_for_warnings
from check_done.checks import check_done_project_items_for_warnings

logger = logging.getLogger(__name__)


def check_done_command():
result = 1
try:
warnings = check_done_issues_for_warnings()
warnings = check_done_project_items_for_warnings()
if len(warnings) == 0:
logger.info("No warnings found.")
result = 0
Expand Down
9 changes: 7 additions & 2 deletions check_done/done_project_items_info/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,16 @@ class RepositoryInfo(BaseModel):
name: str


class AssigneesInfo(BaseModel):
total_count: NonNegativeInt = Field(alias="totalCount")


class ProjectItemInfo(BaseModel):
number: NonNegativeInt
assignees: AssigneesInfo
closed: bool
title: str
number: NonNegativeInt
repository: RepositoryInfo
title: str


class ProjectV2ItemNodeInfo(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ query projectV2Issues(
type
content {
... on Issue {
assignees {
totalCount
}
number
closed
title
Expand All @@ -24,6 +27,9 @@ query projectV2Issues(
}
}
... on PullRequest {
assignees {
totalCount
}
number
closed
title
Expand Down

0 comments on commit 93b95f0

Please sign in to comment.