mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 17:47:24 +01:00
Python 3.14 stdlib package wiring git to the todo MCP server: - closer (post-commit): runs the done_check of each Todo: trailer task and close_task's it only on exit 0. It FAILS OPEN: the commit already happened, so a down server, bad token or no gh prints one warning and exits 0 instead of failing the hook. - sweep: nightly drift report (systemd units shipped, not enabled). - import-pr: a merged PR's '## Todo:' items become tasks, deduped. - A done_check runs only if its sha256 is in ~/.config/todo-hooks/trusted-checks; 'Check: manual' notes are never auto-closed. - Hooks exposed in .pre-commit-hooks.yaml (post-commit, post-merge, post-rewrite). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""``python3 -m todo_hooks {closer|sweep|trust|import-pr}``."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from typing import TYPE_CHECKING
|
|
|
|
from todo_hooks import closer, import_pr, sweep, trust_cmd
|
|
from todo_hooks.context import Context
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Callable, Mapping
|
|
from pathlib import Path
|
|
|
|
from todo_hooks.client import TaskClient
|
|
|
|
USAGE = "usage: python3 -m todo_hooks {closer|sweep|trust|import-pr} [args]"
|
|
|
|
|
|
def main(
|
|
argv: list[str] | None = None,
|
|
*,
|
|
env: Mapping[str, str] | None = None,
|
|
cwd: Path | None = None,
|
|
stdin: str | None = None,
|
|
make_client: Callable[[], TaskClient] | None = None,
|
|
) -> int:
|
|
"""Dispatch one subcommand; returns the process exit code."""
|
|
args = list(sys.argv[1:] if argv is None else argv)
|
|
if not args or args[0] not in {"closer", "sweep", "trust", "import-pr"}:
|
|
print(USAGE)
|
|
return 2
|
|
ctx = Context.build(env, cwd, make_client)
|
|
command, rest = args[0], args[1:]
|
|
if command == "closer":
|
|
return closer.run(ctx)
|
|
if command == "sweep":
|
|
return sweep.main(ctx, rest)
|
|
if command == "trust":
|
|
return trust_cmd.run(ctx, rest)
|
|
return import_pr.run(ctx, rest, stdin=stdin)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|