diff --git a/src/devops_cli/commands/gh.py b/src/devops_cli/commands/gh.py index 11bb3d9565..e3230ba460 100644 --- a/src/devops_cli/commands/gh.py +++ b/src/devops_cli/commands/gh.py @@ -12,6 +12,7 @@ import typer from devops_cli.commands.pr import app as pr_app +from devops_cli.config.constants import CONST_PROJECT_WORKFLOW_EXPECTATIONS from devops_cli.config.env import ENV_GITHUB_TOKEN from devops_cli.config.settings import get_keyring_secret from devops_cli.core.cli import new_typer @@ -685,17 +686,43 @@ def list_project_workflows( print_info(f"No built-in workflows found for project #{proj_num} ({owner}).") return - columns = ["#", "Workflow Name", "Status", "Configuration URL"] + columns = ["#", "Workflow Name", "Status", "Expected Configuration"] rows = [ [ str(w["number"]), w["name"], "[green]✓ Enabled[/green]" if w["enabled"] else "[yellow]○ Disabled[/yellow]", - w["url"], + CONST_PROJECT_WORKFLOW_EXPECTATIONS.get(w["name"], "[dim]not required[/dim]"), ] for w in workflows ] print_table(f"Built-In Automations (Project #{proj_num})", columns, rows) + _report_workflow_gaps(workflows, proj_num) + + +def _report_workflow_gaps(workflows: list[dict[str, Any]], proj_num: int) -> None: + """Name the workflows the task flow depends on that the board has switched off. + + These cannot be enabled from here. GitHub's GraphQL API offers `deleteProjectV2Workflow` + and no counterpart that creates or enables one, so a board owner sets them in the web + UI. Reporting the gap precisely is the most the CLI can do, and leaving it unreported + is why a board silently stops tracking what it is supposed to track. + """ + expected = [w for w in workflows if w["name"] in CONST_PROJECT_WORKFLOW_EXPECTATIONS] + missing = [w for w in expected if not w["enabled"]] + if not missing: + print_success(f"Every expected automation is enabled on project #{proj_num}.") + return + + print_warning( + f"{len(missing)} of {len(expected)} expected automations are disabled. Items will " + f"not change status on their own." + ) + for workflow in missing: + print_info( + f" {workflow['name']} -> {CONST_PROJECT_WORKFLOW_EXPECTATIONS[workflow['name']]}" + ) + print_info(f"Enable them at: {missing[0]['url']}") @project_app.command("list", help=HELP.gh.project_list) diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index 83a381f9d8..27735f5d3d 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -1474,3 +1474,17 @@ # pathspec's git ignore pattern factory. The older "gitwildmatch" alias is deprecated and # emits a warning per compiled file; the semantics are identical. CONST_GITIGNORE_PATTERN_STYLE: Final[str] = "gitignore" +# What each built-in Projects v2 workflow must be set to for this repository's task flow +# to keep a board honest without anyone touching it. GitHub's GraphQL API exposes only +# `deleteProjectV2Workflow` -- there is no mutation that enables or configures one -- so +# these are reported as a gap against the live board rather than applied. +CONST_PROJECT_WORKFLOW_EXPECTATIONS: Final[dict[str, str]] = { + "Item added to project": "Set Status to Todo", + "Item closed": "Set Status to Done", + "Item reopened": "Set Status to Todo", + "Pull request linked to issue": "Set Status to In Progress", + "Pull request merged": "Set Status to Done", + "Auto-close issue": "Close the issue when its linked pull request merges", + "Auto-add sub-issues to project": "Add sub-issues to this project", + "Auto-archive items": "Archive items closed more than two weeks ago", +} diff --git a/tests/test_gh_project_workflows.py b/tests/test_gh_project_workflows.py index 0a09fdeae9..7b2f1c91f2 100644 --- a/tests/test_gh_project_workflows.py +++ b/tests/test_gh_project_workflows.py @@ -4,6 +4,7 @@ import json import subprocess +from typing import Any from unittest.mock import patch import pytest @@ -279,3 +280,59 @@ def test_cli_project_workflows_list_empty() -> None: ], ) assert (result.exit_code, "No built-in workflows found" in result.output) == (0, True) + + +# ============================================================================= +# Expected configuration +# ============================================================================= + + +def _workflow(name: str, number: int, enabled: bool) -> dict[str, object]: + """Shape one built-in workflow as the API returns it.""" + return { + "id": f"PW_{number}", + "name": name, + "number": number, + "enabled": enabled, + "url": f"https://github.com/users/dan-petty/projects/2/workflows/{number}", + } + + +def _run_list() -> Any: + """Invoke the listing against a fixed board.""" + return runner.invoke( + app, + ["project", "workflows", "list", "--project-number", "2", "--repo", "dan-petty/devops-cli"], + ) + + +def test_a_disabled_automation_is_named_with_what_it_should_do() -> None: + """A board whose automations are off stops tracking silently. + + The listing showed only enabled/disabled, so a board that had never been configured + looked the same as one deliberately left manual. GitHub's GraphQL API offers no + mutation that enables a workflow, so naming the gap precisely is the whole remedy. + """ + workflows = [ + _workflow("Item closed", 1, False), + _workflow("Auto-add sub-issues to project", 4, True), + ] + with patch("devops_cli.commands.gh.get_project_workflows", return_value=workflows): + result = _run_list() + assert (result.exit_code, "Set Status to Done" in result.output) == (0, True) + + +def test_the_gap_is_counted_against_the_automations_the_board_has() -> None: + """Counting against every known expectation would report a gap for absent workflows.""" + workflows = [_workflow("Item closed", 1, False), _workflow("Item added to project", 6, False)] + with patch("devops_cli.commands.gh.get_project_workflows", return_value=workflows): + result = _run_list() + assert "2 of 2 expected automations are disabled" in result.output + + +def test_a_fully_configured_board_reports_no_gap() -> None: + """The report must be quiet when there is nothing to act on.""" + workflows = [_workflow("Item closed", 1, True), _workflow("Pull request merged", 2, True)] + with patch("devops_cli.commands.gh.get_project_workflows", return_value=workflows): + result = _run_list() + assert "Every expected automation is enabled" in result.output